From b7bf07cdfd69f6b7b68739ea36e0ea077c8cb04e Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Tue, 22 Sep 2026 11:11:48 -0600 Subject: [PATCH] test: honor HELM_KUBECONTEXT when deleting the e2e namespace Helm subprocesses inherit HELM_KUBECONTEXT from the environment, but the cleanup client loaded the kubeconfig's current-context. When the two differ, releases are installed into one cluster while the namespace delete is sent to another, where it returns NotFound and is treated as success, leaking the namespace it was meant to remove. Apply the same context override when building the cleanup client. Signed-off-by: Terry Howe --- test/e2e/helper_test.go | 4 ++++ test/e2e/oci_test.go | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/e2e/helper_test.go b/test/e2e/helper_test.go index 82770323a..f869224c9 100644 --- a/test/e2e/helper_test.go +++ b/test/e2e/helper_test.go @@ -65,6 +65,10 @@ const ( envKubernetes = "HELM_E2E_KUBERNETES" // envNamespace is the namespace the Kubernetes tests install into. envNamespace = "HELM_E2E_NAMESPACE" + // envHelmKubeContext is helm's own kubecontext variable. The tests do not + // set it, but helm subprocesses inherit it, so cleanup performed through + // the Kubernetes API has to honor it too. + envHelmKubeContext = "HELM_KUBECONTEXT" ) // harness carries the resolved configuration shared by the end-to-end tests. diff --git a/test/e2e/oci_test.go b/test/e2e/oci_test.go index afd0e7daf..1a841f8cb 100644 --- a/test/e2e/oci_test.go +++ b/test/e2e/oci_test.go @@ -370,9 +370,20 @@ func archiveFiles(t *testing.T, path string) map[string][]byte { func deleteNamespace(t *testing.T, namespace string) { t.Helper() + // Select the same context the helm subprocesses used. They inherit + // HELM_KUBECONTEXT from the environment, so without this override the + // releases would be installed into one cluster while the namespace was + // deleted from whichever cluster the kubeconfig's current-context names. + // A delete against the wrong cluster returns NotFound, which would look + // like success while leaking the namespace. + overrides := &clientcmd.ConfigOverrides{} + if kubeContext := os.Getenv(envHelmKubeContext); kubeContext != "" { + overrides.CurrentContext = kubeContext + } + cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( clientcmd.NewDefaultClientConfigLoadingRules(), - &clientcmd.ConfigOverrides{}, + overrides, ).ClientConfig() if err != nil { t.Errorf("building kube client config to delete namespace %s: %v", namespace, err)