Skip to content

Commit

Permalink
Retry the image pull once after 5 seconds
Browse files Browse the repository at this point in the history
Signed-off-by: Jose R. Gonzalez <jose@flutes.dev>
  • Loading branch information
komish committed Oct 14, 2022
1 parent ae43bbe commit 5bdb893
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions certification/internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}))
}
}

0 comments on commit 5bdb893

Please sign in to comment.