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 <thowe@nvidia.com>
pull/31590/head
Terry Howe 2 weeks ago
parent 4565758ff8
commit b7bf07cdfd
No known key found for this signature in database

@ -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.

@ -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)

Loading…
Cancel
Save