Skip to content

Commit 9df66c3

Browse files
sufianNetAppmboglesby
authored andcommitted
Added load-balancer option for clone juyterlab function
1 parent c05158f commit 9df66c3

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

netapp_dataops_k8s/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ The following options/arguments are optional:
129129
-n, --namespace= Kubernetes namespace that source workspace is located in. If not specified, namespace "default" will be used.
130130
-p, --cpu= Number of CPUs to reserve for new JupyterLab workspace. Format: '0.5', '1', etc. If not specified, no CPUs will be reserved.
131131
-s, --source-snapshot-name= Name of Kubernetes VolumeSnapshot to use as source for clone. Either -s/--source-snapshot-name or -j/--source-workspace-name must be specified.
132+
-b, --load-balancer Option to choose a LoadBalancer service instead of using NodePort service. If not specified, NodePort service will be utilized.
132133
```
133134

134135
##### Example Usage
135136

136-
Near-instantaneously create a new JupyterLab workspace, named 'project1-experiment3', that is an exact copy of the current contents of existing JupyterLab workspace 'project1' in namespace 'default'. Allocate 2 NVIDIA GPUs to the new workspace.
137+
Near-instantaneously create a new JupyterLab workspace, named 'project1-experiment3', that is an exact copy of the current contents of existing JupyterLab workspace 'project1' in namespace 'default'. Allocate 2 NVIDIA GPUs to the new workspace and use LoadBalancer service instead of NodePort.
137138

138139
```sh
139-
netapp_dataops_k8s_cli.py clone jupyterlab --new-workspace-name=project1-experiment3 --source-workspace-name=project1 --nvidia-gpu=2
140+
netapp_dataops_k8s_cli.py clone jupyterlab --new-workspace-name=project1-experiment3 --source-workspace-name=project1 --nvidia-gpu=2 --load-balancer
140141
Creating new JupyterLab workspace 'project1-experiment3' from source workspace 'project1' in namespace 'default'...
141142
142143
Creating new VolumeSnapshot 'ntap-dsutil.for-clone.20210315185504' for source PVC 'ntap-dsutil-jupyterlab-project1' in namespace 'default' to use as source for clone...
@@ -161,7 +162,7 @@ Waiting for Deployment 'ntap-dsutil-jupyterlab-project1-experiment3' to reach Re
161162
Deployment successfully created.
162163
163164
Workspace successfully created.
164-
To access workspace, navigate to http://10.61.188.112:30993
165+
To access workspace, navigate to http://10.61.188.110
165166
JupyterLab workspace successfully cloned.
166167
```
167168

@@ -832,6 +833,7 @@ def clone_jupyter_lab(
832833
new_workspace_name: str, # Name of new workspace (name to be applied to new JupyterLab workspace) (required).
833834
source_workspace_name: str, # Name of JupyterLab workspace to use as source for clone. (required).
834835
source_snapshot_name: str = None, # Name of Kubernetes VolumeSnapshot to use as source for clone.
836+
load_balancer_service: bool = False, # Option to use a LoadBalancer instead of using NodePort service. If not specified, NodePort service will be utilized.
835837
new_workspace_password: str = None, # Workspace password (this password will be required in order to access the workspace). If not specified, you will be prompted to enter a password via the console.
836838
volume_snapshot_class: str = "csi-snapclass", # Kubernetes VolumeSnapshotClass to use when creating clone. If not specified, "csi-snapclass" will be used. Note: VolumeSnapshotClass must be configured to use Trident.
837839
namespace: str = "default", # Kubernetes namespace that source workspace is located in. If not specified, namespace "default" will be used.

netapp_dataops_k8s/netapp_dataops/k8s.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _wait_for_jupyter_lab_deployment_ready(workspaceName: str, namespace: str =
331331

332332

333333
def clone_jupyter_lab(new_workspace_name: str, source_workspace_name: str, source_snapshot_name: str = None,
334-
new_workspace_password: str = None, volume_snapshot_class: str = "csi-snapclass",
334+
load_balancer_service: bool = False, new_workspace_password: str = None, volume_snapshot_class: str = "csi-snapclass",
335335
namespace: str = "default", request_cpu: str = None, request_memory: str = None,
336336
request_nvidia_gpu: str = None, print_output: bool = False):
337337
# Determine source PVC details
@@ -374,7 +374,7 @@ def clone_jupyter_lab(new_workspace_name: str, source_workspace_name: str, sourc
374374
print()
375375
create_jupyter_lab(workspace_name=new_workspace_name, workspace_size=workspaceSize, namespace=namespace,
376376
workspace_password=new_workspace_password, workspace_image=sourceWorkspaceImage, request_cpu=request_cpu,
377-
request_memory=request_memory, request_nvidia_gpu=request_nvidia_gpu, print_output=print_output,
377+
load_balancer_service=load_balancer_service, request_memory=request_memory, request_nvidia_gpu=request_nvidia_gpu, print_output=print_output,
378378
pvc_already_exists=True, labels=labels)
379379

380380
if print_output:

netapp_dataops_k8s/netapp_dataops/netapp_dataops_k8s_cli.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@
7373
\t-n, --namespace=\t\tKubernetes namespace that source workspace is located in. If not specified, namespace "default" will be used.
7474
\t-p, --cpu=\t\t\tNumber of CPUs to reserve for new JupyterLab workspace. Format: '0.5', '1', etc. If not specified, no CPUs will be reserved.
7575
\t-s, --source-snapshot-name=\tName of Kubernetes VolumeSnapshot to use as source for clone. Either -s/--source-snapshot-name or -j/--source-workspace-name must be specified.
76+
\t-b, --source-snapshot-name=\tName of Kubernetes VolumeSnapshot to use as source for clone. Either -s/--source-snapshot-name or -j/--source-workspace-name must be specified.
77+
\t-b, --load-balancer\tOption to use a LoadBalancer instead of using NodePort service. If not specified, NodePort service will be utilized.
7678
7779
Examples:
78-
\tnetapp_dataops_k8s_cli.py clone jupyterlab --new-workspace-name=project1-experiment1 --source-workspace-name=project1 --nvidia-gpu=1
79-
\tnetapp_dataops_k8s_cli.py clone jupyterlab -w project2-mike -s project2-snap1 -n team1 -g 1 -p 0.5 -m 1Gi
80+
\tnetapp_dataops_k8s_cli.py clone jupyterlab --new-workspace-name=project1-experiment1 --source-workspace-name=project1 --nvidia-gpu=1
81+
\tnetapp_dataops_k8s_cli.py clone jupyterlab -w project2-mike -s project2-snap1 -n team1 -g 1 -p 0.5 -m 1Gi -b
8082
'''
8183
helpTextCloneVolume = '''
8284
Command: clone volume
@@ -438,13 +440,14 @@ def getTarget(args: list) -> str:
438440
requestNvidiaGpu = None
439441
requestMemory = None
440442
requestCpu = None
443+
load_balancer_service= False
441444

442445
# Get command line options
443446
try:
444-
opts, args = getopt.getopt(sys.argv[3:], "hw:c:n:s:j:g:m:p:",
447+
opts, args = getopt.getopt(sys.argv[3:], "hw:c:n:s:j:g:m:p:b",
445448
["help", "new-workspace-name=", "volume-snapshot-class=", "namespace=",
446449
"source-snapshot-name=", "source-workspace-name=", "nvidia-gpu=", "memory=",
447-
"cpu="])
450+
"cpu=", "load-balancer"])
448451
except:
449452
handleInvalidCommand(helpText=helpTextCloneJupyterLab, invalidOptArg=True)
450453

@@ -469,6 +472,8 @@ def getTarget(args: list) -> str:
469472
requestMemory = arg
470473
elif opt in ("-p", "--cpu"):
471474
requestCpu = arg
475+
elif opt in ("-b", "--load-balancer"):
476+
load_balancer_service = True
472477

473478
# Check for required options
474479
if not newWorkspaceName or (not sourceSnapshotName and not sourceWorkspaceName):
@@ -480,7 +485,7 @@ def getTarget(args: list) -> str:
480485

481486
# Clone volume
482487
try:
483-
clone_jupyter_lab(new_workspace_name=newWorkspaceName, source_workspace_name=sourceWorkspaceName,
488+
clone_jupyter_lab(new_workspace_name=newWorkspaceName, source_workspace_name=sourceWorkspaceName, load_balancer_service=load_balancer_service,
484489
source_snapshot_name=sourceSnapshotName, volume_snapshot_class=volumeSnapshotClass,
485490
namespace=namespace, request_cpu=requestCpu, request_memory=requestMemory,
486491
request_nvidia_gpu=requestNvidiaGpu, print_output=True)

0 commit comments

Comments
 (0)