PodStorage#

class controller.storage.kubernetes.pod.PodStorage(api_client, logger)#

Bases: KubernetesObjectDeleter

Storage layer for Pod objects.

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

  • logger (BoundLogger) – Logger to use.

Methods Summary

delete_after_completion(name, namespace, timeout)

Wait for a pod to complete and then delete it.

events_for_pod(name, namespace, timeout)

Iterate over Kubernetes events involving a pod.

wait_for_phase(name, namespace, timeout, *, ...)

Wait for a pod to exit a set of phases.

watch_pod_changes(namespace)

Watches a namespace for pod changes (not creation or deletion).

Methods Documentation

async delete_after_completion(name, namespace, timeout)#

Wait for a pod to complete and then delete it.

This first waits for a pod to finish running, after which it deletes the pod. This method does not wait for the pod to be deleted before returning.

Parameters:
  • name (str) – Name of the pod.

  • namespace (str) – Namespace of the pod.

  • timeout (Timeout) – How long to wait for the pod to start and then stop.

Raises:
  • ControllerTimeoutError – Raised if the timeout expires while waiting for a pod phase change.

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

  • TimeoutError – Raised if the timeout expires while performing Kubernetes operations.

Return type:

None

async events_for_pod(name, namespace, timeout)#

Iterate over Kubernetes events involving a pod.

Watches for events involving a pod, yielding them. Must be cancelled by the caller when the watch is no longer of interest.

Parameters:
  • name (str) – Name of the pod.

  • namespace (str) – Namespace in which the pod is located.

  • timeout (Timeout) – How long to watch events for. When this timeout expires, the iterator will end without raising any error.

Yields:

str – The next observed event.

Raises:

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

Return type:

AsyncIterator[str]

async wait_for_phase(name, namespace, timeout, *, until_not)#

Wait for a pod to exit a set of phases.

Waits for the pod to reach a phase other than the ones given, and returns the new phase.

Parameters:
  • pod_name – Name of the pod.

  • namespace (str) – Namespace in which the pod is located.

  • timeout (Timeout) – Timeout to wait for the pod to enter another phase.

  • until_not (set[PodPhase]) – Wait until the pod is not in one of these phases (or was deleted, or the watch timed out).

  • name (str) –

Returns:

New pod phase, or None if the pod has disappeared.

Return type:

PodPhase

Raises:
async watch_pod_changes(namespace)#

Watches a namespace for pod changes (not creation or deletion).

This watch will continue forever until cancelled. It is meant to be run from a background task handling pod changes continuously.

Parameters:

namespace (str) – Namespace to watch for changes.

Yields:

PodChange – Change to a pod in this namespace.

Raises:

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

Return type:

AsyncIterator[PodChange]