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)