Я столкнулся с проблемой при создании нового модуля с помощью jupyterhub с использованием специального kubespawner. Ниже мой файл custom_kubespawner.py
import json
import os
from kubespawner import KubeSpawner
class CustomSpawner(KubeSpawner):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def load_config(self):
config_file_path = "/srv/jupyterhub/profiles.json" # Update this to your file path
if os.path.exists(config_file_path):
with open(config_file_path) as f:
self.lab_config = json.load(f)
else:
raise FileNotFoundError(f"Configuration file not found: {config_file_path}")
async def start(self):
# Load the configuration before starting the pod
self.load_config()
# Use the loaded configuration to set the parameters
self.singleuser_image = self.lab_config.get("notebook_image", "jupyter/notebook")
self.mem_limit = self.lab_config.get("mem_limit", "2G")
self.cpu_limit = self.lab_config.get("cpu_limit", 1)
# Set environment variables
env_vars = self.lab_config.get("env_variables", {})
for key, value in env_vars.items():
self.environment[key] = value
# Set affinity based on the JSON configuration
affinity = self.lab_config.get("affinity", {})
if affinity:
self.extra_pod_config['affinity'] = affinity
# Set the storage capacity and mount path
self.storage_capacity = self.lab_config.get("storage_capacity", "20Gi") # Default to 20Gi if not specified
self.pvc_name_template = f"{self.user.name}-pvc"
self.volume_name_template = f"{self.user.name}-vol"
self.volumes = [
{
"name": self.volume_name_template,
"persistentVolumeClaim": {"claimName": "{pvc_name}"},
}
]
self.volume_mounts = [
{
'mountPath': '/home/jovyan', # Specify where to mount the volume in the pod
'name': self.volume_name_template
}
]
return await super().start()
Файл Jupyterhub_cnnfig.py содержит доступный код jupyter_config.py
Я добавил строки
[E 2024-10-28 16:09:54.115 JupyterHub gen:629] Exception in Future after timeout
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/tornado/gen.py", line 624, in error_callback
future.result()
File "/usr/local/lib/python3.11/site-packages/jupyterhub/handlers/base.py", line 1088, in finish_user_spawn
await spawn_future
File "/usr/local/lib/python3.11/site-packages/jupyterhub/user.py", line 905, in spawn
raise e
File "/usr/local/lib/python3.11/site-packages/jupyterhub/user.py", line 801, in spawn
url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/jupyterhub/custom_spawner.py", line 117, in start
return await super().start()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 2718, in _start
pod = await self.get_pod_manifest()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 2015, in get_pod_manifest
volumes=self._expand_all(self.volumes),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1845, in _expand_all
return [self._expand_all(i) for i in src]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1845, in
return [self._expand_all(i) for i in src]
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in _expand_all
return {k: self._expand_all(v) for k, v in src.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in
return {k: self._expand_all(v) for k, v in src.items()}
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in _expand_all
return {k: self._expand_all(v) for k, v in src.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in
return {k: self._expand_all(v) for k, v in src.items()}
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1849, in _expand_all
return self._expand_user_properties(src)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1827, in _expand_user_properties
rendered = template.format(
^^^^^^^^^^^^^^^^
KeyError: 'pvc_name'
Это ошибка.
Я развернул jupthub GKE, используя концепцию от 0 до jupytehub.
Любое обновление или альтернативный способ добиться этого.
Примечание: не хочу использовать ProfileList, так как мне нужно подготовить данные на основе предоставленных данных, поэтому я не могу показать параметры пользователю.>
Я столкнулся с проблемой при создании нового модуля с помощью jupyterhub с использованием специального kubespawner. Ниже мой файл custom_kubespawner.py [code]import json import os from kubespawner import KubeSpawner
class CustomSpawner(KubeSpawner): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
def load_config(self): config_file_path = "/srv/jupyterhub/profiles.json" # Update this to your file path if os.path.exists(config_file_path): with open(config_file_path) as f: self.lab_config = json.load(f) else: raise FileNotFoundError(f"Configuration file not found: {config_file_path}")
async def start(self): # Load the configuration before starting the pod self.load_config()
# Use the loaded configuration to set the parameters self.singleuser_image = self.lab_config.get("notebook_image", "jupyter/notebook") self.mem_limit = self.lab_config.get("mem_limit", "2G") self.cpu_limit = self.lab_config.get("cpu_limit", 1)
# Set environment variables env_vars = self.lab_config.get("env_variables", {}) for key, value in env_vars.items(): self.environment[key] = value
# Set affinity based on the JSON configuration affinity = self.lab_config.get("affinity", {}) if affinity: self.extra_pod_config['affinity'] = affinity
# Set the storage capacity and mount path self.storage_capacity = self.lab_config.get("storage_capacity", "20Gi") # Default to 20Gi if not specified self.pvc_name_template = f"{self.user.name}-pvc" self.volume_name_template = f"{self.user.name}-vol" self.volumes = [
self.volume_mounts = [ { 'mountPath': '/home/jovyan', # Specify where to mount the volume in the pod 'name': self.volume_name_template } ]
return await super().start() [/code] Файл Jupyterhub_cnnfig.py содержит доступный код jupyter_config.py Я добавил строки [code]sys.path.insert(0, "/srv/jupyterhub") sys.path.insert(0, "/usr/local/etc/jupyterhub") from custom_spawner import CustomSpawner c.JupyterHub.spawner_class = "CustomSpawner" [/code] чтобы импортировать файл jupyterhub_config.py и использовать собственный генератор. [code]{ "notebook_image": "jupyter/scipy-notebook", "cpu_limit": 1, "mem_limit": "2G", "env_variables": { "MY_ENV_VAR": "TOKYO" }, "affinity": { "nodeAffinity": { "requiredDuringSchedulingIgnoredDuringExecution": { "nodeSelectorTerms": [ { "matchExpressions": [ { "key": "image", "operator": "In", "values": [ "minimal-notebook" ] } ] } ] } } }, "storage_capacity": "10Gi" } [/code] Все файлы хранятся в папке /srv/jupyterhub в модуле концентратора [code][E 2024-10-28 16:09:54.115 JupyterHub gen:629] Exception in Future after timeout Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/tornado/gen.py", line 624, in error_callback future.result() File "/usr/local/lib/python3.11/site-packages/jupyterhub/handlers/base.py", line 1088, in finish_user_spawn await spawn_future File "/usr/local/lib/python3.11/site-packages/jupyterhub/user.py", line 905, in spawn raise e File "/usr/local/lib/python3.11/site-packages/jupyterhub/user.py", line 801, in spawn url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/srv/jupyterhub/custom_spawner.py", line 117, in start return await super().start() ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 2718, in _start pod = await self.get_pod_manifest() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 2015, in get_pod_manifest volumes=self._expand_all(self.volumes), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1845, in _expand_all return [self._expand_all(i) for i in src] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1845, in return [self._expand_all(i) for i in src] ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in _expand_all return {k: self._expand_all(v) for k, v in src.items()} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in return {k: self._expand_all(v) for k, v in src.items()} ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in _expand_all return {k: self._expand_all(v) for k, v in src.items()} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1847, in return {k: self._expand_all(v) for k, v in src.items()} ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1849, in _expand_all return self._expand_user_properties(src) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/kubespawner/spawner.py", line 1827, in _expand_user_properties rendered = template.format( ^^^^^^^^^^^^^^^^ KeyError: 'pvc_name' [/code] Это ошибка. Я развернул jupthub GKE, используя концепцию от 0 до jupytehub. Любое обновление или альтернативный способ добиться этого. Примечание: не хочу использовать ProfileList, так как мне нужно подготовить данные на основе предоставленных данных, поэтому я не могу показать параметры пользователю.>