From 9b2c8b55910cecc1f3833e6c638d001209746541 Mon Sep 17 00:00:00 2001 From: Sam Dowell Date: Tue, 18 Jun 2024 11:25:59 -0700 Subject: [PATCH] test: clean up ConfigManagement in e2e test (#1277) If either of the migrate tests fail early, the ConfigManagement object may be left lingering on the cluster. This will cause the Create call to fail for subsequent executions of these tests on the cluster, because the config-management object already exists. --- e2e/testcases/cli_test.go | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/e2e/testcases/cli_test.go b/e2e/testcases/cli_test.go index 224c6aaba..64ee5f8ff 100644 --- a/e2e/testcases/cli_test.go +++ b/e2e/testcases/cli_test.go @@ -1297,6 +1297,37 @@ func TestNomosMigrate(t *testing.T) { } }) nt.T.Cleanup(func() { + cmObj := &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "configmanagement.gke.io/v1", + "kind": "ConfigManagement", + "metadata": map[string]interface{}{ + "name": "config-management", + }, + }, + } + + if err := nt.KubeClient.MergePatch(cmObj, `{"metadata":{"finalizers":[]}}`); err != nil { + if apierrors.IsNotFound(err) { + return // object already deleted, exit early to prevent watch error (GVK not found) + } + nt.T.Error(err) + } + // Delete the ConfigManagement CR, in case the test failed early. + if err := nt.KubeClient.Delete(cmObj); err != nil { + if apierrors.IsNotFound(err) { + return // object already deleted, exit early to prevent watch error (GVK not found) + } + nt.T.Fatal(err) + } + if err := nt.Watcher.WatchForNotFound(kinds.ConfigManagement(), cmObj.GetName(), "", testwatcher.WatchUnstructured()); err != nil { + nt.T.Fatal(err) + } + }) + nt.T.Cleanup(func() { + if t.Failed() { + nt.PodLogs(configsync.ControllerNamespace, "config-management", "", false) + } // Delete the ConfigManagement operator in case the test failed early. // If this lingers around it could cause issues for subsequent tests. cmDeployment := fake.DeploymentObject( @@ -1407,6 +1438,37 @@ func TestNomosMigrateMonoRepo(t *testing.T) { } }) nt.T.Cleanup(func() { + cmObj := &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "configmanagement.gke.io/v1", + "kind": "ConfigManagement", + "metadata": map[string]interface{}{ + "name": "config-management", + }, + }, + } + + if err := nt.KubeClient.MergePatch(cmObj, `{"metadata":{"finalizers":[]}}`); err != nil { + if apierrors.IsNotFound(err) { + return // object already deleted, exit early to prevent watch error (GVK not found) + } + nt.T.Error(err) + } + // Delete the ConfigManagement CR, in case the test failed early. + if err := nt.KubeClient.Delete(cmObj); err != nil { + if apierrors.IsNotFound(err) { + return // object already deleted, exit early to prevent watch error (GVK not found) + } + nt.T.Fatal(err) + } + if err := nt.Watcher.WatchForNotFound(kinds.ConfigManagement(), cmObj.GetName(), "", testwatcher.WatchUnstructured()); err != nil { + nt.T.Fatal(err) + } + }) + nt.T.Cleanup(func() { + if t.Failed() { + nt.PodLogs(configsync.ControllerNamespace, "config-management", "", false) + } // Delete the ConfigManagement operator in case the test failed early. // If this lingers around it could cause issues for subsequent tests. cmDeployment := fake.DeploymentObject(