From 3f4765f82d255f710dae6aaf9a889b58e18f08ca Mon Sep 17 00:00:00 2001 From: Subhransu <47723536+Shubhranshu153@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:15:24 -0700 Subject: [PATCH] fix: Retry image pull for 3 times and then fail (#137) 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 --- tests/tests.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/tests.go b/tests/tests.go index 6e2fb41..4d3c58e 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -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" @@ -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. @@ -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)