diff --git a/molecule/default/tasks/full.yml b/molecule/default/tasks/full.yml index 608e3d21..2e3268ed 100644 --- a/molecule/default/tasks/full.yml +++ b/molecule/default/tasks/full.yml @@ -24,6 +24,38 @@ that: - output is failed + - block: + - name: Copy default kubeconfig + copy: + remote_src: yes + src: ~/.kube/config + dest: ~/.kube/customconfig + + - name: Delete default kubeconfig + file: + path: ~/.kube/config + state: absent + + - name: Using custom config location should succeed + kubernetes.core.k8s: + name: testing + kind: Namespace + kubeconfig: ~/.kube/customconfig + + always: + - name: Return kubeconfig + copy: + remote_src: yes + src: ~/.kube/customconfig + dest: ~/.kube/config + ignore_errors: yes + + - name: Delete custom config + file: + path: ~/.kube/customconfig + state: absent + ignore_errors: yes + - name: Ensure k8s_info works with empty resources k8s_info: kind: Deployment diff --git a/plugins/lookup/k8s.py b/plugins/lookup/k8s.py index 55125104..9520a1f6 100644 --- a/plugins/lookup/k8s.py +++ b/plugins/lookup/k8s.py @@ -239,7 +239,7 @@ class KubernetesLookup(K8sAnsibleMixin): def run(self, terms, variables=None, **kwargs): self.params = kwargs - self.client = get_api_client() + self.client = get_api_client(**kwargs) cluster_info = kwargs.get('cluster_info') if cluster_info == 'version': diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 5b0744e0..4474eed3 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -508,7 +508,7 @@ class K8sAnsibleMixin(object): changed = False results = [] try: - self.client = get_api_client() + self.client = get_api_client(self.module) # Hopefully the kubernetes client will provide its own exception class one day except (urllib3.exceptions.RequestError) as e: self.fail_json(msg="Couldn't connect to Kubernetes: %s" % str(e))