kubernetes_asyncio.dynamic.client module

class kubernetes_asyncio.dynamic.client.DynamicClient(client: ApiClient, cache_file: str | None = None, discoverer: Type[Discoverer] | None = None)

Bases: object

A kubernetes client that dynamically discovers and interacts with the kubernetes API

async create(resource: Resource, body: dict | ResourceInstance | None = None, namespace: str | None = None, **kwargs) Any
async delete(resource: Resource, name: str | None = None, namespace: str | None = None, body: dict | ResourceInstance | None = None, label_selector: str | None = None, field_selector: str | None = None, **kwargs: Any) Any
static ensure_namespace(resource: Resource, namespace: str, body: Any) str
async get(resource: Resource, name: str | None = None, namespace: str | None = None, **kwargs: Any) Any
async patch(resource: Resource, body: dict | ResourceInstance | None = None, name: str | None = None, namespace: str | None = None, **kwargs: Any) Any
async replace(resource: Resource, body: dict | ResourceInstance | None = None, name: str | None = None, namespace: str | None = None, **kwargs: Any) Any
async request(*args, **kwargs)
property resources: Discoverer
static serialize_body(body: ResourceInstance | ResourceField | dict) dict

Serialize body to raw dict so apiserver can handle it

Parameters:

body – kubernetes resource body, current support: Union[Dict, ResourceInstance]

async server_side_apply(resource: Resource, body: dict | ResourceInstance | None = None, name: str | None = None, namespace: str | None = None, force_conflicts: bool | None = None, **kwargs: Any) Any
validate(definition: dict, version: str | None = None, strict: bool = False)

validate checks a kubernetes resource definition

Args:

definition (dict): resource definition version (str): version of kubernetes to validate against strict (bool): whether unexpected additional properties should be considered errors

Returns:

warnings (list), errors (list): warnings are missing validations, errors are validation failures

property version: dict[str, Any]
static watch(resource: Resource, namespace: str | None = None, name: str | None = None, label_selector: str | None = None, field_selector: str | None = None, resource_version: int | None = None, timeout: int | None = None, watcher: Watch | None = None) Any

Stream events for a resource from the Kubernetes API

Parameters:
  • resource – The API resource object that will be used to query the API

  • namespace – The namespace to query

  • name – The name of the resource instance to query

  • label_selector – The label selector with which to filter results

  • field_selector – The field selector with which to filter results

  • resource_version – The version with which to filter results. Only events with a resource_version greater than this value will be returned

  • timeout – The amount of time in seconds to wait before terminating the stream

  • watcher – The Watcher object that will be used to stream the resource

Returns:

Event object with these keys: ‘type’: The type of event such as “ADDED”, “DELETED”, etc. ‘raw_object’: a dict representing the watched object. ‘object’: A ResourceInstance wrapping raw_object.

Example:

client = DynamicClient(k8s_client) watcher = watch.Watch() v1_pods = client.resources.get(api_version=’v1’, kind=’Pod’)

for e in v1_pods.watch(resource_version=0, namespace=default, timeout=5, watcher=watcher):

print(e[‘type’]) print(e[‘object’].metadata) # If you want to gracefully stop the stream watcher watcher.stop()

class kubernetes_asyncio.dynamic.client.EagerDiscoverer(client, cache_file)

Bases: Discoverer

A convenient container for storing discovered API resources. Allows easy searching and retrieval of specific resources.

All resources are discovered for the cluster upon object instantiation.

property api_groups

list available api groups

async discover()
async search(prefix: str | None = None, group: str | None = None, api_version: str | None = None, kind: str | None = None, **kwargs: Any) list[Resource]

Takes keyword arguments and returns matching resources. The search will happen in the following order:

prefix: The api prefix for a resource, ie, /api, /oapi, /apis. Can usually be ignored group: The api group of a resource. Will also be extracted from api_version if it is present there api_version: The api version of a resource kind: The kind of the resource arbitrary arguments (see below), in random order

The arbitrary arguments can be any valid attribute for an Resource object

update(resources)
class kubernetes_asyncio.dynamic.client.LazyDiscoverer(client, cache_file)

Bases: Discoverer

A convenient container for storing discovered API resources. Allows easy searching and retrieval of specific resources.

Resources for the cluster are loaded lazily.

property api_groups
async discover()
async search(prefix: str | None = None, group: str | None = None, api_version: str | None = None, kind: str | None = None, **kwargs: Any) list[Resource]
class kubernetes_asyncio.dynamic.client.Resource(prefix: str | None = None, group: str | None = None, api_version: str | None = None, kind: str | None = None, namespaced: bool = False, verbs: str | None = None, name: str | None = None, preferred: bool = False, client: DynamicClient | None = None, singular_name: str | None = None, short_names: str | None = None, categories: str | None = None, subresources: dict | None = None, **kwargs)

Bases: object

Represents an API resource type, containing the information required to build urls for requests

property group_version: str | None
path(name: str | None = None, namespace: str | None = None) str
to_dict() dict[str, Any]
property urls: dict[str, str]
class kubernetes_asyncio.dynamic.client.ResourceField(params)

Bases: object

A parsed instance of an API resource attribute. It exists solely to ease interaction with API objects by allowing attributes to be accessed with ‘.’ notation

to_dict() dict
class kubernetes_asyncio.dynamic.client.ResourceInstance(client, instance)

Bases: object

A parsed instance of an API resource. It exists solely to ease interaction with API objects by allowing attributes to be accessed with ‘.’ notation.

to_dict()
to_str()
class kubernetes_asyncio.dynamic.client.ResourceList(client: DynamicClient, group: str | None = None, api_version: str | None = None, base_kind: str | None = None, kind: str | None = None, base_resource_lookup=None)

Bases: Resource

Represents a list of API objects

async base_resource()
async create(*args, **kwargs)
async classmethod create_list(client, group='', api_version='v1', base_kind='', kind=None)
async delete(body, name=None, namespace=None, **kwargs)
async get(body, name=None, namespace=None, **kwargs)
async patch(*args, **kwargs)
async replace(*args, **kwargs)
to_dict()
async verb_mapper(verb, body, **kwargs)
class kubernetes_asyncio.dynamic.client.Subresource(parent, **kwargs)

Bases: Resource

Represents a subresource of an API resource. This generally includes operations like scale, as well as status objects for an instantiated resource

async create(body=None, name: str | None = None, namespace: str | None = None, **kwargs: Any)
to_dict() dict[str, str]
property urls: dict[str, str]