Skip to content

Commit 0640e64

Browse files
authored
Merge pull request #12 from NetApp/sufian-mount-pvc
K8s - Create JupyterLab - Add Option to Mount PVC
2 parents 297580a + 49183db commit 0640e64

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

netapp_dataops_k8s/netapp_dataops/k8s/__init__.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
by applications using the import method of utilizing the toolkit.
55
"""
66

7-
__version__ = "2.1.1"
7+
__version__ = "2.2.0beta1"
88

99
import base64
1010
from datetime import datetime
@@ -609,7 +609,8 @@ def clone_volume(new_pvc_name: str, source_pvc_name: str, source_snapshot_name:
609609
print("Volume successfully cloned.")
610610

611611

612-
def create_jupyter_lab(workspace_name: str, workspace_size: str, storage_class: str = None, load_balancer_service: bool = False, namespace: str = "default",
612+
def create_jupyter_lab(workspace_name: str, workspace_size: str, mount_pvc: str = None, storage_class: str = None,
613+
load_balancer_service: bool = False, namespace: str = "default",
613614
workspace_password: str = None, workspace_image: str = "jupyter/tensorflow-notebook",
614615
request_cpu: str = None, request_memory: str = None, request_nvidia_gpu: str = None, register_with_astra: bool = False,
615616
print_output: bool = False, pvc_already_exists: bool = False, labels: dict = None) -> str:
@@ -779,6 +780,34 @@ def create_jupyter_lab(workspace_name: str, workspace_size: str, storage_class:
779780
)
780781
)
781782

783+
# Mount Additional pvc if needed
784+
if mount_pvc:
785+
786+
divider_index = mount_pvc.find(":")
787+
user_pvc_name = mount_pvc[:divider_index]
788+
user_pvc_mountpoint = mount_pvc[divider_index+1:]
789+
790+
if print_output:
791+
print("\nAttaching Additional PVC: '" + user_pvc_name + "' at mount_path: '" + user_pvc_mountpoint + "'.")
792+
793+
# Add user-specified PVC
794+
deployment.spec.template.spec.volumes.append(
795+
client.V1Volume(
796+
name="uservol",
797+
persistent_volume_claim={
798+
"claimName": user_pvc_name
799+
}
800+
)
801+
)
802+
803+
# Add mountpoint for user-specified PVC
804+
deployment.spec.template.spec.containers[0].volume_mounts.append(
805+
client.V1VolumeMount(
806+
name="uservol",
807+
mount_path=user_pvc_mountpoint
808+
)
809+
)
810+
782811
# Apply resource requests
783812
if request_cpu:
784813
deployment.spec.template.spec.containers[0].resources["requests"]["cpu"] = request_cpu

netapp_dataops_k8s/netapp_dataops/netapp_dataops_k8s_cli.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
\t-b, --load-balancer\t\tOption to use a LoadBalancer instead of using NodePort service. If not specified, NodePort service will be utilized.
103103
104104
Examples:
105-
\tnetapp_dataops_k8s_cli.py clone jupyterlab --new-workspace-name=project1-experiment1 --source-workspace-name=project1 --nvidia-gpu=1
105+
\tnetapp_dataops_k8s_cli.py clone jupyterlab --new-workspace-name=project1-experiment1 --source-workspace-name=project1 --nvidia-gpu=1
106106
\tnetapp_dataops_k8s_cli.py clone jupyterlab -w project2-mike -s project2-snap1 -n team1 -g 1 -p 0.5 -m 1Gi -b
107107
'''
108108
helpTextCloneToNewNsJupyterLab = '''
@@ -165,6 +165,7 @@
165165
\t-p, --cpu=\t\t\tNumber of CPUs to reserve for JupyterLab workspace. Format: '0.5', '1', etc. If not specified, no CPUs will be reserved.
166166
\t-b, --load-balancer\t\tOption to use a LoadBalancer instead of using NodePort service. If not specified, NodePort service will be utilized.
167167
\t-a, --register-with-astra\tRegister new workspace with Astra Control (requires Astra Control).
168+
\t-v, --mount-pvc\t\t\tOption to attach an additional existing PVC that can be mounted at a spefic path whithin the container. Format: -v/--mount-pvc=existing_pvc_name:mount_point. If not specified, no additional PVC will be attached.
168169
169170
Examples:
170171
\tnetapp_dataops_k8s_cli.py create jupyterlab --workspace-name=mike --size=10Gi --nvidia-gpu=2
@@ -739,12 +740,13 @@ def getTarget(args: list) -> str:
739740
requestCpu = None
740741
register_with_astra = False
741742
load_balancer_service = False
743+
mount_pvc = None
742744

743745
# Get command line options
744746
try:
745-
opts, args = getopt.getopt(sys.argv[3:], "hw:s:n:c:i:g:m:p:ab",
747+
opts, args = getopt.getopt(sys.argv[3:], "hw:s:n:c:i:g:m:p:abv:",
746748
["help", "workspace-name=", "size=", "namespace=", "storage-class=",
747-
"image=", "nvidia-gpu=", "memory=", "cpu=", "register-with-astra", "load-balancer"])
749+
"image=", "nvidia-gpu=", "memory=", "cpu=", "register-with-astra", "load-balancer", "mount-pvc="])
748750
except:
749751
handleInvalidCommand(helpText=helpTextCreateJupyterLab, invalidOptArg=True)
750752

@@ -773,7 +775,8 @@ def getTarget(args: list) -> str:
773775
register_with_astra = True
774776
elif opt in ("-b", "--load-balancer"):
775777
load_balancer_service = True
776-
778+
elif opt in ("-v", "--mount-pvc"):
779+
mount_pvc = arg
777780

778781
# Check for required options
779782
if not workspaceName or not workspaceSize:
@@ -782,7 +785,7 @@ def getTarget(args: list) -> str:
782785
# Create JupyterLab workspace
783786
try:
784787
create_jupyter_lab(workspace_name=workspaceName, workspace_size=workspaceSize, storage_class=storageClass,
785-
load_balancer_service=load_balancer_service, namespace=namespace, workspace_image=workspaceImage, request_cpu=requestCpu,
788+
load_balancer_service=load_balancer_service, namespace=namespace, workspace_image=workspaceImage, request_cpu=requestCpu, mount_pvc=mount_pvc,
786789
request_memory=requestMemory, request_nvidia_gpu=requestNvidiaGpu, register_with_astra=register_with_astra, print_output=True)
787790
except (InvalidConfigError, APIConnectionError):
788791
sys.exit(1)

0 commit comments

Comments
 (0)