From 5bdb8930d205aedf28997824fc3d4f6264938529 Mon Sep 17 00:00:00 2001 From: "Jose R. Gonzalez" Date: Tue, 11 Oct 2022 10:29:24 -0500 Subject: [PATCH] Retry the image pull once after 5 seconds Signed-off-by: Jose R. Gonzalez --- certification/internal/engine/engine.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/certification/internal/engine/engine.go b/certification/internal/engine/engine.go index 1ca1163d..e3eb34b1 100644 --- a/certification/internal/engine/engine.go +++ b/certification/internal/engine/engine.go @@ -29,6 +29,7 @@ import ( "github.com/google/go-containerregistry/pkg/crane" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/cache" + "github.com/google/go-containerregistry/pkg/v1/remote" log "github.com/sirupsen/logrus" ) @@ -75,6 +76,7 @@ func (c *CraneEngine) ExecuteChecks(ctx context.Context) error { authn.WithDockerConfig(c.Config.DockerConfig()), ), ), + retryOnceAfter(5 * time.Second), } // pull the image and save to fs @@ -585,3 +587,15 @@ func convertLabels(imageLabels map[string]string) []pyxis.Label { return pyxisLabels } + +// retryOnceAfter is a crane option that retries once after t duration. +func retryOnceAfter(t time.Duration) crane.Option { + return func(o *crane.Options) { + o.Remote = append(o.Remote, remote.WithRetryBackoff(remote.Backoff{ + Duration: t, + Factor: 1.0, + Jitter: 0.1, + Steps: 2, + })) + } +}