diff --git a/kubernetes/base/dynamic/client.py b/kubernetes/base/dynamic/client.py index 64163d7b5c..067e209101 100644 --- a/kubernetes/base/dynamic/client.py +++ b/kubernetes/base/dynamic/client.py @@ -163,7 +163,7 @@ def server_side_apply(self, resource, body=None, name=None, namespace=None, forc return self.request('patch', path, body=body, force_conflicts=force_conflicts, **kwargs) - 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): + 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, _request_timeout=None): """ Stream events for a resource from the Kubernetes API @@ -177,6 +177,7 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_ :param timeout: The amount of time in seconds to wait before terminating the stream :param watcher: The Watcher object that will be used to stream the resource :param allow_watch_bookmarks: Ask the API server to send BOOKMARK events + :param _request_timeout: The amount of time in seconds to wait for a request to complete :return: Event object with these keys: 'type': The type of event such as "ADDED", "DELETED", etc. @@ -193,6 +194,10 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_ print(e['object'].metadata) # If you want to gracefully stop the stream watcher watcher.stop() + + # Using a client-side request timeout + for e in v1_pods.watch(timeout=60, _request_timeout=(5, 65)): + print(e['type']) """ if not watcher: watcher = watch.Watch() @@ -209,6 +214,7 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_ serialize=False, timeout_seconds=timeout, allow_watch_bookmarks=allow_watch_bookmarks, + _request_timeout=_request_timeout, ): event['object'] = ResourceInstance(resource, event['object']) yield event