mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-26 21:33:02 +00:00
Don't wait on *List resources for info module (#253)
Don't wait on *List resources for info module SUMMARY We can't use the same wait logic on *List resources because they lack the same metadata that other resources have. We should ensure that we are waiting on the items in the list, but not the list itself. Waiting on the list itself results in unexpected behavior. This fixes the waiting logic when waiting on a list to wait until the list being queried contains one or more items, or the wait timeout has been reached. Each item in the list can then be waited on with the usual wait logic. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: None <None> Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None>
This commit is contained in:
@@ -360,21 +360,28 @@ class K8sAnsibleMixin(object):
|
||||
def _elapsed():
|
||||
return (datetime.now() - start).seconds
|
||||
|
||||
if result is None:
|
||||
while _elapsed() < wait_timeout:
|
||||
try:
|
||||
result = resource.get(
|
||||
name=name,
|
||||
namespace=namespace,
|
||||
label_selector=",".join(label_selectors),
|
||||
field_selector=",".join(field_selectors),
|
||||
)
|
||||
break
|
||||
except NotFoundError:
|
||||
pass
|
||||
time.sleep(wait_sleep)
|
||||
if result is None:
|
||||
return dict(resources=[], api_found=True)
|
||||
def result_empty(result):
|
||||
return (
|
||||
result is None
|
||||
or result.kind.endswith("List")
|
||||
and not result.get("items")
|
||||
)
|
||||
|
||||
while result_empty(result) and _elapsed() < wait_timeout:
|
||||
try:
|
||||
result = resource.get(
|
||||
name=name,
|
||||
namespace=namespace,
|
||||
label_selector=",".join(label_selectors),
|
||||
field_selector=",".join(field_selectors),
|
||||
)
|
||||
except NotFoundError:
|
||||
pass
|
||||
if not result_empty(result):
|
||||
break
|
||||
time.sleep(wait_sleep)
|
||||
if result_empty(result):
|
||||
return dict(resources=[], api_found=True)
|
||||
|
||||
if isinstance(result, ResourceInstance):
|
||||
satisfied_by = []
|
||||
|
||||
Reference in New Issue
Block a user