This release is a pre-release and may not be stable for production use.
e2x-course-hub-kubespawner
e2x-course-hub-kubespawner is the Kubernetes infrastructure provider for e2x-course-hub. It translates the courses and roles that e2x-course-hub says a user is allowed to spawn into concrete KubeSpawner profile options: which container image to use, how much CPU/memory to grant, which volumes to mount, and which environment variables to set.
e2x-course-hub owns who may spawn what (courses, terms, roles). This package owns how a given role is actually realized on Kubernetes (images, resources, mounts). The two communicate through a small, provider-based contract so that either side can be swapped out independently — e.g. a different LMS could reuse this Kubernetes provider, or e2x-course-hub could be paired with a different spawner backend.
┌──────────────────────────┐ ┌──────────────────────────────────┐
│ e2x-course-hub │ │ e2x-course-hub-kubespawner │
│ │ │ │
│ Courses, Terms, Roles │ │ Image / Resource / Mount │
│ SpawnOfferingProvider ─┼─────────▶│ catalogs (YAML) │
│ (who may spawn what) │ │ K8sInfrastructureCatalogProvider│
│ │◀─────────┼─ (what a role gets, in K8s terms)│
└────────────┬─────────────┘ └─────────────────┬────────────────┘
│ │
│ profile list / pre-spawn hooks │
└──────────────────────┬───────────────────┘
▼
┌───────────────────────┐
│ JupyterHub + │
│ KubeSpawner │
└───────────────────────┘
e2x-course-hubimplementsSpawnOfferingProvider: given a user, it returns the list of(course, term, role)combinations they may spawn.- This package implements
InfrastructureCatalogProvider(registered as a plugin entry point) and consumes those offerings to build KubeSpawner'sprofile_list, resolve volume mounts before spawn, and drive the "Your Courses" spawn page.
What does it provide?
- Catalog schemas & loading (
e2x_course_hub_kubespawner.schemas,.loading) — Pydantic models and YAML loaders for image families, resource tiers, per-role profiles, and volume mounts, plus a top-levelconfig.yamlthat ties them together. K8sInfrastructureCatalogProvider(.catalog_provider) — implementse2x_course_hub'sInfrastructureCatalogProviderprotocol, exposing the catalog (image families, resource tiers, per-role profiles) soe2x-course-hubcan render its own choices.K8sSpawnerAPI(.spawner_api) — takes aSpawnOfferingProvider(supplied bye2x-course-hub) and turns each offering into a KubeSpawnerprofile_listentry, and resolves the concrete image/resources/mounts for a chosen offering at spawn time.- JupyterHub hooks (
.hooks) — ready-madeSpawner.profile_listandSpawner.pre_spawn_hookcallables, plusconfigure_autospawn()for enabling single-course auto-spawn fromjupyterhub_config.py. - Spawn page templates (
share/e2x_k8s_spawner/templates/) — a JupyterHubspawn.htmland a KubeSpawnerform.htmlfor the "Your Courses" selection page, with support for auto-spawning when a user only has one course.
Installation
This package is not yet published; install it from source alongside e2x-course-hub:
git clone https://github.com/Digiklausur/e2x-course-hub-kubespawner.git
cd e2x-course-hub-kubespawner
pip install -e .
It depends on e2x-course-hub being installed in the same environment, since it consumes and implements types from e2x_course_hub.contract.
Configuration
Configuration is split across a top-level config.yaml and the catalog files it points to. Paths inside config.yaml may be relative; they are resolved against the directory containing config.yaml itself.
config.yaml
mount_catalog_file: "mount_catalog.yaml"
image_catalog_file: "image_catalog.yaml"
resource_tier_catalog_file: "resource_tiers.yaml"
profiles:
student:
default_profile: basic
profiles:
basic: "profiles/student.yaml"
grader:
default_profile: basic
profiles:
basic: "profiles/grader.yaml"
profiles is keyed by spawn role (student, grader, ...) as defined by e2x_course_hub.contract.SpawnRole. Each role points to one or more named profile files and declares which one is the default.
The package reads the path to this file from the E2X_KUBESPAWNER_CONFIG_FILE environment variable.
Image catalog (image_catalog_file)
Defines image families, their tags, and which concrete image each spawn role maps to:
default_registry: ghcr.io/digiklausur/docker-stacks
default_pull_policy: IfNotPresent
default_family: "datascience"
families:
datascience:
display_name: "Datascience Notebook"
description: "Comes with numpy, scipy, etc."
default_tag: "2026-07-01"
images:
student: datascience-notebook-student
grader: datascience-notebook-teacher
tags:
"2026-07-01": { status: active }
"2026-04-02": { status: deprecated }
Resource tiers (resource_tier_catalog_file)
Defines selectable CPU/memory tiers per spawn role:
student:
default_tier: normal
tiers:
low:
display_name: "Low"
description: "Low resources, for courses that mostly use textbooks"
resources: { cpu_limit: 1.0, mem_guarantee: 0.5G, mem_limit: 1G }
normal:
display_name: "Normal"
description: "Standard resources sufficient for everything"
resources: { cpu_limit: 2.0, mem_guarantee: 1G, mem_limit: 2G }
Profiles (per role, referenced from config.yaml)
Each profile declares the environment variables to inject and which named mounts to attach, using ${{inputs.*}} placeholders resolved at spawn time from the username, course ID, and term ID:
display_name: "Student"
environment:
NB_USER: "${{inputs.username}}"
NBGRADER_COURSE_ID: "${{inputs.course_id}}-${{inputs.term_id}}"
mounts:
- student_home
- nbgrader_exchange_outbound
has_archive_mounts: false
Mount catalog (mount_catalog_file)
Declares the volumes available to reference by name from profiles. Three mounts are required (student_home, grader_home, course_term); archived_term is automatically derived from course_term as read-only. Any further mounts go under extra:
student_home:
name: disk2
mountPath: "/home/${{inputs.username}}"
subPath: "homes/students/${{inputs.course_id}}-${{inputs.term_id}}/${{inputs.username}}"
readOnly: false
grader_home:
name: disk2
mountPath: "/home/${{inputs.username}}"
subPath: "homes/graders/${{inputs.username}}"
readOnly: false
course_term:
name: disk2
mountPath: "/home/${{inputs.username}}/courses/${{inputs.course_id}}/${{inputs.course_id}}-${{inputs.term_id}}"
subPath: "courses/${{inputs.course_id}}/${{inputs.course_id}}-${{inputs.term_id}}"
readOnly: false
extra:
nbgrader_exchange_outbound:
name: disk3
mountPath: "/srv/nbgrader/exchange/${{inputs.course_id}}-${{inputs.term_id}}/outbound"
subPath: "nbgrader/exchanges/${{inputs.course_id}}/${{inputs.course_id}}-${{inputs.term_id}}/outbound"
readOnly: true
A profile with has_archive_mounts: true (typically graders) additionally gets a read-only archived_term mount for every other term in which the user holds the same role, so graders retain read access to past terms of the same course.
Validating the catalog
Validate the catalog before rolling out a change, e.g. in CI or as a deployment pre-sync step:
e2x-kubespawner-validate /path/to/config.yaml
It prints every problem found across all files and exits with 1, or prints Catalog is valid. and exits with 0. It checks that:
- every file matches its schema, with no unknown keys,
- every spawn role has profiles, resource tiers, and an image in every image family,
- every profile can be resolved: its mounts exist, its placeholders are known, and its mount paths (including archive mounts) don't conflict.
The hub runs the same checks every time it loads the catalog. If the catalog is invalid, the problems are logged and users see a "Course environments are currently unavailable" page.
JupyterHub integration
1. Register the catalog provider
e2x-course-hub discovers this package's catalog automatically through the e2x_course_hub.infrastructure_catalog_providers entry point declared in pyproject.toml. Installing the package is enough — no manual wiring is needed on that side.
2. Wire up the spawner hooks
In jupyterhub_config.py:
from e2x_course_hub_kubespawner._data import JUPYTERHUB_TEMPLATE_PATH, KUBESPAWNER_TEMPLATE_PATH
from e2x_course_hub_kubespawner.hooks import (
configure_autospawn,
get_pre_spawn_hook,
get_profile_list_hook,
)
import os
# set the environment variable pointing to the config.yaml
os.environ["E2X_KUBESPAWNER_CONFIG_FILE"] = "/path/to/my/config.yaml"
# spawn_offering_provider comes from e2x-course-hub
c.KubeSpawner.profile_list = get_profile_list_hook(spawn_offering_provider)
c.KubeSpawner.pre_spawn_hook = get_pre_spawn_hook(spawn_offering_provider)
# Optional: auto-spawn a user's single course without showing the picker
configure_autospawn(c, auto_spawn_single_course=True, auto_spawn_countdown=5)
c.JupyterHub.template_paths = [JUPYTERHUB_TEMPLATE_PATH]
c.KubeSpawner.additional_profile_form_template_paths = [KUBESPAWNER_TEMPLATE_PATH]
get_profile_list_hookbuilds oneprofile_listentry per (course, term) the user has access to, with one selectable choice per role/read-only combination.get_pre_spawn_hookresolves the chosen offering's image, resources, and volume mounts and applies the mounts to the spawner right before the pod is created (the image and resources are already applied through thekubespawner_overridereturned by the profile list).configure_autospawnexposesauto_spawn_single_course/auto_spawn_countdownto the Jinja templates so the spawn page can skip the picker when only one option exists.- The spawn page shows the current username above the course list, with a hint telling students to give it to their instructor. Override the texts with
c.JupyterHub.template_vars["username_label"](defaultUsername) andc.JupyterHub.template_vars["username_hint"].
Each selectable choice is identified by a SpawnChoiceSlug of the form <course_id>.<term_id>.<role>[.ro], round-tripped through to_str()/from_str() — this is the value KubeSpawner stores in user_options["profile-slug"].
Development
git clone https://github.com/Digiklausur/e2x-course-hub-kubespawner.git
cd e2x-course-hub-kubespawner
pip install -e ".[dev,test]"
pre-commit install
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for e2x-course-hub-kubespawner 0.2.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| e2x_course_hub_kubespawner-0.2.0rc1.tar.gz | 32.3 kB | With provenance | Details for e2x_course_hub_kubespawner-0.2.0rc1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| e2x_course_hub_kubespawner-0.2.0rc1-py3-none-any.whl | Python 3 | none | any | Details for e2x_course_hub_kubespawner-0.2.0rc1-py3-none-any.whl |
Total release size: 68.4 kB
Release files / e2x_course_hub_kubespawner-0.2.0rc1.tar.gz
| Download URL | e2x_course_hub_kubespawner-0.2.0rc1.tar.gz |
|---|---|
| Size | 32.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac23ddb73ff1b12199375ce83a3bea10f8ea3515ea15a46a60033969fa045cde
|
|
BLAKE2b-256 checksum How to use checksums |
fa9537058358a07f38c58429d3d3c76962d6a5eb2bdc7e82ded987f94ea4eb20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / e2x_course_hub_kubespawner-0.2.0rc1-py3-none-any.whl
| Download URL | e2x_course_hub_kubespawner-0.2.0rc1-py3-none-any.whl |
|---|---|
| Size | 36.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e298feac462f0a44e8bcc69eb5c15fd74d9f67fd82100fe2ffe966484b3e8550
|
|
BLAKE2b-256 checksum How to use checksums |
1fdd29266ec67f2a5cb00ad891b3436cd141e7b6268b4b4765cb746edc093c3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for e2x-course-hub-kubespawner 0.2.0rc1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for e2x_course_hub_kubespawner-0.2.0rc1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.