11# load the config object (satisfies linters)
2-
32c = get_config () # noqa
43
54import glob
2524configuration_directory = os .path .dirname (os .path .realpath (__file__ ))
2625sys .path .insert (0 , configuration_directory )
2726
28- from z2jh import ( # noqa
27+ from z2jh import ( # noqa
2928 get_config ,
3029 get_name ,
3130 get_name_env ,
@@ -118,28 +117,35 @@ def camelCaseify(s):
118117)
119118
120119# implement common labels
121- # this duplicates the jupyterhub.commonLabels helper
120+ # This mimics the jupyterhub.commonLabels helper, but declares managed-by to
121+ # kubespawner instead of helm.
122+ #
123+ # The labels app and release are old labels enabled to be deleted in z2jh 5, but
124+ # for now retained to avoid a breaking change in z2jh 4 that would force user
125+ # server restarts. Restarts would be required because NetworkPolicy resources
126+ # must select old/new pods with labels that then needs to be seen on both
127+ # old/new pods, and we want these resources to keep functioning for old/new user
128+ # server pods during an upgrade.
129+ #
122130common_labels = c .KubeSpawner .common_labels = {}
123- common_labels ["app" ] = get_config (
131+ common_labels ["app.kubernetes.io/name" ] = common_labels [ "app " ] = get_config (
124132 "nameOverride" ,
125133 default = get_config ("Chart.Name" , "jupyterhub" ),
126134)
127- common_labels ["heritage" ] = "jupyterhub"
135+ release = get_config ("Release.Name" )
136+ if release :
137+ common_labels ["app.kubernetes.io/instance" ] = common_labels ["release" ] = release
128138chart_name = get_config ("Chart.Name" )
129139chart_version = get_config ("Chart.Version" )
130140if chart_name and chart_version :
131- common_labels ["chart" ] = "{}-{}" .format (
132- chart_name ,
133- chart_version .replace ("+" , "_" ),
141+ common_labels ["helm.sh/chart" ] = common_labels ["chart" ] = (
142+ f"{ chart_name } -{ chart_version .replace ('+' , '_' )} "
134143 )
135- release = get_config ("Release.Name" )
136- if release :
137- common_labels ["release" ] = release
144+ common_labels ["app.kubernetes.io/managed-by" ] = "kubespawner"
138145
139146c .KubeSpawner .namespace = os .environ .get ("POD_NAMESPACE" , "default" )
140147
141148# Max number of consecutive failures before the Hub restarts itself
142- # requires jupyterhub 0.9.2
143149set_config_if_not_none (
144150 c .Spawner ,
145151 "consecutive_failure_limit" ,
@@ -260,7 +266,8 @@ def camelCaseify(s):
260266storage_type = get_config ("singleuser.storage.type" )
261267if storage_type == "dynamic" :
262268 pvc_name_template = get_config ("singleuser.storage.dynamic.pvcNameTemplate" )
263- c .KubeSpawner .pvc_name_template = pvc_name_template
269+ if pvc_name_template :
270+ c .KubeSpawner .pvc_name_template = pvc_name_template
264271 volume_name_template = get_config ("singleuser.storage.dynamic.volumeNameTemplate" )
265272 c .KubeSpawner .storage_pvc_ensure = True
266273 set_config_if_not_none (
@@ -279,13 +286,14 @@ def camelCaseify(s):
279286 c .KubeSpawner .volumes = [
280287 {
281288 "name" : volume_name_template ,
282- "persistentVolumeClaim" : {"claimName" : pvc_name_template },
289+ "persistentVolumeClaim" : {"claimName" : "{ pvc_name_template}" },
283290 }
284291 ]
285292 c .KubeSpawner .volume_mounts = [
286293 {
287294 "mountPath" : get_config ("singleuser.storage.homeMountPath" ),
288295 "name" : volume_name_template ,
296+ "subPath" : get_config ("singleuser.storage.dynamic.subPath" ),
289297 }
290298 ]
291299elif storage_type == "static" :
@@ -491,7 +499,6 @@ def camelCaseify(s):
491499 cfg .pop ("keys" , None )
492500 c [app ].update (cfg )
493501
494-
495502# load /usr/local/etc/jupyterhub/jupyterhub_config.d config files
496503config_dir = "/usr/local/etc/jupyterhub/jupyterhub_config.d"
497504if os .path .isdir (config_dir ):
0 commit comments