From 5d4ea2f4fa22fa1703d12f4cc07e9eb7763e329a Mon Sep 17 00:00:00 2001 From: Steven Clark Date: Fri, 23 Aug 2024 08:33:21 -0400 Subject: [PATCH] Add retry logic to building zlint test container (#28167) - Sometimes we are failing to pull the zlint tagged version from GitHub when building up the test containers. Add a simple retry around the container building step to see if this resolves the issue. --- builtin/logical/pkiext/zlint_test.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/builtin/logical/pkiext/zlint_test.go b/builtin/logical/pkiext/zlint_test.go index 981d62bf1e..38f39e0a71 100644 --- a/builtin/logical/pkiext/zlint_test.go +++ b/builtin/logical/pkiext/zlint_test.go @@ -6,10 +6,13 @@ package pkiext import ( "context" "encoding/json" + "fmt" "sync" "testing" + "time" "github.com/hashicorp/vault/builtin/logical/pki" + "github.com/hashicorp/vault/helper/testhelpers" "github.com/hashicorp/vault/sdk/helper/docker" "github.com/stretchr/testify/require" ) @@ -50,15 +53,21 @@ RUN go install github.com/zmap/zlint/v3/cmd/zlint@v3.6.2 } ctx := context.Background() - output, err := zRunner.BuildImage(ctx, containerfile, bCtx, - docker.BuildRemove(true), docker.BuildForceRemove(true), - docker.BuildPullParent(true), - docker.BuildTags([]string{imageName + ":" + imageTag})) - if err != nil { - t.Fatalf("Could not build new image: %v", err) - } - t.Logf("Image build output: %v", string(output)) + // Sometimes we see timeouts and issues pulling the zlint code from GitHub + testhelpers.RetryUntil(t, 30*time.Second, func() error { + output, err := zRunner.BuildImage(ctx, containerfile, bCtx, + docker.BuildRemove(true), + docker.BuildForceRemove(true), + docker.BuildPullParent(true), + docker.BuildTags([]string{imageName + ":" + imageTag})) + if err != nil { + return fmt.Errorf("could not build new image with zlint: %w", err) + } + + t.Logf("Image build output: %v", string(output)) + return nil + }) } func RunZLintContainer(t *testing.T, certificate string) []byte {