1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
Will Thames 2018-08-28 12:51:26 +10:00 committed by GitHub
parent 83fd82ca7e
commit b8907ff09e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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