k8s handle absent resources when waiting (#51682)
* k8s wait - don't try to call to_dict on None Need to ensure that the resource dict is correctly returned for absent resources * Cope with resources without a namespace Some resources (e.g. ClusterRoleBinding) do not have a Namespace. Handle the lack of a namespace key.
This commit is contained in:
parent
031a1a5cc2
commit
9babd16942
1 changed files with 6 additions and 3 deletions
|
@ -375,11 +375,14 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
|||
try:
|
||||
response = resource.get(name=name, namespace=namespace)
|
||||
if predicate(response):
|
||||
return True, response.to_dict(), _wait_for_elapsed()
|
||||
if response:
|
||||
return True, response.to_dict(), _wait_for_elapsed()
|
||||
else:
|
||||
return True, {}, _wait_for_elapsed()
|
||||
time.sleep(timeout // 20)
|
||||
except NotFoundError:
|
||||
if state == 'absent':
|
||||
return True, response.to_dict(), _wait_for_elapsed()
|
||||
return True, {}, _wait_for_elapsed()
|
||||
if response:
|
||||
response = response.to_dict()
|
||||
return False, response, _wait_for_elapsed()
|
||||
|
@ -415,4 +418,4 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
|||
predicate = waiter.get(kind, lambda x: True)
|
||||
else:
|
||||
predicate = _resource_absent
|
||||
return self._wait_for(resource, definition['metadata']['name'], definition['metadata']['namespace'], predicate, timeout, state)
|
||||
return self._wait_for(resource, definition['metadata']['name'], definition['metadata'].get('namespace'), predicate, timeout, state)
|
||||
|
|
Loading…
Reference in a new issue