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

Method watch

kubernetes/base/dynamic/client.py:161–209  ·  view source on GitHub ↗

Stream events for a resource from the Kubernetes API :param resource: The API resource object that will be used to query the API :param namespace: The namespace to query :param name: The name of the resource instance to query :param label_selector: The label

(self, resource, namespace=None, name=None, label_selector=None, field_selector=None, resource_version=None, timeout=None, watcher=None, allow_watch_bookmarks=None)

Source from the content-addressed store, hash-verified

159 return self.request('patch', path, body=body, force_conflicts=force_conflicts, **kwargs)
160
161 def watch(self, resource, namespace=None, name=None, label_selector=None, field_selector=None, resource_version=None, timeout=None, watcher=None, allow_watch_bookmarks=None):
162 """
163 Stream events for a resource from the Kubernetes API
164
165 :param resource: The API resource object that will be used to query the API
166 :param namespace: The namespace to query
167 :param name: The name of the resource instance to query
168 :param label_selector: The label selector with which to filter results
169 :param field_selector: The field selector with which to filter results
170 :param resource_version: The version with which to filter results. Only events with
171 a resource_version greater than this value will be returned
172 :param timeout: The amount of time in seconds to wait before terminating the stream
173 :param watcher: The Watcher object that will be used to stream the resource
174 :param allow_watch_bookmarks: Ask the API server to send BOOKMARK events
175
176 :return: Event object with these keys:
177 'type': The type of event such as "ADDED", "DELETED", etc.
178 'raw_object': a dict representing the watched object.
179 'object': A ResourceInstance wrapping raw_object.
180
181 Example:
182 client = DynamicClient(k8s_client)
183 watcher = watch.Watch()
184 v1_pods = client.resources.get(api_version='v1', kind='Pod')
185
186 for e in v1_pods.watch(resource_version=0, namespace=default, timeout=5, watcher=watcher):
187 print(e['type'])
188 print(e['object'].metadata)
189 # If you want to gracefully stop the stream watcher
190 watcher.stop()
191 """
192 if not watcher: watcher = watch.Watch()
193
194 # Use field selector to query for named instance so the watch parameter is handled properly.
195 if name:
196 field_selector = f"metadata.name={name}"
197
198 for event in watcher.stream(
199 resource.get,
200 namespace=namespace,
201 field_selector=field_selector,
202 label_selector=label_selector,
203 resource_version=resource_version,
204 serialize=False,
205 timeout_seconds=timeout,
206 allow_watch_bookmarks=allow_watch_bookmarks,
207 ):
208 event['object'] = ResourceInstance(resource, event['object'])
209 yield event
210
211 @meta_request
212 def request(self, method, path, body=None, **params):

Callers 2

test_configmap_apisMethod · 0.95
mainFunction · 0.80

Calls 2

streamMethod · 0.95
ResourceInstanceClass · 0.85

Tested by 1

test_configmap_apisMethod · 0.76