Skip to content

Commit

Permalink
fix: Retry image pull for 3 times and then fail (#137)
Browse files Browse the repository at this point in the history
Issue #, if available:

*Description of changes:*
Seems the ecr connection is reset during runtime which restricts any
chance for successful pull for open connections. Adding retry to see if
that can solve the issue. A more broad approach can to retry the entire
process.

*Testing done:*



- [ ] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

Signed-off-by: Shubharanshu Mahapatra <shubhum@amazon.com>
  • Loading branch information
Shubhranshu153 committed Mar 27, 2024
1 parent ac67c9f commit 3f4765f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"

"github.com/runfinch/common-tests/fnet"

Expand Down Expand Up @@ -78,6 +79,8 @@ const (
Hybrid
// Unified with only cgroups v2 mounted.
Unified

retryPull = 3
)

// SetupLocalRegistry can be invoked before running the tests to save time when pulling images during tests.
Expand All @@ -102,7 +105,18 @@ func SetupLocalRegistry(o *option.Option) {
_, name, _ := strings.Cut(ref, "/")
// allow up to a minute for remote pulls to account for external network
// latency/throughput issues or throttling (default is 10 seconds)
command.New(o, "pull", ref).WithTimeoutInSeconds(60).Run()
// retry pull for 3 times
var session *gexec.Session
for i := 0; i < retryPull; i++ {
session = command.New(o, "pull", ref).WithTimeoutInSeconds(30).WithoutSuccessfulExit().Run()
if session.ExitCode() == 0 {
break
}
}
if session.ExitCode() != 0 {
ginkgo.Fail("Failed to pull image " + ref)
}

localRef := fmt.Sprintf("localhost:%d/%s", hostPort, name)
command.Run(o, "tag", ref, localRef)
command.Run(o, "push", localRef)
Expand Down

0 comments on commit 3f4765f

Please sign in to comment.