From 632295f19404d9ac6b9c34b56071a2df4c13973b Mon Sep 17 00:00:00 2001 From: brendandburns <5751682+brendandburns@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:03:49 +0000 Subject: [PATCH 1/3] Initial plan From 128e286aff5710ca72e742c86ef9c7539c609869 Mon Sep 17 00:00:00 2001 From: brendandburns <5751682+brendandburns@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:06:30 +0000 Subject: [PATCH 2/3] test: cover dynamic watch client request timeout Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- kubernetes/dynamic/client_test.py | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/kubernetes/dynamic/client_test.py b/kubernetes/dynamic/client_test.py index b424b78e9f..091ff53cbc 100644 --- a/kubernetes/dynamic/client_test.py +++ b/kubernetes/dynamic/client_test.py @@ -21,6 +21,7 @@ from .client import DynamicClient from .exceptions import NotFoundError +from .resource import Resource class DynamicClientTest(unittest.TestCase): @@ -235,6 +236,41 @@ def get(self, **kwargs): self.assertEqual(True, watcher.kwargs['send_initial_events']) self.assertEqual('NotOlderThan', watcher.kwargs['resource_version_match']) + def test_resource_watch_forwards_request_timeout(self): + class FakeWatcher: + def __init__(self): + self.kwargs = None + + def stream(self, func, **kwargs): + self.kwargs = kwargs + return iter(()) + + dynamic = DynamicClient.__new__(DynamicClient) + resource = Resource( + prefix='apis', + api_version='v1', + kind='Pod', + name='pods', + client=dynamic, + ) + + for request_timeout in (5, (2, 5)): + watcher = FakeWatcher() + list(resource.watch( + watcher=watcher, + timeout=30, + _request_timeout=request_timeout, + )) + + self.assertEqual(request_timeout, watcher.kwargs['_request_timeout']) + self.assertEqual(30, watcher.kwargs['timeout_seconds']) + + watcher = FakeWatcher() + list(resource.watch(watcher=watcher, timeout=30)) + + self.assertNotIn('_request_timeout', watcher.kwargs) + self.assertEqual(30, watcher.kwargs['timeout_seconds']) + def test_request_builds_send_initial_events_query_params(self): class Handler(BaseHTTPRequestHandler): def do_GET(self): From 42d5c2f3b6cd8735330c3269615aa8dac5c98029 Mon Sep 17 00:00:00 2001 From: brendandburns <5751682+brendandburns@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:07:41 +0000 Subject: [PATCH 3/3] fix: forward client timeout through dynamic watch Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- kubernetes/dynamic/client.py | 17 +++++++++++++++-- kubernetes/dynamic/client_test.py | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/kubernetes/dynamic/client.py b/kubernetes/dynamic/client.py index 05f6bdb81c..14eaf91c71 100644 --- a/kubernetes/dynamic/client.py +++ b/kubernetes/dynamic/client.py @@ -158,7 +158,12 @@ 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, send_initial_events=None, resource_version_match=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, send_initial_events=None, + resource_version_match=None, _request_timeout=None + ): """ Stream events for a resource from the Kubernetes API @@ -169,7 +174,10 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_ :param field_selector: The field selector with which to filter results :param resource_version: The version with which to filter results. Only events with a resource_version greater than this value will be returned - :param timeout: The amount of time in seconds to wait before terminating the stream + :param timeout: The server-side amount of time in seconds to wait before terminating + the stream + :param _request_timeout: The client-side request timeout in seconds, or a + (connect, read) timeout tuple :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 send_initial_events: Ask the API server to begin the stream with synthetic events @@ -199,6 +207,10 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_ if name: field_selector = f"metadata.name={name}" + request_timeout_kwargs = {} + if _request_timeout is not None: + request_timeout_kwargs['_request_timeout'] = _request_timeout + for event in watcher.stream( resource.get, namespace=namespace, @@ -210,6 +222,7 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_ allow_watch_bookmarks=allow_watch_bookmarks, send_initial_events=send_initial_events, resource_version_match=resource_version_match, + **request_timeout_kwargs, ): event['object'] = ResourceInstance(resource, event['object']) yield event diff --git a/kubernetes/dynamic/client_test.py b/kubernetes/dynamic/client_test.py index 091ff53cbc..2e33d513cb 100644 --- a/kubernetes/dynamic/client_test.py +++ b/kubernetes/dynamic/client_test.py @@ -262,7 +262,8 @@ def stream(self, func, **kwargs): _request_timeout=request_timeout, )) - self.assertEqual(request_timeout, watcher.kwargs['_request_timeout']) + self.assertEqual( + request_timeout, watcher.kwargs['_request_timeout']) self.assertEqual(30, watcher.kwargs['timeout_seconds']) watcher = FakeWatcher()