mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-14 13:32:14 +00:00
[backport/2.3] continue waiting when an exception is raised (#408)
Depends-On: #446
Continue waiting when an exception is raised
SUMMARY
When an exception is raised and the wait_timeout is not reached, we should continue waiting as this may occurs due to temporary issue on cluster
Fixes #407
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION
Reviewed-by: Mike Graves mgraves@redhat.com
Reviewed-by: Abhijeet Kasurde
(cherry picked from commit f418353)
This commit is contained in:
2
changelogs/fragments/408-fix-wait-on-exception.yml
Normal file
2
changelogs/fragments/408-fix-wait-on-exception.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- Catch expectation raised when the process is waiting for resources (https://github.com/ansible-collections/kubernetes.core/issues/407).
|
||||||
@@ -421,18 +421,25 @@ class K8sAnsibleMixin(object):
|
|||||||
field_selectors = []
|
field_selectors = []
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
try:
|
params = dict(
|
||||||
result = resource.get(
|
|
||||||
name=name,
|
name=name,
|
||||||
namespace=namespace,
|
namespace=namespace,
|
||||||
label_selector=",".join(label_selectors),
|
label_selector=",".join(label_selectors),
|
||||||
field_selector=",".join(field_selectors),
|
field_selector=",".join(field_selectors),
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
result = resource.get(**params)
|
||||||
except BadRequestError:
|
except BadRequestError:
|
||||||
return dict(resources=[], api_found=True)
|
return dict(resources=[], api_found=True)
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
if not wait or name is None:
|
if not wait or name is None:
|
||||||
return dict(resources=[], api_found=True)
|
return dict(resources=[], api_found=True)
|
||||||
|
except Exception as e:
|
||||||
|
if not wait or name is None:
|
||||||
|
err = "Exception '{0}' raised while trying to get resource using {1}".format(
|
||||||
|
e, params
|
||||||
|
)
|
||||||
|
return dict(resources=[], msg=err, api_found=True)
|
||||||
|
|
||||||
if not wait:
|
if not wait:
|
||||||
result = result.to_dict()
|
result = result.to_dict()
|
||||||
@@ -452,21 +459,27 @@ class K8sAnsibleMixin(object):
|
|||||||
and not result.get("items")
|
and not result.get("items")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
last_exception = None
|
||||||
while result_empty(result) and _elapsed() < wait_timeout:
|
while result_empty(result) and _elapsed() < wait_timeout:
|
||||||
try:
|
try:
|
||||||
result = resource.get(
|
result = resource.get(**params)
|
||||||
name=name,
|
|
||||||
namespace=namespace,
|
|
||||||
label_selector=",".join(label_selectors),
|
|
||||||
field_selector=",".join(field_selectors),
|
|
||||||
)
|
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
pass
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
last_exception = e
|
||||||
if not result_empty(result):
|
if not result_empty(result):
|
||||||
break
|
break
|
||||||
time.sleep(wait_sleep)
|
time.sleep(wait_sleep)
|
||||||
if result_empty(result):
|
if result_empty(result):
|
||||||
return dict(resources=[], api_found=True)
|
res = dict(resources=[], api_found=True)
|
||||||
|
if last_exception is not None:
|
||||||
|
res[
|
||||||
|
"msg"
|
||||||
|
] = "Exception '%s' raised while trying to get resource using %s" % (
|
||||||
|
last_exception,
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
return res
|
||||||
|
|
||||||
if isinstance(result, ResourceInstance):
|
if isinstance(result, ResourceInstance):
|
||||||
satisfied_by = []
|
satisfied_by = []
|
||||||
@@ -583,6 +596,8 @@ class K8sAnsibleMixin(object):
|
|||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
return True, {}, _wait_for_elapsed()
|
return True, {}, _wait_for_elapsed()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
if response:
|
if response:
|
||||||
response = response.to_dict()
|
response = response.to_dict()
|
||||||
return False, response, _wait_for_elapsed()
|
return False, response, _wait_for_elapsed()
|
||||||
|
|||||||
Reference in New Issue
Block a user