KubernetesObjectDeleter¶
- class controller.storage.kubernetes.deleter.KubernetesObjectDeleter(*, create_method, delete_method, list_method, read_method, object_type, kind, logger)¶
Bases:
KubernetesObjectCreator
,Generic
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:
create_method (
Callable
[...
,Awaitable
[Any
]]) – Method to create this type of object.delete_method (
Callable
[...
,Awaitable
[Any
]]) – Method to delete this type of object.list_method (
Callable
[...
,Awaitable
[Any
]]) – Method to list all of this type of object.read_method (
Callable
[...
,Awaitable
[Any
]]) – Method to read this type of object.object_type (
type
[TypeVar
(T
, bound=KubernetesModel
)]) – Type of object being acted on.kind (
str
) – Kubernetes kind of object being acted on.logger (
BoundLogger
) – Logger to use.
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
) – IfTrue
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:
ControllerTimeoutError – Raised if the timeout expired waiting for deletion.
KubernetesError – Raised for exceptions from the Kubernetes API server.
TimeoutError – Raised if the timeout expired.
- Return type:
- 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:
ControllerTimeoutError – Raised if the timeout expired waiting for deletion.
KubernetesError – Raised for exceptions from the Kubernetes API server.
TimeoutError – Raised if the timeout expired.
- Return type:
- async list(namespace, timeout, *, label_selector=None)¶
List all objects of the appropriate kind in the namespace.
- Parameters:
- Returns:
List of objects found.
- Return type:
- Raises:
KubernetesError – Raised for exceptions from the Kubernetes API server.
TimeoutError – Raised if the timeout expired.
- async wait_for_deletion(name, namespace, timeout)¶
Wait for an object deletion to complete.
- Parameters:
- Raises:
ControllerTimeoutError – Raised if the timeout expired.
KubernetesError – Raised for exceptions from the Kubernetes API server.
- Return type: