Skip to content

Commit 5b5739d

Browse files
e2e/image: retry private registry ops on transient DNS errors
Signed-off-by: aryansharma9917 <sharmaaryan9837@gmail.com>
1 parent 8ca9f75 commit 5b5739d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

e2e/image/private_test.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package image
33
import (
44
"strings"
55
"testing"
6+
"time"
67

78
"github.com/docker/cli/e2e/internal/fixtures"
89
"gotest.tools/v3/assert"
@@ -29,14 +30,14 @@ func TestPullPushPrivateRepository(t *testing.T) {
2930

3031
icmd.RunCommand("docker", "tag", sourceImage, privateImage).Assert(t, icmd.Success)
3132

32-
pushNoAuth := icmd.RunCmd(
33+
pushNoAuth := runWithPrivateRegistryRetry(t,
3334
icmd.Command("docker", "push", privateImage),
3435
fixtures.WithConfig(emptyConfigDir),
3536
)
3637
pushNoAuth.Assert(t, icmd.Expected{ExitCode: 1})
3738
assertAuthDenied(t, pushNoAuth)
3839

39-
pushWithAuth := icmd.RunCmd(
40+
pushWithAuth := runWithPrivateRegistryRetry(t,
4041
icmd.Command("docker", "push", privateImage),
4142
fixtures.WithConfig(dir.Path()),
4243
)
@@ -45,14 +46,14 @@ func TestPullPushPrivateRepository(t *testing.T) {
4546

4647
icmd.RunCommand("docker", "image", "rm", "-f", privateImage).Assert(t, icmd.Success)
4748

48-
pullNoAuth := icmd.RunCmd(
49+
pullNoAuth := runWithPrivateRegistryRetry(t,
4950
icmd.Command("docker", "pull", privateImage),
5051
fixtures.WithConfig(emptyConfigDir),
5152
)
5253
pullNoAuth.Assert(t, icmd.Expected{ExitCode: 1})
5354
assertAuthDenied(t, pullNoAuth)
5455

55-
pullWithAuth := icmd.RunCmd(
56+
pullWithAuth := runWithPrivateRegistryRetry(t,
5657
icmd.Command("docker", "pull", privateImage),
5758
fixtures.WithConfig(dir.Path()),
5859
)
@@ -72,3 +73,23 @@ func assertAuthDenied(t *testing.T, result *icmd.Result) {
7273
output,
7374
)
7475
}
76+
77+
func runWithPrivateRegistryRetry(t *testing.T, cmd *icmd.Cmd, opts ...func(*icmd.Cmd)) *icmd.Result {
78+
t.Helper()
79+
80+
deadline := time.Now().Add(30 * time.Second)
81+
for {
82+
result := icmd.RunCmd(cmd, opts...)
83+
output := result.Combined()
84+
if strings.Contains(output, "lookup private-registry") ||
85+
strings.Contains(output, "no such host") ||
86+
strings.Contains(output, "server misbehaving") {
87+
if time.Now().Before(deadline) {
88+
t.Logf("waiting for private registry DNS to become available: %s", output)
89+
time.Sleep(500 * time.Millisecond)
90+
continue
91+
}
92+
}
93+
return result
94+
}
95+
}

0 commit comments

Comments
 (0)