Skip to content

Commit

Permalink
Merge pull request #1258 from mitchfriedman/push-retries
Browse files Browse the repository at this point in the history
Add retries to image push.
  • Loading branch information
tejal29 authored May 19, 2020
2 parents 699d2f4 + da5c420 commit 6dfbdae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions pkg/executor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

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

Expand Down Expand Up @@ -339,15 +349,22 @@ 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,
}
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)
})
}
}
Expand Down

0 comments on commit 6dfbdae

Please sign in to comment.