From 3ee48e53ba15fb8efd334155424121be03547ec8 Mon Sep 17 00:00:00 2001 From: Niki Dokovski Date: Tue, 21 May 2024 15:25:49 +0200 Subject: [PATCH] Pod creation is now retryable operation --- test/e2e/deployment_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index b48e2e6..f77a572 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -102,19 +102,27 @@ var _ = Describe("Oidc Apps Deployment Framework Test", Ordered, func() { pod *corev1.Pod ) - BeforeAll(func() { + // We need to implement a retryable operations in the BeforeAll block because the webhook server might not be + // initialized before the pod is created and the admission webhook is called. In the latter case, the pod creation + // will fail because the webhook server is not ready to serve the k8s-apiserver request. + BeforeAll(func(ctx SpecContext) { // Create a deployment and the downstream replicaset and the pod as there is no controller to create them - time.Sleep(1 * time.Second) deployment = createDeployment() - Expect(c.Create(context.TODO(), deployment)).Should(Succeed()) + Eventually( + func() error { return c.Create(ctx, deployment) }, + ).WithPolling(100 * time.Millisecond).Should(Succeed()) replicaSet = createReplicaSet(deployment) - Expect(c.Create(context.TODO(), replicaSet)).Should(Succeed()) + Eventually( + func() error { return c.Create(ctx, replicaSet) }, + ).WithPolling(100 * time.Millisecond).Should(Succeed()) pod = createPod(replicaSet) - Expect(c.Create(context.TODO(), pod)).Should(Succeed()) + Eventually( + func() error { return c.Create(ctx, pod) }, + ).WithPolling(100 * time.Millisecond).Should(Succeed()) - }) + }, NodeTimeout(5*time.Second)) AfterAll(func() { Expect(client.IgnoreNotFound(c.Delete(context.TODO(), deployment))).Should(Succeed())