From 74d2be9a9384eacbaf82076ca9184a6a6abecdb4 Mon Sep 17 00:00:00 2001 From: Yamunadevi Shanmugam Date: Mon, 29 Jun 2026 13:46:20 +0530 Subject: [PATCH] fix(flakiness): Improve the cleanup order Improve the cleanup order for fixing flakiness --- test/extended/util/client.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/extended/util/client.go b/test/extended/util/client.go index f268eee0158c..115f8ca617ea 100644 --- a/test/extended/util/client.go +++ b/test/extended/util/client.go @@ -688,6 +688,10 @@ func (c *CLI) TeardownProject() { err := dynamicClient.Resource(resource.Resource).Namespace(resource.Namespace).Delete(context.Background(), resource.Name, metav1.DeleteOptions{}) framework.Logf("Deleted %v, err: %v", resource, err) } + // Clear the slice so resources from this test do not accumulate and get + // redundantly re-attempted for deletion in subsequent tests that share the + // same CLI instance + c.resourcesToDelete = nil } // Verbose turns on printing verbose messages when executing OpenShift commands @@ -1195,18 +1199,25 @@ func (c *CLI) GetClientConfigForUser(username string) *rest.Config { } privToken, pubToken := GenerateOAuthTokenPair() - token, err := oauthClient.OauthV1().OAuthAccessTokens().Create(ctx, &oauthv1.OAuthAccessToken{ + _, err = oauthClient.OauthV1().OAuthAccessTokens().Create(ctx, &oauthv1.OAuthAccessToken{ ObjectMeta: metav1.ObjectMeta{Name: pubToken}, ClientName: oauthClientName, UserName: username, UserUID: string(user.UID), Scopes: []string{"user:full"}, RedirectURI: "https://localhost:8443/oauth/token/implicit", + ExpiresIn: 86400, // 24 h TTL; auto-expires without explicit deletion }, metav1.CreateOptions{}) if err != nil { FatalErr(err) } - c.AddResourceToDelete(oauthv1.GroupVersion.WithResource("oauthaccesstokens"), token) + // The token is intentionally not added to resourcesToDelete. + // TeardownProject runs as an AfterEach, which fires before the framework's + // DeferCleanup (namespace deletion). Deleting the token there invalidates + // the bearer token in any DeferCleanup that still needs to authenticate as + // this user. The User deletion (registered above) makes the token + // effectively unusable for auth anyway, and ExpiresIn ensures it is + // eventually cleaned up by the OAuth token controller. userClientConfig := rest.AnonymousClientConfig(turnOffRateLimiting(rest.CopyConfig(c.AdminConfig()))) userClientConfig.BearerToken = privToken