From 885c5a54c8d53d995befe51e1b6dd3cb705a640b Mon Sep 17 00:00:00 2001 From: muhammad adil ghaffar Date: Mon, 25 Mar 2024 12:52:56 +0200 Subject: [PATCH] Fix for TestServerSideApplyWithDefaulting Signed-off-by: muhammad adil ghaffar --- .../cluster/structuredmerge/serversidepathhelper_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go b/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go index 65fb42436f1b..8cfc58075114 100644 --- a/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go +++ b/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go @@ -651,9 +651,14 @@ func TestServerSideApplyWithDefaulting(t *testing.T) { g.Expect(env.CleanupAndWait(ctx, kct.DeepCopy())).To(Succeed()) }() + // Wait until the initial KubeadmConfigTemplate is visible in the local cache. Otherwise the test fails below. + g.Eventually(ctx, func(g Gomega) { + g.Expect(env.Get(ctx, client.ObjectKeyFromObject(kct), &bootstrapv1.KubeadmConfigTemplate{})).To(Succeed()) + }, 5*time.Second).Should(Succeed()) + // Enable the new defaulting logic (i.e. simulate the Cluster API update). // The webhook will default the users field to `[{Name: "default-user"}]`. - g.Expect(env.Create(ctx, mutatingWebhookConfiguration)).To(Succeed()) + g.Expect(env.CreateAndWait(ctx, mutatingWebhookConfiguration)).To(Succeed()) defer func() { g.Expect(env.CleanupAndWait(ctx, mutatingWebhookConfiguration)).To(Succeed()) }()