From 1c9551f93d5d58c22877abb57e57778d0b3d8845 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Thu, 25 Oct 2018 00:33:20 +1000 Subject: [PATCH] Use kubeconfig if either context or kubeconfig is set (#47373) (#47496) * Use kubeconfig if either context or kubeconfig is set (#47373) kubeconfig should be loaded if *either* or both of context or kubeconfig is set (this allows picking a context and default kubeconfig or picking a kubeconfig with default context) Fixes #47149 (cherry picked from commit 00ccad97642dd125c196e0336c79bac0a5250316) * Add changelog for k8s auth config fix --- changelogs/fragments/k8s_auth_kubeconfig.yml | 2 ++ lib/ansible/module_utils/k8s/common.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/k8s_auth_kubeconfig.yml diff --git a/changelogs/fragments/k8s_auth_kubeconfig.yml b/changelogs/fragments/k8s_auth_kubeconfig.yml new file mode 100644 index 00000000000..d4c55494889 --- /dev/null +++ b/changelogs/fragments/k8s_auth_kubeconfig.yml @@ -0,0 +1,2 @@ +bugfixes: + - k8s - allow kubeconfig or context to be set without the other diff --git a/lib/ansible/module_utils/k8s/common.py b/lib/ansible/module_utils/k8s/common.py index f60c232fe9a..a49497577ff 100644 --- a/lib/ansible/module_utils/k8s/common.py +++ b/lib/ansible/module_utils/k8s/common.py @@ -152,7 +152,7 @@ class K8sAnsibleMixin(object): if auth_set('username', 'password', 'host') or auth_set('api_key', 'host'): # We have enough in the parameters to authenticate, no need to load incluster or kubeconfig pass - elif auth_set('kubeconfig', 'context'): + elif auth_set('kubeconfig') or auth_set('context'): kubernetes.config.load_kube_config(auth.get('kubeconfig'), auth.get('context')) else: # First try to do incluster config, then kubeconfig