Merge pull request #1258 from mitchfriedman/push-retries

Add retries to image push.
This commit is contained in:
Tejal Desai
2020-05-19 15:31:32 -07:00
committed by GitHub
2 changed files with 26 additions and 3 deletions
+7 -1
View File
@@ -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
+19 -2
View File
@@ -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)
})
}
}