LabBuilder#

class controller.services.builder.lab.LabBuilder(config, base_url, logger)#

Bases: object

Construct Kubernetes objects for user lab environments.

Parameters:
  • config (LabConfig) – Lab configuration.

  • base_url (str) – Base URL for this Notebook Aspect instance.

  • logger (BoundLogger) – Logger to use.

Methods Summary

build_internal_url(username, env)

Determine the URL of a newly-spawned lab.

build_lab(*, user, lab, image, secrets[, ...])

Construct the objects that make up a user's lab.

build_object_names(username)

Construct the names of the critical lab objects for a user.

recreate_lab_state(username, objects)

Recreate user lab state from Kubernetes.

Methods Documentation

build_internal_url(username, env)#

Determine the URL of a newly-spawned lab.

The hostname and port are fixed to match the Kubernetes Service we create, but the local part is normally determined by an environment variable passed from JupyterHub.

Parameters:
  • username (str) – Username of lab user.

  • env (dict[str, str]) – Environment variables from JupyterHub.

Returns:

URL of the newly-spawned lab.

Return type:

str

build_lab(*, user, lab, image, secrets, pull_secret=None)#

Construct the objects that make up a user’s lab.

Parameters:
  • username – Username of the user.

  • lab (LabSpecification) – Specification of the lab requested.

  • image (RSPImage) – Image to use for the lab.

  • secrets (dict[str, str]) – Dictionary of secrets to expose to the lab.

  • pull_secret (V1Secret | None, default: None) – Optional pull secret for the lab pod.

  • user (GafaelfawrUserInfo) –

Returns:

Kubernetes objects that make up the user’s lab.

Return type:

LabObjects

build_object_names(username)#

Construct the names of the critical lab objects for a user.

This is used to construct names to pass to the lab storage layer to identify the objects used to get lab status or reconcile lab state.

Parameters:

username (str) – Username of the user to construct object names for.

Returns:

Names of objects for that user.

Return type:

LabObjectNames

async recreate_lab_state(username, objects)#

Recreate user lab state from Kubernetes.

Given the critical objects from a user’s lab, reconstruct the user’s lab state. This is used during reconciliation and allows us to recreate internal state from whatever currently exists in Kubernetes when the lab controller is restarted.

Parameters:
  • username (str) – User whose lab state should be recreated.

  • objects (LabStateObjects | None) – Objects for that user’s lab, or None if any required objects were not found.

Returns:

Recreated lab state, or None if the user’s lab environment did not exist or could not be parsed.

Return type:

LabState or None

Raises:

KubernetesError – Raised if Kubernetes API calls fail for reasons other than the resources not existing.