From c9157ce713259448ab66885efcace1bf9d7969c6 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sat, 27 Mar 2021 00:06:47 +0530 Subject: [PATCH] k8s: fix get_api_client usage in inventory plugin (#395) Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/k8s_inventory.yml | 2 ++ plugins/inventory/k8s.py | 2 +- plugins/module_utils/common.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/k8s_inventory.yml diff --git a/changelogs/fragments/k8s_inventory.yml b/changelogs/fragments/k8s_inventory.yml new file mode 100644 index 00000000..7800c288 --- /dev/null +++ b/changelogs/fragments/k8s_inventory.yml @@ -0,0 +1,2 @@ +bugfixes: +- k8s - fix get_api_client API in k8s inventory plugin (https://github.com/ansible-collections/community.kubernetes/pull/395). diff --git a/plugins/inventory/k8s.py b/plugins/inventory/k8s.py index f98d9d21..cc106fce 100644 --- a/plugins/inventory/k8s.py +++ b/plugins/inventory/k8s.py @@ -23,7 +23,7 @@ plugin: description: token that ensures this is a source file for the 'k8s' plugin. required: True - choices: ['k8s'] + choices: ['community.kubernetes.k8s', 'k8s'] connections: description: - Optional list of cluster connection settings. If no connections are provided, the default diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 114ba777..40e9564e 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -118,7 +118,7 @@ def configuration_digest(configuration): return digest -def get_api_client(module=None): +def get_api_client(module=None, **kwargs): auth = {} def _raise_or_fail(exc, msg): @@ -131,6 +131,8 @@ def _raise_or_fail(exc, msg): for true_name, arg_name in AUTH_ARG_MAP.items(): if module and module.params.get(arg_name): auth[true_name] = module.params.get(arg_name) + elif arg_name in kwargs and kwargs.get(arg_name) is not None: + auth[true_name] = kwargs.get(arg_name) else: env_value = os.getenv('K8S_AUTH_{0}'.format(arg_name.upper()), None) or os.getenv('K8S_AUTH_{0}'.format(true_name.upper()), None) if env_value is not None: