Skip to content

Commit

Permalink
Merge pull request #2076 from bobh66/watch_named_object
Browse files Browse the repository at this point in the history
Fix dynamic client watch of named resource
  • Loading branch information
k8s-ci-robot committed Apr 23, 2024
2 parents e0234d3 + cb2aa4e commit 9f9bec2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kubernetes/base/dynamic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,13 @@ def watch(self, resource, namespace=None, name=None, label_selector=None, field_
"""
if not watcher: watcher = watch.Watch()

# Use field selector to query for named instance so the watch parameter is handled properly.
if name:
field_selector = f"metadata.name={name}"

for event in watcher.stream(
resource.get,
namespace=namespace,
name=name,
field_selector=field_selector,
label_selector=label_selector,
resource_version=resource_version,
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/base/dynamic/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ def test_configmap_apis(self):
name=name, namespace='default', label_selector="e2e-test=true")
self.assertEqual(name, resp.metadata.name)

count = 0
for _ in client.watch(api, timeout=10, namespace="default", name=name):
count += 1
self.assertTrue(count > 0, msg="no events received for watch")

test_configmap['data']['config.json'] = "{}"
resp = api.patch(
name=name, namespace='default', body=test_configmap)
Expand Down

0 comments on commit 9f9bec2

Please sign in to comment.