kubernetes.aio.dynamic.client module¶
- class kubernetes.aio.dynamic.client.DynamicClient(client, cache_file=None, discoverer=None)¶
Bases:
objectA kubernetes client that dynamically discovers and interacts with the kubernetes API
- async create(resource, body=None, namespace=None, **kwargs)¶
- async delete(resource, name=None, namespace=None, body=None, label_selector=None, field_selector=None, **kwargs)¶
- static ensure_namespace(resource, namespace, body)¶
- async get(resource, name=None, namespace=None, **kwargs)¶
- async patch(resource, body=None, name=None, namespace=None, **kwargs)¶
- async replace(resource, body=None, name=None, namespace=None, **kwargs)¶
- async request(*args, **kwargs)¶
- property resources¶
- static serialize_body(body)¶
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, body=None, name=None, namespace=None, force_conflicts=None, **kwargs)¶
- validate(definition, version=None, strict=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¶
- static watch(resource, namespace=None, name=None, label_selector=None, field_selector=None, resource_version=None, timeout=None, watcher=None)¶
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.aio.dynamic.client.EagerDiscoverer(client, cache_file)¶
Bases:
DiscovererA 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(**kwargs)¶
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.aio.dynamic.client.LazyDiscoverer(client, cache_file)¶
Bases:
DiscovererA 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(**kwargs)¶
- class kubernetes.aio.dynamic.client.Resource(prefix=None, group=None, api_version=None, kind=None, namespaced=False, verbs=None, name=None, preferred=False, client=None, singular_name=None, short_names=None, categories=None, subresources=None, **kwargs)¶
Bases:
objectRepresents an API resource type, containing the information required to build urls for requests
- property group_version¶
- path(name=None, namespace=None)¶
- to_dict()¶
- property urls¶
- class kubernetes.aio.dynamic.client.ResourceField(params)¶
Bases:
objectA 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()¶
- class kubernetes.aio.dynamic.client.ResourceInstance(client, instance)¶
Bases:
objectA 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.aio.dynamic.client.ResourceList(client, group='', api_version='v1', base_kind='', kind=None, base_resource_lookup=None)¶
Bases:
ResourceRepresents 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.aio.dynamic.client.Subresource(parent, **kwargs)¶
Bases:
ResourceRepresents 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=None, namespace=None, **kwargs)¶
- to_dict()¶
- property urls¶