Skip to content

Commit

Permalink
test: clean up ConfigManagement in e2e test (#1277)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sdowell authored Jun 18, 2024
1 parent 08bfd3a commit 9b2c8b5
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions e2e/testcases/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9b2c8b5

Please sign in to comment.