mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-08 05:52:37 +00:00
Fix apis being overwritten when using k8s_cluster_info (#47)
* Update and rename 389-fix-apis-being-overwritten-in-k8s_cluster_info.yaml to 41-fix-apis-being-overwritten-in-k8s_cluster_info.yaml * Update changelogs/fragments/41-fix-apis-being-overwritten-in-k8s_cluster_info.yaml Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
breaking_changes:
|
||||||
|
- k8s_cluster_info - returned apis as list to avoid being overwritten in case of multiple version (https://github.com/ansible-collections/kubernetes.core/pull/41).
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
- name: Get core API version
|
- name: Get core API version
|
||||||
set_fact:
|
set_fact:
|
||||||
crd: "{{ api_details.apis['apiextensions.k8s.io'] }}"
|
crd: "{{ api_details.apis['apiextensions.k8s.io/v1'] }}"
|
||||||
host: "{{ api_details.connection['host'] }}"
|
host: "{{ api_details.connection['host'] }}"
|
||||||
client_version: "{{ api_details.version['client'] }}"
|
client_version: "{{ api_details.version['client'] }}"
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- api_details.apis is defined
|
- api_details.apis is defined
|
||||||
|
- api_details.apis.v1.Secret is defined
|
||||||
|
- api_details.apis.v1.Service is defined
|
||||||
- crd is defined
|
- crd is defined
|
||||||
- host is defined
|
- host is defined
|
||||||
- client_version is defined
|
- client_version is defined
|
||||||
|
|||||||
@@ -107,26 +107,15 @@ version:
|
|||||||
type: str
|
type: str
|
||||||
apis:
|
apis:
|
||||||
description:
|
description:
|
||||||
- The API(s) that exists in dictionary
|
- dictionary of group + version of resource found from cluster
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
|
elements: dict
|
||||||
contains:
|
contains:
|
||||||
api_version:
|
|
||||||
description: API version
|
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
categories:
|
categories:
|
||||||
description: API categories
|
description: API categories
|
||||||
returned: success
|
returned: success
|
||||||
type: list
|
type: list
|
||||||
group_version:
|
|
||||||
description: Resource Group version
|
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
kind:
|
|
||||||
description: Resource kind
|
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
name:
|
name:
|
||||||
description: Resource short name
|
description: Resource short name
|
||||||
returned: success
|
returned: success
|
||||||
@@ -147,14 +136,6 @@ apis:
|
|||||||
description: Resource singular name
|
description: Resource singular name
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
available_api_version:
|
|
||||||
description: All available versions of the given API
|
|
||||||
returned: success
|
|
||||||
type: list
|
|
||||||
preferred_api_version:
|
|
||||||
description: Preferred version of the given API
|
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
@@ -163,22 +144,22 @@ import copy
|
|||||||
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC)
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC)
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
def execute_module(module, client):
|
def execute_module(module, client):
|
||||||
invalidate_cache = boolean(module.params.get('invalidate_cache', True), strict=False)
|
invalidate_cache = boolean(module.params.get('invalidate_cache', True), strict=False)
|
||||||
if invalidate_cache:
|
if invalidate_cache:
|
||||||
client.resources.invalidate_cache()
|
client.resources.invalidate_cache()
|
||||||
results = {}
|
results = defaultdict(dict)
|
||||||
from openshift.dynamic.resource import ResourceList
|
from openshift.dynamic.resource import ResourceList
|
||||||
for resource in list(client.resources):
|
for resource in list(client.resources):
|
||||||
resource = resource[0]
|
resource = resource[0]
|
||||||
if isinstance(resource, ResourceList):
|
if isinstance(resource, ResourceList):
|
||||||
continue
|
continue
|
||||||
results[resource.group] = {
|
key = resource.group_version if resource.group == '' else '/'.join([resource.group, resource.group_version.split('/')[-1]])
|
||||||
'api_version': resource.group_version,
|
results[key][resource.kind] = {
|
||||||
'categories': resource.categories if resource.categories else [],
|
'categories': resource.categories if resource.categories else [],
|
||||||
'kind': resource.kind,
|
|
||||||
'name': resource.name,
|
'name': resource.name,
|
||||||
'namespaced': resource.namespaced,
|
'namespaced': resource.namespaced,
|
||||||
'preferred': resource.preferred,
|
'preferred': resource.preferred,
|
||||||
|
|||||||
Reference in New Issue
Block a user