mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-28 02:14:41 +00:00
Fix client regression from turbo mode refactor (#79)
* Fix client regression from turbo mode refactor The turbo mode refactoring introduced a regression where the kubernetes client can fail to find the kubeconfig. This happens because get_api_client is called twice and the second time it is called without the module being passed as an argument. Without this, the configuration will use defaults. This will be a problem if the user has specified a location for the kubeconfig that's different from default, for example. * Add tests
This commit is contained in:
@@ -24,6 +24,38 @@
|
|||||||
that:
|
that:
|
||||||
- output is failed
|
- 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
|
- name: Ensure k8s_info works with empty resources
|
||||||
k8s_info:
|
k8s_info:
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ class KubernetesLookup(K8sAnsibleMixin):
|
|||||||
|
|
||||||
def run(self, terms, variables=None, **kwargs):
|
def run(self, terms, variables=None, **kwargs):
|
||||||
self.params = kwargs
|
self.params = kwargs
|
||||||
self.client = get_api_client()
|
self.client = get_api_client(**kwargs)
|
||||||
|
|
||||||
cluster_info = kwargs.get('cluster_info')
|
cluster_info = kwargs.get('cluster_info')
|
||||||
if cluster_info == 'version':
|
if cluster_info == 'version':
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ class K8sAnsibleMixin(object):
|
|||||||
changed = False
|
changed = False
|
||||||
results = []
|
results = []
|
||||||
try:
|
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
|
# Hopefully the kubernetes client will provide its own exception class one day
|
||||||
except (urllib3.exceptions.RequestError) as e:
|
except (urllib3.exceptions.RequestError) as e:
|
||||||
self.fail_json(msg="Couldn't connect to Kubernetes: %s" % str(e))
|
self.fail_json(msg="Couldn't connect to Kubernetes: %s" % str(e))
|
||||||
|
|||||||
Reference in New Issue
Block a user