k8s_facts should not throw exceptions when not found (#44429)

Handle the case where a resource is not found by catching
the exception and returning an empty result set.
pull/44752/head
Will Thames 6 years ago committed by GitHub
parent 83fd82ca7e
commit b8907ff09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -205,10 +205,14 @@ class K8sAnsibleMixin(object):
def kubernetes_facts(self, kind, api_version, name=None, namespace=None, label_selectors=None, field_selectors=None):
resource = self.find_resource(kind, api_version)
result = resource.get(name=name,
namespace=namespace,
label_selector=','.join(label_selectors),
field_selector=','.join(field_selectors)).to_dict()
try:
result = resource.get(name=name,
namespace=namespace,
label_selector=','.join(label_selectors),
field_selector=','.join(field_selectors)).to_dict()
except openshift.dynamic.exceptions.NotFoundError:
return dict(items=[])
if 'items' in result:
return result
else:

Loading…
Cancel
Save