kubernetes.informer.informer module¶
Informer implementation for the Kubernetes Python client.
Provides SharedInformer: a background watcher that keeps a local ObjectCache in sync with the Kubernetes API server and notifies registered event-handler callbacks.
Bases:
objectWatch a Kubernetes resource and maintain a local cache.
The informer starts a daemon thread that continuously watches the given resource via
list_func. On each event the localObjectCacheis updated and registered event-handler callbacks are invoked.Parameters¶
- list_func:
Bound API method used for the initial list and as the watch source. It must accept a watch keyword argument (e.g. CoreV1Api().list_namespaced_pod).
- namespace:
Kubernetes namespace to watch. Pass None for cluster-scoped or all-namespace list functions.
- resync_period:
How often (seconds) to perform a full re-list from the API server. Defaults to 0 which disables periodic resyncs.
- label_selector:
Optional label selector string forwarded to the API server.
- field_selector:
Optional field selector string forwarded to the API server.
- key_func:
Optional callable (obj) -> str used to key objects in the cache. Defaults to namespace/name.
Register a callback for a specific event type.
Parameters¶
- event_type:
One of
ADDED,MODIFIED,DELETED,BOOKMARKorERROR.- handler:
Callable invoked with the event object (or the raw exception for ERROR events).
The
ObjectCachemaintained by this informer.
Deregister a previously registered handler.
No-op if handler is not registered.
Start the background watch loop in a daemon thread.
Calling
start()more than once without an interveningstop()is a no-op.
Ask the background watch loop to stop and join the thread.