From 6978fab45ce1161a94c7b2f68d93523d43fdd6fe Mon Sep 17 00:00:00 2001 From: Mitchell Friedman Date: Fri, 8 May 2020 08:45:54 +0100 Subject: [PATCH] Add retries to image push. This uses the default provided retry transport by go-containerregistry as this originally had no retries built in. This is useful to avoid intermittent failures of image registries when returning a retryable status code. --- pkg/executor/push.go | 3 ++- pkg/executor/push_test.go | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/executor/push.go b/pkg/executor/push.go index ff81409e3..7bc69f8ca 100644 --- a/pkg/executor/push.go +++ b/pkg/executor/push.go @@ -41,6 +41,7 @@ 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" @@ -311,7 +312,7 @@ func makeTransport(opts *config.KanikoOptions, registryName string, loader syste } } } - return tr + return transport.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 7d919db7b..2147b73f8 100644 --- a/pkg/executor/push_test.go +++ b/pkg/executor/push_test.go @@ -283,6 +283,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" @@ -347,7 +355,7 @@ func Test_makeTransport(t *testing.T) { return &certPool } transport := makeTransport(tt.opts, registryName, mockedSystemCertLoader) - tt.check(transport.(*http.Transport).TLSClientConfig, &certPool) + tt.check(transport.(*retryTransport).inner.(*http.Transport).TLSClientConfig, &certPool) }) } }