MCPcopy Index your code
hub / github.com/kubernetes-client/python / SharedInformer

Class SharedInformer

kubernetes/informer/informer.py:42–342  ·  view source on GitHub ↗

Watch 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 local :class:`ObjectCache` is updated and registered event-handler callbacks are invoked. Parameters

Source from the content-addressed store, hash-verified

40
41
42class SharedInformer:
43 """Watch a Kubernetes resource and maintain a local cache.
44
45 The informer starts a daemon thread that continuously watches the
46 given resource via ``list_func``. On each event the local
47 :class:`ObjectCache` is updated and registered
48 event-handler callbacks are invoked.
49
50 Parameters
51 ----------
52 list_func:
53 Bound API method used for the initial list **and** as the watch
54 source. It must accept a watch keyword argument (e.g.
55 CoreV1Api().list_namespaced_pod).
56 namespace:
57 Kubernetes namespace to watch. Pass None for cluster-scoped
58 or all-namespace list functions.
59 resync_period:
60 How often (seconds) to perform a full re-list from the API server.
61 Defaults to 0 which disables periodic resyncs.
62 label_selector:
63 Optional label selector string forwarded to the API server.
64 field_selector:
65 Optional field selector string forwarded to the API server.
66 key_func:
67 Optional callable (obj) -> str used to key objects in the
68 cache. Defaults to namespace/name.
69 """
70
71 def __init__(
72 self,
73 list_func,
74 namespace=None,
75 resync_period=0,
76 label_selector=None,
77 field_selector=None,
78 key_func=None,
79 ):
80 self._list_func = list_func
81 self._namespace = namespace
82 self._resync_period = resync_period
83 self._label_selector = label_selector
84 self._field_selector = field_selector
85
86 self._cache = ObjectCache(key_func=key_func)
87 self._handlers = {ADDED: [], MODIFIED: [], DELETED: [], BOOKMARK: [], ERROR: []}
88 self._handler_lock = threading.Lock()
89
90 self._watch = None
91 self._thread = None
92 self._stop_event = threading.Event()
93 self._resource_version = None # most recent RV seen; None forces a full re-list
94
95 # ---------------------------------------------------------------- #
96 # Public API #
97 # ---------------------------------------------------------------- #
98
99 @property

Calls

no outgoing calls