Fix dynamic client watch of named resource

Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
This commit is contained in:
Bob Haddleton 2023-06-16 10:46:05 -05:00
parent 08aabad06a
commit cb2aa4ef80
2 changed files with 9 additions and 1 deletions

View File

@ -195,10 +195,13 @@ class DynamicClient(object):
"""
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,

View File

@ -468,6 +468,11 @@ class TestDynamicClient(unittest.TestCase):
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)