mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-06 13:02:37 +00:00
[backport/2.2] Don't wait on *List resources for info module (#331)
This commit is contained in:
@@ -279,18 +279,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 = []
|
||||
|
||||
@@ -191,6 +191,10 @@ def main():
|
||||
|
||||
k8s_ansible_mixin = K8sAnsibleMixin(module)
|
||||
k8s_ansible_mixin.client = get_api_client(module=module)
|
||||
k8s_ansible_mixin.fail_json = module.fail_json
|
||||
k8s_ansible_mixin.fail = module.fail_json
|
||||
k8s_ansible_mixin.exit_json = module.exit_json
|
||||
k8s_ansible_mixin.warn = module.warn
|
||||
execute_module(module, k8s_ansible_mixin)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user