From ef6722d29049ea05b7675cce4a9bf81f771452b9 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 2 Jul 2020 18:48:41 +0530 Subject: [PATCH] helm: Add support for K8S_AUTH_CONTEXT, K8S_AUTH_KUBECONFIG env (#141) Added support for K8S_AUTH_CONTEXT, K8S_AUTH_KUBECONFIG env --- changelogs/fragments/140_kubeconfig_env.yaml | 3 +++ plugins/modules/helm.py | 8 +++++--- plugins/modules/helm_info.py | 8 +++++--- 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/140_kubeconfig_env.yaml diff --git a/changelogs/fragments/140_kubeconfig_env.yaml b/changelogs/fragments/140_kubeconfig_env.yaml new file mode 100644 index 00000000..48a3e99a --- /dev/null +++ b/changelogs/fragments/140_kubeconfig_env.yaml @@ -0,0 +1,3 @@ +minor_changes: +- helm - add support for K8S_AUTH_KUBECONFIG and K8S_AUTH_CONTEXT environment variable (https://github.com/ansible-collections/community.kubernetes/issues/140). +- helm_info - add support for K8S_AUTH_KUBECONFIG and K8S_AUTH_CONTEXT environment variable (https://github.com/ansible-collections/community.kubernetes/issues/140). diff --git a/plugins/modules/helm.py b/plugins/modules/helm.py index 5b593fd9..9ca1beed 100644 --- a/plugins/modules/helm.py +++ b/plugins/modules/helm.py @@ -98,10 +98,12 @@ options: kube_context: description: - Helm option to specify which kubeconfig context to use. + - If the value is not specified in the task, the value of environment variable C(K8S_AUTH_CONTEXT) will be used instead. type: str kubeconfig_path: description: - Helm option to specify kubeconfig path to use. + - If the value is not specified in the task, the value of environment variable C(K8S_AUTH_KUBECONFIG) will be used instead. type: path aliases: [ kubeconfig ] purge: @@ -245,7 +247,7 @@ except ImportError: IMP_YAML_ERR = traceback.format_exc() IMP_YAML = False -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule, missing_required_lib, env_fallback module = None @@ -395,8 +397,8 @@ def main(): # Helm options disable_hook=dict(type='bool', default=False), force=dict(type='bool', default=False), - kube_context=dict(type='str'), - kubeconfig_path=dict(type='path', aliases=['kubeconfig']), + kube_context=dict(type='str', fallback=(env_fallback, ['K8S_AUTH_CONTEXT'])), + kubeconfig_path=dict(type='path', aliases=['kubeconfig'], fallback=(env_fallback, ['K8S_AUTH_KUBECONFIG'])), purge=dict(type='bool', default=True), wait=dict(type='bool', default=False), wait_timeout=dict(type='str'), diff --git a/plugins/modules/helm_info.py b/plugins/modules/helm_info.py index dc02473f..1e514138 100644 --- a/plugins/modules/helm_info.py +++ b/plugins/modules/helm_info.py @@ -48,10 +48,12 @@ options: kube_context: description: - Helm option to specify which kubeconfig context to use. + - If the value is not specified in the task, the value of environment variable C(K8S_AUTH_CONTEXT) will be used instead. type: str kubeconfig_path: description: - Helm option to specify kubeconfig path to use. + - If the value is not specified in the task, the value of environment variable C(K8S_AUTH_KUBECONFIG) will be used instead. type: path aliases: [ kubeconfig ] ''' @@ -112,7 +114,7 @@ except ImportError: IMP_YAML_ERR = traceback.format_exc() IMP_YAML = False -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule, missing_required_lib, env_fallback module = None @@ -177,8 +179,8 @@ def main(): release_namespace=dict(type='str', required=True, aliases=['namespace']), # Helm options - kube_context=dict(type='str'), - kubeconfig_path=dict(type='path', aliases=['kubeconfig']), + kube_context=dict(type='str', fallback=(env_fallback, ['K8S_AUTH_CONTEXT'])), + kubeconfig_path=dict(type='path', aliases=['kubeconfig'], fallback=(env_fallback, ['K8S_AUTH_KUBECONFIG'])), ), supports_check_mode=True, )