From a3ab92d4f964ba801b1c416ad6ababf1294be444 Mon Sep 17 00:00:00 2001 From: Jacob Bohanon Date: Fri, 7 Jun 2024 10:33:16 -0400 Subject: [PATCH] replace sleep with assertion --- testutils/kube/exec.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/testutils/kube/exec.go b/testutils/kube/exec.go index 4207991..23bdb41 100644 --- a/testutils/kube/exec.go +++ b/testutils/kube/exec.go @@ -5,8 +5,8 @@ import ( "fmt" "io" "strings" - "time" + "github.com/onsi/gomega" "github.com/solo-io/go-utils/testutils/kubectl" ) @@ -76,9 +76,14 @@ func ExecFromEphemeralPod(ctx context.Context, params EphemeralPodParams) (strin Logger: params.Logger, }) - // this smells; fix it - // wait so the ephemeral container has a chance to be created before attempting to exec against it - time.Sleep(time.Second * 5) + // Assert that eventually the ephemeral container is created before attempting to exec against it + gomega.Eventually(func(g gomega.Gomega) { + out, err := kubectl.KubectlOut(ctx, kubectl.Params{ + Args: []string{"get", "pod", "-n", params.FromNamespace, params.FromPod, "-o=jsonpath='{.status.ephemeralContainerStatuses[*].name}'"}, + }) + g.Expect(err).ToNot(gomega.HaveOccurred()) + g.Expect(out).To(gomega.ContainSubstring(params.FromContainer)) + }).Should(gomega.Succeed()) execArgs := []string{ "exec",