mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-13 21:12:05 +00:00
k8s_info now outputs whether the api was found (#308)
This commit is contained in:
committed by
GitHub
parent
8f14bf6c46
commit
2474ef1b2c
@@ -159,6 +159,29 @@
|
|||||||
- multi_pod_two_remove is successful
|
- multi_pod_two_remove is successful
|
||||||
- multi_pod_two_remove.changed
|
- multi_pod_two_remove.changed
|
||||||
|
|
||||||
|
- name: "Look for existing API"
|
||||||
|
k8s_info:
|
||||||
|
api_version: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
register: existing_api
|
||||||
|
|
||||||
|
- name: Check if we informed the user the api does exist
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- existing_api.api_found
|
||||||
|
|
||||||
|
- name: "Look for non-existent API"
|
||||||
|
k8s_info:
|
||||||
|
api_version: pleasedonotcreatethisresource.example.com/v7
|
||||||
|
kind: DoesNotExist
|
||||||
|
register: dne_api
|
||||||
|
|
||||||
|
- name: Check if we informed the user the api does not exist
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not dne_api.resources
|
||||||
|
- not dne_api.api_found
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Remove namespace
|
- name: Remove namespace
|
||||||
k8s:
|
k8s:
|
||||||
|
|||||||
@@ -288,8 +288,9 @@ 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,
|
||||||
wait=False, wait_sleep=5, wait_timeout=120, state='present', condition=None):
|
wait=False, wait_sleep=5, wait_timeout=120, state='present', condition=None):
|
||||||
resource = self.find_resource(kind, api_version)
|
resource = self.find_resource(kind, api_version)
|
||||||
if not resource:
|
api_found = bool(resource)
|
||||||
return dict(resources=[])
|
if not api_found:
|
||||||
|
return dict(resources=[], msg='Failed to find API for resource with apiVersion "{0}" and kind "{1}"'.format(api_version, kind), api_found=False)
|
||||||
|
|
||||||
if not label_selectors:
|
if not label_selectors:
|
||||||
label_selectors = []
|
label_selectors = []
|
||||||
@@ -317,14 +318,14 @@ class K8sAnsibleMixin(object):
|
|||||||
self.fail(msg="Failed to gather information about %s(s) even"
|
self.fail(msg="Failed to gather information about %s(s) even"
|
||||||
" after waiting for %s seconds" % (res.get('kind'), duration))
|
" after waiting for %s seconds" % (res.get('kind'), duration))
|
||||||
satisfied_by.append(res)
|
satisfied_by.append(res)
|
||||||
return dict(resources=satisfied_by)
|
return dict(resources=satisfied_by, api_found=True)
|
||||||
result = result.to_dict()
|
result = result.to_dict()
|
||||||
except (openshift.dynamic.exceptions.BadRequestError, openshift.dynamic.exceptions.NotFoundError):
|
except (openshift.dynamic.exceptions.BadRequestError, openshift.dynamic.exceptions.NotFoundError):
|
||||||
return dict(resources=[])
|
return dict(resources=[], api_found=True)
|
||||||
|
|
||||||
if 'items' in result:
|
if 'items' in result:
|
||||||
return dict(resources=result['items'])
|
return dict(resources=result['items'], api_found=True)
|
||||||
return dict(resources=[result])
|
return dict(resources=[result], api_found=True)
|
||||||
|
|
||||||
def remove_aliases(self):
|
def remove_aliases(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ EXAMPLES = r'''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
|
api_found:
|
||||||
|
description:
|
||||||
|
- Whether the specified api_version and kind were successfully mapped to an existing API on the targeted cluster.
|
||||||
|
returned: always
|
||||||
|
type: bool
|
||||||
resources:
|
resources:
|
||||||
description:
|
description:
|
||||||
- The object(s) that exists
|
- The object(s) that exists
|
||||||
|
|||||||
Reference in New Issue
Block a user