KubernetesObjectDeleter

class controller.storage.kubernetes.deleter.KubernetesObjectDeleter(*, create_method, delete_method, list_method, read_method, object_type, kind, logger)

Bases: KubernetesObjectCreator, Generic[T]

Generic Kubernetes object storage supporting list and delete.

This class provides a wrapper around any Kubernetes object type that implements create, read, list, and delete with logging, exception conversion, and waiting for deletion to complete. It is separate from KubernetesObjectCreator primarily to avoid having to implement the list and delete methods in the mock for every object type we manage, even if we never call list and delete.

This class is not meant to be used directly by code outside of the Kubernetes storage layer. Use one of the kind-specific watcher classes built on top of it instead.

Parameters:

Methods Summary

create(namespace, body, timeout, *[, ...])

Create a new Kubernetes object.

delete(name, namespace, timeout, *[, wait, ...])

Delete a Kubernetes object.

list(namespace, timeout, *[, label_selector])

List all objects of the appropriate kind in the namespace.

wait_for_deletion(name, namespace, timeout)

Wait for an object deletion to complete.

Methods Documentation

async create(namespace, body, timeout, *, replace=False, propagation_policy=None)

Create a new Kubernetes object.

Parameters:
  • namespace (str) – Namespace of the object.

  • body (TypeVar(T, bound= KubernetesModel)) – New object.

  • timeout (Timeout) – Timeout on operation.

  • replace (bool, default: False) – If True and an object of that name already exists in that namespace, delete the existing object and then try again.

  • propagation_policy (PropagationPolicy | None, default: None) – Propagation policy for the object deletion when deleting a conflicting object.

Raises:
Return type:

None

async delete(name, namespace, timeout, *, wait=False, propagation_policy=None, grace_period=None)

Delete a Kubernetes object.

If the object does not exist, this is silently treated as success.

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

  • namespace (str) – Namespace of the object.

  • timeout (Timeout) – Timeout on operation.

  • wait (bool, default: False) – Whether to wait for the object to be deleted.

  • propagation_policy (PropagationPolicy | None, default: None) – Propagation policy for the object deletion.

  • grace_period (timedelta | None, default: None) – How long to wait for the object to clean up before deleting it. Primarily of use for pods, where it defines how long Kubernetes will wait between sending SIGTERM and sending SIGKILL to a pod process. The default for pods if no grace period is set is 30s as of Kubernetes 1.27.1. This will be truncated to integer seconds.

Raises:
Return type:

None

async list(namespace, timeout, *, label_selector=None)

List all objects of the appropriate kind in the namespace.

Parameters:
  • namespace (str) – Namespace to list.

  • timeout (Timeout) – Timeout on operation.

  • label_selector (str | None, default: None) – Filter the returned list by the given label selector expression.

Returns:

List of objects found.

Return type:

list

Raises:
async wait_for_deletion(name, namespace, timeout)

Wait for an object deletion to complete.

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

  • namespace (str) – Namespace of the object.

  • timeout (Timeout) – How long to wait for the object to be deleted.

Raises:
Return type:

None