Skip to content

Commit

Permalink
test: move the fake test finalizer removal function into a cleanup bl…
Browse files Browse the repository at this point in the history
…ock (GoogleContainerTools#1106) (GoogleContainerTools#1137)

The fake finalizer should be removed even if the test failed in the
middle. Otherwise, the namespace would be stuck in a terminating state.
Example: https://oss.gprow.dev/view/gs/oss-prow-build-kpt-config-sync/logs/kpt-config-sync-standard-regular-bitbucket/1747668032626364416
  • Loading branch information
nan-yu authored Feb 8, 2024
1 parent de0a88e commit 3f774e5
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions e2e/testcases/reconciler_finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,29 @@ func TestReconcileFinalizerReconcileTimeout(t *testing.T) {
if err := nt.KubeClient.Apply(namespace); err != nil {
nt.T.Fatal(err)
}

// Remove the fake finalizer
t.Cleanup(func() {
namespace = fake.NamespaceObject(namespaceNN.Name)
nt.T.Logf("Remove the fake finalizer named %s from Namespace %s", contrivedFinalizer, namespaceNN.Name)
if err := nt.KubeClient.Apply(namespace); err != nil {
nt.T.Fatal(err)
}
// With the finalizer removed, the deletion should reconcile
tg := taskgroup.New()
tg.Go(func() error {
return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(),
nestedRootSyncNN.Name, nestedRootSyncNN.Namespace)
})
tg.Go(func() error {
return nt.Watcher.WatchForNotFound(kinds.Namespace(),
namespaceNN.Name, namespaceNN.Namespace)
})
if err := tg.Wait(); err != nil {
nt.T.Fatal(err)
}
})

// Try to remove the nested RootSync. Deletion should be blocked by ns finalizer
nestedRootSyncPath := fmt.Sprintf("acme/namespaces/%s/%s.yaml",
configsync.ControllerNamespace, nestedRootSyncNN.Name)
Expand Down Expand Up @@ -576,25 +599,6 @@ func TestReconcileFinalizerReconcileTimeout(t *testing.T) {
if err := nt.Validate(namespaceNN.Name, namespaceNN.Namespace, &corev1.Namespace{}); err != nil {
nt.T.Fatal(err)
}
// Remove the fake finalizer
namespace = fake.NamespaceObject(namespaceNN.Name)
nt.T.Logf("Remove the fake finalizer named %s from Namespace %s", contrivedFinalizer, namespaceNN.Name)
if err := nt.KubeClient.Apply(namespace); err != nil {
nt.T.Fatal(err)
}
// With the finalizer removed, the deletion should reconcile
tg := taskgroup.New()
tg.Go(func() error {
return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(),
nestedRootSyncNN.Name, nestedRootSyncNN.Namespace)
})
tg.Go(func() error {
return nt.Watcher.WatchForNotFound(kinds.Namespace(),
namespaceNN.Name, namespaceNN.Namespace)
})
if err := tg.Wait(); err != nil {
nt.T.Fatal(err)
}
}

func cleanupSingleLevel(nt *nomostest.NT,
Expand Down

0 comments on commit 3f774e5

Please sign in to comment.