44import urllib .parse
55
66from kubespawner .spawner import KubeSpawner
7+
8+ from cloudharness .applications import get_configuration
9+ from cloudharness .auth .quota import get_user_quotas
10+ from cloudharness .utils .config import CloudharnessConfig as conf
11+
12+
713handler = logging .StreamHandler (sys .stdout )
814handler .setLevel (logging .DEBUG )
915logging .getLogger ().addHandler (handler )
1016
11- from cloudharness .applications import get_configuration
12- from cloudharness .auth .quota import get_user_quotas
17+ def custom_options_form (spawner , abc ):
18+ # let's skip the profile selection form for now
19+ # ToDo: for future we can remove this hook
20+ spawner .profile_list = []
21+ # ref: https://github.com/jupyterhub/kubespawner/blob/37a80abb0a6c826e5c118a068fa1cf2725738038/kubespawner/spawner.py#L1885-L1935
22+ return spawner ._options_form_default ()
1323
1424
1525class PodSpawnException (Exception ):
@@ -20,6 +30,9 @@ def harness_hub():
2030 """Wraps the method to change spawner configuration"""
2131 KubeSpawner .get_pod_manifest_base = KubeSpawner .get_pod_manifest
2232 KubeSpawner .get_pod_manifest = spawner_pod_manifest
33+ # let's skip the profile selection form for now
34+ # TODO: for future we can remove this hook
35+ KubeSpawner .options_form = custom_options_form
2336 KubeSpawner .get_pvc_manifest_base = KubeSpawner .get_pvc_manifest
2437 KubeSpawner .get_pvc_manifest = spawner_pvc_manifest
2538
@@ -105,7 +118,6 @@ def change_pod_manifest(self: KubeSpawner):
105118 self .user .name , quota_ws_open
106119 ),
107120 )
108-
109121 try :
110122 subdomain = self .handler .request .host .split (str (self .config ['domain' ]))[0 ][0 :- 1 ]
111123 app_config = self .config ['apps' ]
@@ -115,9 +127,23 @@ def change_pod_manifest(self: KubeSpawner):
115127 harness = app ['harness' ]
116128
117129 if 'subdomain' in harness and harness ['subdomain' ] == subdomain :
118- if app ['name' ] != 'jupyterhub' : # Would use the hub image in that case, which we don't want.
119- print ('Change image to' , harness ['deployment' ]['image' ])
120- self .image = harness ['deployment' ]['image' ]
130+ ws_image = getattr (self , "ws_image" , None )
131+ if ws_image :
132+ # try getting the image + tag from values.yaml
133+ ch_conf = conf .get_configuration ()
134+ task_images = ch_conf ['task-images' ]
135+ for task_image in task_images :
136+ image_plus_tag = task_images [task_image ]
137+ if ws_image in image_plus_tag :
138+ ws_image = image_plus_tag
139+ logging .error (f'Found tag for image: { ws_image } ' )
140+ break
141+ else :
142+ if app ['name' ] != 'jupyterhub' : # Would use the hub image in that case, which we don't want.
143+ ws_image = harness ['deployment' ]['image' ]
144+ if ws_image :
145+ logging .info (f'Change image to { ws_image } ' )
146+ self .image = ws_image
121147 if registry ['name' ] in self .image and registry ['secret' ]:
122148 self .image_pull_secrets = registry ['secret' ]
123149
0 commit comments