diff --git a/changelogs/fragments/387-fix-helm-ignoring-context.yaml b/changelogs/fragments/387-fix-helm-ignoring-context.yaml new file mode 100644 index 00000000..8e696b06 --- /dev/null +++ b/changelogs/fragments/387-fix-helm-ignoring-context.yaml @@ -0,0 +1,2 @@ +bugfixes: + - helm - fix helm ignoring the kubeconfig context when passed through the ``context`` param or the ``K8S_AUTH_CONTEXT`` environment variable (https://github.com/ansible-collections/community.kubernetes/issues/385). diff --git a/molecule/default/roles/helm/tasks/tests_chart.yml b/molecule/default/roles/helm/tasks/tests_chart.yml index e0644048..2199991c 100644 --- a/molecule/default/roles/helm/tasks/tests_chart.yml +++ b/molecule/default/roles/helm/tasks/tests_chart.yml @@ -348,6 +348,24 @@ that: result.stat.exists + - name: Release using non-existent context + helm: + binary_path: "{{ helm_binary }}" + name: test + chart_ref: "{{ chart_source }}" + chart_version: "{{ chart_source_version | default(omit) }}" + namespace: "{{ helm_namespace }}" + create_namespace: true + context: does-not-exist + ignore_errors: yes + register: result + + - name: Assert that release fails with non-existent context + assert: + that: + - result is failed + - "'context \"does-not-exist\" does not exist' in result.stderr" + always: - name: Clean up temp dir file: diff --git a/plugins/module_utils/helm.py b/plugins/module_utils/helm.py index e5a7e901..021a74da 100644 --- a/plugins/module_utils/helm.py +++ b/plugins/module_utils/helm.py @@ -28,8 +28,8 @@ def prepare_helm_environ_update(module): environ_update = {} file_to_cleam_up = None kubeconfig_path = module.params.get('kubeconfig') - if module.params.get('kube_context') is not None: - environ_update["HELM_KUBECONTEXT"] = module.params.get('kube_context') + if module.params.get('context') is not None: + environ_update["HELM_KUBECONTEXT"] = module.params.get('context') if module.params.get('release_namespace'): environ_update["HELM_NAMESPACE"] = module.params.get('release_namespace') if module.params.get("api_key"):