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 11ad9cc
Show file tree
Hide file tree
Showing 2 changed files with 9 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
8 changes: 7 additions & 1 deletion pkg/executor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ func (m *mockedCertPool) append(path string) error {
return nil
}

type retryTransport struct {
inner http.RoundTripper
backoff retry.Backoff
predicate retry.Predicate
}

func Test_makeTransport(t *testing.T) {
registryName := "my.registry.name"

Expand Down Expand Up @@ -347,7 +353,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 11ad9cc

Please sign in to comment.