Skip to content

Commit d955a7b

Browse files
committed
Merge branch 'feature/CH-110' of github.com:MetaCell/cloud-harness into develop
2 parents c882f43 + d42f1f7 commit d955a7b

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

applications/jupyterhub/deploy/resources/hub/jupyterhub_config.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# load the config object (satisfies linters)
2-
32
c = get_config() # noqa
43

54
import glob
@@ -25,7 +24,7 @@
2524
configuration_directory = os.path.dirname(os.path.realpath(__file__))
2625
sys.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+
#
122130
common_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
128138
chart_name = get_config("Chart.Name")
129139
chart_version = get_config("Chart.Version")
130140
if 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

139146
c.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
143149
set_config_if_not_none(
144150
c.Spawner,
145151
"consecutive_failure_limit",
@@ -260,7 +266,8 @@ def camelCaseify(s):
260266
storage_type = get_config("singleuser.storage.type")
261267
if 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
]
291299
elif 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
496503
config_dir = "/usr/local/etc/jupyterhub/jupyterhub_config.d"
497504
if os.path.isdir(config_dir):

applications/jupyterhub/deploy/resources/hub/z2jh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Methods here can be imported by extraConfig in values.yaml
55
"""
6+
67
import os
78
from collections.abc import Mapping
89
from functools import lru_cache
@@ -141,4 +142,4 @@ def set_config_if_not_none(cparent, name, key):
141142
"""
142143
data = get_config(key)
143144
if data is not None:
144-
setattr(cparent, name, data)
145+
setattr(cparent, name, data)

applications/jupyterhub/src/harness_jupyter/harness_jupyter/jupyterhub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ def change_pod_manifest(self: KubeSpawner):
225225

226226
# set user quota cpu/mem usage if value has a "value" else don't change the value
227227
logging.info("Setting user quota cpu/mem usage")
228-
set_key_value(self, key="cpu_guarantee", value=user_quotas.get(
229-
"quota-ws-guaranteecpu"))
228+
set_key_value(self, key="cpu_guarantee", value=float(user_quotas.get(
229+
"quota-ws-guaranteecpu")))
230230
set_key_value(self, key="cpu_limit",
231-
value=user_quotas.get("quota-ws-maxcpu"))
231+
value=float(user_quotas.get("quota-ws-maxcpu")))
232232
set_key_value(self, key="mem_guarantee", value=user_quotas.get(
233233
"quota-ws-guaranteemem"), unit="G")
234234
set_key_value(self, key="mem_limit", value=user_quotas.get(

libraries/cloudharness-common/cloudharness/auth/quota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_user_quotas(application_config: ApplicationConfig = None, user_id: str =
3939
valid_keys_map = {key for key in base_quotas}
4040

4141
try:
42-
return get_user_attributes(user_id, valid_keys=valid_keys_map, default_attributes=base_quotas)
42+
return get_user_attributes(user_id, valid_keys=valid_keys_map, default_attributes=base_quotas, transform_value_fn=attribute_to_quota)
4343

4444
except UserNotFound as e:
4545
log.warning("Quotas not available: error retrieving user: %s", user_id)

0 commit comments

Comments
 (0)