Skip to content

Commit 5386112

Browse files
committed
Add chart label back and add test for user server labels
1 parent 06114e0 commit 5386112

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

jupyterhub/files/hub/jupyterhub_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ def camelCaseify(s):
128128
chart_name = get_config("Chart.Name")
129129
chart_version = get_config("Chart.Version")
130130
if chart_name and chart_version:
131-
common_labels["helm.sh/chart"] = f"{chart_name}-{chart_version.replace('+', '_')}"
131+
common_labels["helm.sh/chart"] = common_labels["chart"] = (
132+
f"{chart_name}-{chart_version.replace('+', '_')}"
133+
)
132134
chart_app_version = get_config("Chart.AppVersion")
133135
if chart_app_version:
134136
common_labels["app.kubernetes.io/version"] = chart_app_version

tests/test_spawn.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import subprocess
23
import time
34

@@ -22,7 +23,7 @@ def test_spawn_basic(
2223
r = api_request.post("/users/" + jupyter_user + "/server")
2324
assert r.status_code in (201, 202)
2425
try:
25-
# check successfull spawn
26+
# check successful spawn
2627
server_model = _wait_for_user_to_spawn(
2728
api_request, jupyter_user, request_data["test_timeout"]
2829
)
@@ -36,8 +37,38 @@ def test_spawn_basic(
3637
assert r.status_code == 200
3738
assert "version" in r.json()
3839

39-
# check user pod's extra environment variable
4040
pod_name = server_model["state"]["pod_name"]
41+
42+
# check user pod's labels
43+
pod_json = subprocess.check_output(
44+
[
45+
"kubectl",
46+
"get",
47+
"pod",
48+
"--output=json",
49+
pod_name,
50+
]
51+
)
52+
pod = json.loads(pod_json)
53+
pod_labels = pod["metadata"]["labels"]
54+
55+
# check for modern labels
56+
assert pod_labels["app.kubernetes.io/name"] == "jupyterhub"
57+
assert "app.kubernetes.io/instance" in pod_labels
58+
# FIXME: app.kubernetes.io/component for user pods require kubespawner
59+
# with https://github.com/jupyterhub/kubespawner/pull/835.
60+
# assert pod_labels["app.kubernetes.io/component"] == "singleuser-server"
61+
assert pod_labels["helm.sh/chart"].startswith("jupyterhub-")
62+
assert "app.kubernetes.io/version" in pod_labels
63+
assert pod_labels["app.kubernetes.io/managed-by"] == "kubespawner"
64+
65+
# check for legacy labels still meant to be around
66+
assert pod_labels["app"] == "jupyterhub"
67+
assert "release" in pod_labels
68+
assert pod_labels["chart"].startswith("jupyterhub-")
69+
assert pod_labels["component"] == "singleuser-server"
70+
71+
# check user pod's extra environment variable
4172
c = subprocess.run(
4273
[
4374
"kubectl",

0 commit comments

Comments
 (0)