@@ -144,7 +144,7 @@ def patch(self, resource, body=None, name=None, namespace=None, **kwargs):
144144
145145 return self .request ('patch' , path , body = body , content_type = content_type , ** kwargs )
146146
147- def watch (self , resource , namespace = None , name = None , label_selector = None , field_selector = None , resource_version = None , timeout = None ):
147+ def watch (self , resource , namespace = None , name = None , label_selector = None , field_selector = None , resource_version = None , timeout = None , watcher = None ):
148148 """
149149 Stream events for a resource from the Kubernetes API
150150
@@ -156,6 +156,7 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_
156156 :param resource_version: The version with which to filter results. Only events with
157157 a resource_version greater than this value will be returned
158158 :param timeout: The amount of time in seconds to wait before terminating the stream
159+ :param watcher: The Watcher object that will be used to stream the resource
159160
160161 :return: Event object with these keys:
161162 'type': The type of event such as "ADDED", "DELETED", etc.
@@ -164,13 +165,17 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_
164165
165166 Example:
166167 client = DynamicClient(k8s_client)
168+ watcher = watch.Watch()
167169 v1_pods = client.resources.get(api_version='v1', kind='Pod')
168170
169- for e in v1_pods.watch(resource_version=0, namespace=default, timeout=5):
171+ for e in v1_pods.watch(resource_version=0, namespace=default, timeout=5, watcher=watcher ):
170172 print(e['type'])
171173 print(e['object'].metadata)
174+ # If you want to gracefully stop the stream watcher
175+ watcher.stop()
172176 """
173- watcher = watch .Watch ()
177+ if not watcher : watcher = watch .Watch ()
178+
174179 for event in watcher .stream (
175180 resource .get ,
176181 namespace = namespace ,
0 commit comments