Newer
Older
# The spawner is based on PRP's https://gitlab.nrp-nautilus.io/vpeddu/jupyterlab-west.git
# This file is managed by [youngsu.kim|dung.vu]@csusb.edu
from kubespawner import KubeSpawner
class MySpawner(KubeSpawner):
with open('/etc/jupyterhub/custom/my_spawner.html', 'r') as f:
profile_form_template = f.readlines()
profile_form_template = "".join(profile_form_template)
def options_from_form(self, formdata):
# if not self.profile_list or not hasattr(self, '_profile_list'):
# return formdata
profile_slug = formdata.get('profile', [None])[0]
# initialize a dictionary to return
user_options = {}
# if a profile is declared, add a dictionary key for the profile, and
# dictionary keys for the formdata related to the profile's
# profile_options, as recognized by being named like:
#
# profile-option-{profile_slug}--{profile_option_slug}
#
if profile_slug:
user_options["profile"] = profile_slug
prefix = f'profile-option-{profile_slug}--'
for k, v in formdata.items():
if k.startswith(prefix):
profile_option_slug = k[len(prefix) :]
user_options[profile_option_slug] = v[0]
else:
user_options[prefix+k] = v[0]
# self.log.info("Applying KubeSpawner override for profile '%s'", user_options)
# kubespawner_override = user_options.get('kubespawner_override', {})
profile = self._get_profile(profile_slug, self.profile_list)
if (("image_choice" in profile) and (isinstance(profile["image_choice"], dict))):
if gpus > 0:
image = profile["image_choice"]["cuda"]
else:
image = profile["image_choice"]["cpu"]
setattr(self, "image", image)
setattr(self, "extra_resource_limits", {"nvidia.com/gpu": gpus})
setattr(self, "mem_guarantee", formdata.get('ram', [0])[0]+"G")
setattr(self, "cpu_guarantee", float(formdata.get('cores', [0])[0]))
setattr(self, "mem_limit", formdata.get('ram', [0])[0]+"G")
setattr(self, "cpu_limit", float(formdata.get('cores', [0])[0]))
'key': 'topology.kubernetes.io/region',
'operator': 'In',
if formdata.get('gputype', [0])[0]:
nodeSelectorTermsExpressions.append({
'key': 'nvidia.com/gpu.product',
'operator': 'In',
'values': formdata.get('gputype', [0])
})
if gpus == 0:
nodeSelectorTermsExpressions.append({
'key': 'nvidia.com/gpu.product',
'operator': 'NotIn',
'values': [ "NVIDIA-GeForce-RTX-3090", "NVIDIA-A100-80GB-PCIe-MIG-1g.10gb", "NVIDIA-L40", "NVIDIA-A10",
"NVIDIA-RTX-A4000", "NVIDIA-RTX-A5000", "NVIDIA-RTX-A5000", "NVIDIA-A100-SXM4-80GB", "NVIDIA-GeForce-GTX-1080-Ti",
# tolerationsExpression = [{
# 'key': 'nautilus.io/nrp-testing',
# 'operator': 'Exists',
# 'effect': 'NoSchedule',
# }]
setattr(self, 'extra_pod_config', {
'affinity': {
'nodeAffinity': {
'requiredDuringSchedulingIgnoredDuringExecution': {
'nodeSelectorTerms': [{
'matchExpressions': nodeSelectorTermsExpressions,
}],
},
},
# self.volume_mounts = [
# {
# 'name': 'volume-{username}',
# 'mountPath': '/home/jovyan',
# },
# {
# 'name': 'csusb-share',
# 'mountPath': '/home/jovyan/shared',
# },
# ]
# self.volumes = [
# {
# 'name': 'volume-{username}',
# 'persistentVolumeClaim': {
# 'claimName': 'claim-{username}'
# }
# },
# {
# 'name': 'csusb-share',
# 'persistentVolumeClaim': {
# 'claimName': 'csusb-khan-share'
# }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{
'display_name': 'Scipy',
'slug': 'scipy',
'kubespawner_override': {
'image': 'quay.io/jupyter/scipy-notebook:2024-04-22'
}
},
{
'display_name': 'R',
'slug': 'r',
'kubespawner_override': {
'image': 'quay.io/jupyter/r-notebook:2024-04-22'
}
},
{
'display_name': 'Julia',
'slug': 'julia',
'kubespawner_override': {
'image': 'quay.io/jupyter/julia-notebook:2024-04-22'
}
},
{
'display_name': 'Tensorflow',
'slug': 'tf',
'image_choice': {
'cuda': 'quay.io/jupyter/tensorflow-notebook:cuda-2024-04-22',
'cpu': 'quay.io/jupyter/tensorflow-notebook:2024-04-22'
}
},
{
'display_name': 'Pytorch',
'slug': 'tf',
'image_choice': {
'cuda': 'quay.io/jupyter/pytorch-notebook:cuda12-2024-04-22',
'cpu': 'quay.io/jupyter/pytorch-notebook:2024-04-22'
}
},
{
'display_name': 'Datascience (scipy, Julia, R)',
'default': 'true',
'slug': 'ds',
'kubespawner_override': {
'image': 'quay.io/jupyter/datascience-notebook:2024-04-22'
}