|
| 1 | +"""Structural tests that every hand-editable image reference in values.yaml |
| 2 | +agrees with ``jupyterhub.singleuser.image``. |
| 3 | +
|
| 4 | +e2e derives its cache key and kind side-load from ``singleuser.image``, but |
| 5 | +the pod that actually spawns comes from the *default profile*: the spawn |
| 6 | +POST has no body, so kubespawner falls through to the ``default: true`` |
| 7 | +profile, whose ``profile_options`` default choice overwrites the image. |
| 8 | +A bump that moves ``singleuser.image.tag`` but misses a profile ref would |
| 9 | +therefore have e2e report the new tag while the pod pulls the old image — |
| 10 | +green CI on stale code. ``scripts/bump_image_tags.py`` keeps these in sync |
| 11 | +on the automated path; these asserts catch the hand-edit path. |
| 12 | +""" |
| 13 | + |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +import yaml |
| 19 | + |
| 20 | +REPO_ROOT = Path(__file__).resolve().parents[2] |
| 21 | +VALUES_YAML = REPO_ROOT / "values.yaml" |
| 22 | + |
| 23 | + |
| 24 | +def _jupyterhub_values(): |
| 25 | + with VALUES_YAML.open() as f: |
| 26 | + return yaml.safe_load(f)["jupyterhub"] |
| 27 | + |
| 28 | + |
| 29 | +def _singleuser_ref(jh): |
| 30 | + image = jh["singleuser"]["image"] |
| 31 | + return f'{image["name"]}:{image["tag"]}' |
| 32 | + |
| 33 | + |
| 34 | +def test_profile_images_match_singleuser(): |
| 35 | + """Every profile's outer kubespawner_override.image AND its |
| 36 | + profile_options default-choice image must equal singleuser.image — |
| 37 | + the default choice is what the spawned pod actually runs.""" |
| 38 | + jh = _jupyterhub_values() |
| 39 | + ref = _singleuser_ref(jh) |
| 40 | + profiles = jh["custom"]["profiles"] |
| 41 | + assert profiles, "no profiles found under jupyterhub.custom.profiles" |
| 42 | + for profile in profiles: |
| 43 | + slug = profile["slug"] |
| 44 | + assert profile["kubespawner_override"]["image"] == ref, ( |
| 45 | + f"profile {slug!r}: kubespawner_override.image does not match " |
| 46 | + f"singleuser.image ({ref}) — jhub-apps' Create App shows this " |
| 47 | + "value; a half-bump here spawns a stale image" |
| 48 | + ) |
| 49 | + choices = profile["profile_options"]["image"]["choices"] |
| 50 | + for name, choice in choices.items(): |
| 51 | + assert choice["kubespawner_override"]["image"] == ref, ( |
| 52 | + f"profile {slug!r} choice {name!r}: image does not match " |
| 53 | + f"singleuser.image ({ref}) — this choice overwrites the pod " |
| 54 | + "image at spawn, so e2e would report the new tag while the " |
| 55 | + "pod pulls the old one" |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +def test_profile_choice_display_names_match_image(): |
| 60 | + """The default choice's display_name embeds the tag the profile selector |
| 61 | + shows; it must name the image the choice actually spawns.""" |
| 62 | + jh = _jupyterhub_values() |
| 63 | + image = jh["singleuser"]["image"] |
| 64 | + expected = f'{image["name"].rsplit("/", 1)[-1]}:{image["tag"]}' |
| 65 | + for profile in jh["custom"]["profiles"]: |
| 66 | + choices = profile["profile_options"]["image"]["choices"] |
| 67 | + for name, choice in choices.items(): |
| 68 | + assert choice["display_name"] == expected, ( |
| 69 | + f'profile {profile["slug"]!r} choice {name!r}: display_name ' |
| 70 | + f'{choice["display_name"]!r} does not match the image it ' |
| 71 | + f"spawns ({expected}) — the selector would show one tag and " |
| 72 | + "run another" |
| 73 | + ) |
| 74 | + |
| 75 | + |
| 76 | +def test_hub_tag_matches_singleuser_tag(): |
| 77 | + """hub and jupyterlab images are built from the same commit and tagged |
| 78 | + with the same sha; a half-bump that moves the hub pair but not the |
| 79 | + jupyterlab refs (or vice versa) must not pass unnoticed.""" |
| 80 | + jh = _jupyterhub_values() |
| 81 | + assert jh["hub"]["image"]["tag"] == jh["singleuser"]["image"]["tag"], ( |
| 82 | + "hub.image.tag and singleuser.image.tag are bumped together from the " |
| 83 | + "same commit's build; a mismatch means a partial hand-bump" |
| 84 | + ) |
0 commit comments