diff --git a/pkg/executor/push.go b/pkg/executor/push.go index ff81409e3b..f894bcda8f 100644 --- a/pkg/executor/push.go +++ b/pkg/executor/push.go @@ -41,12 +41,18 @@ import ( "github.com/google/go-containerregistry/pkg/v1/layout" "github.com/google/go-containerregistry/pkg/v1/mutate" "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/afero" ) +// for testing +var ( + newRetry = transport.NewRetry +) + type withUserAgent struct { t http.RoundTripper } @@ -311,7 +317,7 @@ func makeTransport(opts *config.KanikoOptions, registryName string, loader syste } } } - return tr + return newRetry(tr) } // pushLayerToCache pushes layer (tagged with cacheKey) to opts.Cache diff --git a/pkg/executor/push_test.go b/pkg/executor/push_test.go index 7d919db7b1..f4581955c9 100644 --- a/pkg/executor/push_test.go +++ b/pkg/executor/push_test.go @@ -34,7 +34,9 @@ import ( "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/layout" "github.com/google/go-containerregistry/pkg/v1/random" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" "github.com/google/go-containerregistry/pkg/v1/validate" + "github.com/spf13/afero" ) @@ -283,6 +285,14 @@ func (m *mockedCertPool) append(path string) error { return nil } +type retryTransport struct { + inner http.RoundTripper +} + +func (t *retryTransport) RoundTrip(in *http.Request) (out *http.Response, err error) { + return nil, nil +} + func Test_makeTransport(t *testing.T) { registryName := "my.registry.name" @@ -339,6 +349,13 @@ func Test_makeTransport(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + originalRetry := newRetry + newRetry = func(inner http.RoundTripper, _ ...transport.Option) http.RoundTripper { + return &retryTransport{ + inner: inner, + } + } + defer func() { newRetry = originalRetry }() var certificatesPath []string certPool := mockedCertPool{ certificatesPath: certificatesPath, @@ -346,8 +363,8 @@ func Test_makeTransport(t *testing.T) { var mockedSystemCertLoader systemCertLoader = func() CertPool { return &certPool } - transport := makeTransport(tt.opts, registryName, mockedSystemCertLoader) - tt.check(transport.(*http.Transport).TLSClientConfig, &certPool) + actual := makeTransport(tt.opts, registryName, mockedSystemCertLoader) + tt.check(actual.(*retryTransport).inner.(*http.Transport).TLSClientConfig, &certPool) }) } }