From 97188c0e07d99fd5b77c6e3d5c95592a7c68e540 Mon Sep 17 00:00:00 2001 From: Thomas Geirhovd Date: Mon, 3 Jun 2024 13:44:38 +0200 Subject: [PATCH] Fix watcher initial list always using default namespace --- k8s/watcher.py | 2 +- tests/k8s/test_watcher.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/k8s/watcher.py b/k8s/watcher.py index cfc2d05..4667d27 100644 --- a/k8s/watcher.py +++ b/k8s/watcher.py @@ -59,7 +59,7 @@ def watch(self, namespace=None): while self._run_forever: if last_seen_resource_version is None: # list all resources and yield a synthetic ADDED watch event for each - model_list = self._model.list_with_meta() + model_list = self._model.list_with_meta(namespace=namespace) LOG.info("Got %d %s instances from quorum read", len(model_list.items), self._model.__name__) for obj in model_list.items: event = SyntheticAddedWatchEvent(obj) diff --git a/tests/k8s/test_watcher.py b/tests/k8s/test_watcher.py index 6fcd73c..1a66537 100644 --- a/tests/k8s/test_watcher.py +++ b/tests/k8s/test_watcher.py @@ -106,7 +106,7 @@ def test_multiple_events( watcher._run_forever = False assert list(gen) == [] - api_list_with_meta.assert_called_with() + api_list_with_meta.assert_called_with(namespace=None) # verify watch_list was called with resourceVersion returned by list call api_watch_list.assert_called_with(namespace=None, resource_version=list_resource_version, allow_bookmarks=True) @@ -126,7 +126,7 @@ def stop_iteration(*args, **kwargs): assert list(gen) == [] - api_list_with_meta.assert_called_with() + api_list_with_meta.assert_called_with(namespace=None) # verify watch_list was called with resourceVersion returned by list call api_watch_list.assert_called_with(namespace=None, resource_version=list_resource_version, allow_bookmarks=True) @@ -252,7 +252,7 @@ def stop_iteration(*args, **kwargs): assert list(gen) == [] - api_list_with_meta.assert_called_with() + api_list_with_meta.assert_called_with(namespace=namespace) api_watch_list.assert_called_with(namespace=namespace, resource_version=None, allow_bookmarks=True) def test_handle_410_list(self, api_watch_list, api_list_with_meta): @@ -306,7 +306,7 @@ def test_handle_410_watch(self, api_watch_list, api_list_with_meta): _assert_event(next(gen), 1, MODIFIED, 3) # verify list and watch_list has now been called twice, and each call of watch_list used the resourceVersion # returned by the preceding list call - assert api_list_with_meta.call_args_list == [mock.call(), mock.call()] + assert api_list_with_meta.call_args_list == [mock.call(namespace=None), mock.call(namespace=None)] assert api_watch_list.call_args_list == [ mock.call(namespace=None, resource_version=first_list_resource_version, allow_bookmarks=True), mock.call(namespace=None, resource_version=second_list_resource_version, allow_bookmarks=True),