Skip to content

Commit

Permalink
Add chart label back and add test for user server labels
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Apr 27, 2024
1 parent 06114e0 commit d73782f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 3 additions & 1 deletion jupyterhub/files/hub/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def camelCaseify(s):
chart_name = get_config("Chart.Name")
chart_version = get_config("Chart.Version")
if chart_name and chart_version:
common_labels["helm.sh/chart"] = f"{chart_name}-{chart_version.replace('+', '_')}"
common_labels["helm.sh/chart"] = common_labels["chart"] = (
f"{chart_name}-{chart_version.replace('+', '_')}"
)
chart_app_version = get_config("Chart.AppVersion")
if chart_app_version:
common_labels["app.kubernetes.io/version"] = chart_app_version
Expand Down
33 changes: 31 additions & 2 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import subprocess
import time

Expand All @@ -22,7 +23,7 @@ def test_spawn_basic(
r = api_request.post("/users/" + jupyter_user + "/server")
assert r.status_code in (201, 202)
try:
# check successfull spawn
# check successful spawn
server_model = _wait_for_user_to_spawn(
api_request, jupyter_user, request_data["test_timeout"]
)
Expand All @@ -36,8 +37,36 @@ def test_spawn_basic(
assert r.status_code == 200
assert "version" in r.json()

# check user pod's extra environment variable
pod_name = server_model["state"]["pod_name"]

# check user pod's labels
pod_json = subprocess.check_output(
[
"kubectl",
"get",
"pod",
"--output=json",
pod_name,
]
)
pod = json.loads(pod_json)
pod_labels = pod["metadata"]["labels"]

# check for modern labels
assert pod_labels["app.kubernetes.io/name"] == "jupyterhub"
assert "app.kubernetes.io/instance" in pod_labels
assert pod_labels["app.kubernetes.io/component"] == "singleuser-server"
assert pod_labels["helm.sh/chart"].startswith("jupyterhub-")
assert "app.kubernetes.io/version" in pod_labels
assert pod_labels["app.kubernetes.io/managed-by"] == "kubespawner"

# check for legacy labels still meant to be around
assert pod_labels["app"] == "jupyterhub"
assert "release" in pod_labels
assert pod_labels["chart"].startswith("jupyterhub-")
assert pod_labels["component"] == "singleuser-server"

# check user pod's extra environment variable
c = subprocess.run(
[
"kubectl",
Expand Down

0 comments on commit d73782f

Please sign in to comment.