diff --git a/pykube/query.py b/pykube/query.py index ba4232d..676ba1e 100644 --- a/pykube/query.py +++ b/pykube/query.py @@ -103,8 +103,9 @@ def get_or_none(self, *args, **kwargs): except ObjectDoesNotExist: return None - def watch(self, since=None): + def watch(self, since=None, *, params=None): query = self._clone(WatchQuery) + query.params = params if since is now: query.resource_version = self.response["metadata"]["resourceVersion"] elif since is not None: @@ -156,11 +157,13 @@ class WatchQuery(BaseQuery): def __init__(self, *args, **kwargs): self.resource_version = kwargs.pop("resource_version", None) + self.params = None super(WatchQuery, self).__init__(*args, **kwargs) self._response = None def object_stream(self): - params = {"watch": "true"} + params = dict(self.params or {}) # shallow clone for local use + params["watch"] = "true" if self.resource_version is not None: params["resourceVersion"] = self.resource_version kwargs = { diff --git a/tests/test_watch.py b/tests/test_watch.py index 6575908..c422f0f 100644 --- a/tests/test_watch.py +++ b/tests/test_watch.py @@ -38,3 +38,18 @@ def test_watch_response_is_set_on_iter(api): assert api.get.call_count == 1 assert api.get.call_args_list[0][1]['stream'] is True assert 'watch=true' in api.get.call_args_list[0][1]['url'] + + +def test_watch_params_are_passed_through(api): + line1 = json.dumps({'type': 'ADDED', 'object': {}}).encode('utf-8') + expected_response = MagicMock() + expected_response.iter_lines.return_value = [line1] + api.get.return_value = expected_response + + params = dict(timeoutSeconds=123, arbitraryParam=456) + stream = Query(api, Pod).watch(params=params) + next(iter(stream)) + + assert api.get.call_count == 1 + assert 'timeoutSeconds=123' in api.get.call_args_list[0][1]['url'] + assert 'arbitraryParam=456' in api.get.call_args_list[0][1]['url']