k8s: Handle ValueError raised (#330)

This commit is contained in:
Abhijeet Kasurde
2021-01-12 21:38:58 +05:30
committed by GitHub
parent a6cb6c4821
commit 9059f2c526
2 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
bugfixes:
- k8s - handle ValueError when namespace is not provided (https://github.com/ansible-collections/community.kubernetes/pull/330).

View File

@@ -633,8 +633,8 @@ class K8sAnsibleMixin(object):
except DynamicApiError as exc:
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc.body),
error=exc.status, status=exc.status, reason=exc.reason)
except Exception as exc:
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(to_native(exc)),
except ValueError as value_exc:
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(to_native(value_exc)),
error='', status='', reason='')
if state == 'absent':
@@ -708,6 +708,11 @@ class K8sAnsibleMixin(object):
if self.warnings:
msg += "\n" + "\n ".join(self.warnings)
self.fail_json(msg=msg, error=exc.status, status=exc.status, reason=exc.reason)
except Exception as exc:
msg = "Failed to create object: {0}".format(exc)
if self.warnings:
msg += "\n" + "\n ".join(self.warnings)
self.fail_json(msg=msg, error='', status='', reason='')
success = True
result['result'] = k8s_obj
if wait and not self.check_mode: