k8s.watcher module

class k8s.watcher.Watcher(model, capacity=1000)[source]

Bases: object

Higher-level interface to watch for changes in objects

The low-level watch_list() method will stop when the API-server drops the connection. When reconnecting using that method, the API-server will send a list of ADDED events for all objects, even if they have been seen before.

The Watcher will hide this complexity for you, and make sure to reconnect when the connection drops, and skip events that have already been seen. It additionally uses bookmarks to avoid the increased load that might be caused by reconnecting.

Parameters:
  • model (Model) – The model class to watch

  • capacity (int) – How many seen objects to keep track of

watch(namespace=None)[source]

Watch for events

Parameters:

namespace (str) – the namespace to watch for events in. The default (None) results in watching for events in all namespaces.

Returns:

a generator that yields WatchEvent objects not seen before