add support for in-memory kubeconfig (#212)

add support for in-memory kubeconfig

SUMMARY

k8s module support now authentication with kubeconfig parameter as file and dict.

Closes #139
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: None <None>
This commit is contained in:
abikouo
2021-08-30 11:31:07 +02:00
committed by GitHub
parent e21ad0212d
commit d78b64d792
7 changed files with 85 additions and 17 deletions

View File

@@ -60,6 +60,12 @@
environment:
K8S_AUTH_KUBECONFIG: ~/.kube/customconfig
- name: Using in-memory kubeconfig should succeed
kubernetes.core.k8s:
name: testing
kind: Namespace
kubeconfig: "{{ lookup('file', '~/.kube/customconfig') | from_yaml }}"
always:
- name: Return kubeconfig
copy:

View File

@@ -177,10 +177,43 @@
that:
- result is successful
- "'warnings' in result"
vars:
ansible_python_interpreter: "{{ virtualenv_interpreter }}"
- name: stat default kube config
stat:
path: "~/.kube/config"
register: _stat
- name: validate that in-memory kubeconfig authentication failed for kubernetes < 17.17.0
block:
- set_fact:
virtualenv_kubeconfig: "{{ remote_tmp_dir }}/kubeconfig"
- pip:
name:
- "kubernetes<17.17.0"
virtualenv: "{{ virtualenv_kubeconfig }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: false
- name: list namespace using in-memory kubeconfig
k8s_info:
kind: Namespace
kubeconfig: "{{ lookup('file', '~/.kube/config') | from_yaml }}"
register: _result
ignore_errors: true
vars:
ansible_python_interpreter: "{{ virtualenv_kubeconfig }}/bin/python"
- name: assert that task failed with proper message
assert:
that:
- '"kubernetes >= 17.17.0 is required" in _result.msg'
when:
- _stat.stat.exists
- _stat.stat.readable
- _stat.stat.isreg
always:
- name: Remove temp directory
file: