Skip to main content

e2x-course-hub-kubespawner

License: MIT Python Version

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-hub implements SpawnOfferingProvider: 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's profile_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-level config.yaml that ties them together.
  • K8sInfrastructureCatalogProvider (.catalog_provider) — implements e2x_course_hub's InfrastructureCatalogProvider protocol, exposing the catalog (image families, resource tiers, per-role profiles) so e2x-course-hub can render its own choices.
  • K8sSpawnerAPI (.spawner_api) — takes a SpawnOfferingProvider (supplied by e2x-course-hub) and turns each offering into a KubeSpawner profile_list entry, and resolves the concrete image/resources/mounts for a chosen offering at spawn time.
  • JupyterHub hooks (.hooks) — ready-made Spawner.profile_list and Spawner.pre_spawn_hook callables, plus configure_autospawn() for enabling single-course auto-spawn from jupyterhub_config.py.
  • Spawn page templates (share/e2x_k8s_spawner/templates/) — a JupyterHub spawn.html and a KubeSpawner form.html for 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_hook builds one profile_list entry per (course, term) the user has access to, with one selectable choice per role/read-only combination.
  • get_pre_spawn_hook resolves 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 the kubespawner_override returned by the profile list).
  • configure_autospawn exposes auto_spawn_single_course/auto_spawn_countdown to 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"] (default Username) and c.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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for e2x-course-hub-kubespawner 0.2.0
File Size Uploaded Provenance Actions
e2x_course_hub_kubespawner-0.2.0.tar.gz 32.3 kB With provenance Details for e2x_course_hub_kubespawner-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for e2x-course-hub-kubespawner 0.2.0
File Interpreter ABI Platform Actions
e2x_course_hub_kubespawner-0.2.0-py3-none-any.whl Python 3 none any Details for e2x_course_hub_kubespawner-0.2.0-py3-none-any.whl

Total release size: 68.4 kB

Release files / e2x_course_hub_kubespawner-0.2.0.tar.gz

Download URL e2x_course_hub_kubespawner-0.2.0.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
030184b49893f3d478dd53afa0e7a33fa1e465935491183eb9c1d394ab8f6c7c
BLAKE2b-256 checksum
How to use checksums
70c3becd3b1743a325ed5c075111838aa35706fa86b91b991e6c402d6aa188e8
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 9, 2026.

Transparency log

Release files / e2x_course_hub_kubespawner-0.2.0-py3-none-any.whl

Download URL e2x_course_hub_kubespawner-0.2.0-py3-none-any.whl
Size 36.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3119d577f1e0f205a54493555eaa34f2da2d0745ff9d07c921cc09115b6e642c
BLAKE2b-256 checksum
How to use checksums
d3cbabdb612739236982663d16c75a67447734a18f093a656ca5090272471a8d
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 9, 2026.

Transparency log

Security for e2x-course-hub-kubespawner 0.2.0

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.

Select from 2 files

Attestation for e2x_course_hub_kubespawner-0.2.0.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 9, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page