Skip to content

Commit

Permalink
Add retries to image push.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mitchfriedman committed May 8, 2020
1 parent cb11a99 commit 6978fab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion pkg/executor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit 6978fab

Please sign in to comment.