Fix default configuration getter in client v12.0.0 (#276)

Fixes #273
This commit is contained in:
jaydesl
2020-10-22 20:41:51 +01:00
committed by GitHub
parent d03823794e
commit aad4696f20
3 changed files with 43 additions and 1 deletions

View File

@@ -252,7 +252,12 @@ class K8sAnsibleMixin(object):
self.fail(msg='Failed to load kubeconfig due to %s' % to_native(err))
# Override any values in the default configuration with Ansible parameters
configuration = kubernetes.client.Configuration()
# As of kubernetes-client v12.0.0, get_default_copy() is required here
try:
configuration = kubernetes.client.Configuration().get_default_copy()
except AttributeError:
configuration = kubernetes.client.Configuration()
for key, value in iteritems(auth):
if key in AUTH_ARG_MAP.keys() and value is not None:
if key == 'api_key':

View File

@@ -51,6 +51,27 @@
state: absent
no_log: yes
# Test new config getter (kubernetes==12.0.0)
- pip:
name:
- kubernetes==12.0.0
- openshift>=0.9.2
- coverage
virtualenv: "{{ virtualenv }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no
- include_tasks: new_config_getter.yml
vars:
ansible_python_interpreter: "{{ virtualenv_interpreter }}"
playbook_namespace: ansible-test-k8s-config-getter
- file:
path: "{{ virtualenv }}"
state: absent
no_log: yes
# Test graceful failure for older versions of openshift
- pip:

View File

@@ -0,0 +1,16 @@
---
- block:
- name: Create a namespace
k8s:
name: "{{ playbook_namespace }}"
kind: Namespace
- name: Delete namespace
k8s:
state: absent
definition:
- kind: Namespace
apiVersion: v1
metadata:
name: "{{ playbook_namespace }}"
ignore_errors: yes