FileserverStorage

class controller.storage.kubernetes.fileserver.FileserverStorage(api_client, logger)

Bases: object

Kubernetes storage layer for file servers.

Parameters:
  • api_client (ApiClient) – Kubernetes API client.

  • logger (BoundLogger) – Logger to use.

Notes

This class isn’t strictly necessary; instead, the file server service could call the storage layers for individual Kubernetes objects directly. But there are enough different objects in play that adding a thin layer to wrangle the storage objects makes the file server service easier to follow.

Methods Summary

create(namespace, objects, timeout)

Create all of the Kubernetes objects for a fileserver.

delete(name, namespace, username, timeout)

Delete a file server.

read_fileserver_state(namespace, timeout)

Read Kubernetes objects for all running fileservers.

watch_pods(namespace)

Watches the file server namespace for pod phase changes.

Methods Documentation

async create(namespace, objects, timeout)

Create all of the Kubernetes objects for a fileserver.

Create the objects in Kubernetes and then wait for the fileserver pod to start and for the ingress to be ready.

Parameters:
  • namespace (str) – Namespace where the objects should live.

  • objects (FileserverObjects) – Kubernetes objects making up the fileserver.

  • timeout (Timeout) – How long to wait for the fileserver to start.

Raises:
  • DuplicateObjectError – Raised if multiple pods were found for the fileserver job.

  • KubernetesError – Raised if there is some failure in a Kubernetes API call.

  • MissingObjectError – Raised if no pod was created for the fileserver job.

  • TimeoutError – Raised if the fileserver takes longer than the provided timeout to create or start.

Return type:

None

async delete(name, namespace, username, timeout)

Delete a file server.

Parameters:
  • name (str) – Name of the file sever objects.

  • namespace (str) – Namespace in which file servers run.

  • username (str) – Username owning the file server, to find the PVCs to delete.

  • timeout (Timeout) – Timeout on operation.

Raises:
  • KubernetesError – Raised if there is some failure in a Kubernetes API call.

  • TimeoutError – Raised if the deletion of any individual object took longer than the Kubernetes delete timeout.

Return type:

None

async read_fileserver_state(namespace, timeout)

Read Kubernetes objects for all running fileservers.

Assumes that all objects have the same name as the Job.

Parameters:
  • namespace (str) – Namespace in which to look for running fileservers.

  • timeout (Timeout) – Timeout on operation.

Returns:

Dictionary mapping usernames to the state of their running fileservers.

Return type:

dict of FileserverStateObjects

async watch_pods(namespace)

Watches the file server namespace for pod phase changes.

Technically, this iterator detects any change to a pod and returns its current phase. The change may not be a phase change. That’s good enough for our purposes.

It will continue forever until cancelled. It is meant to be run from a background task handling file server pod phase changes.

Parameters:

namespace (str) – Namespace to watch for changes.

Yields:

PodChange – Phase change of a pod in this namespace.

Raises:

KubernetesError – Raised if there is some failure in a Kubernetes API call.

Return type:

AsyncIterator[PodChange]