Skip to content

Commit

Permalink
Add --push-ignore-immutable-tag-errors boolean CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuscscp committed Oct 4, 2023
1 parent 2a1b29a commit 500272c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func addKanikoOptionsFlags() {
RootCmd.PersistentFlags().BoolVarP(&opts.InsecurePull, "insecure-pull", "", false, "Pull from insecure registry using plain HTTP")
RootCmd.PersistentFlags().BoolVarP(&opts.SkipTLSVerifyPull, "skip-tls-verify-pull", "", false, "Pull from insecure registry ignoring TLS verify")
RootCmd.PersistentFlags().IntVar(&opts.PushRetry, "push-retry", 0, "Number of retries for the push operation")
RootCmd.PersistentFlags().BoolVar(&opts.PushIgnoreImmutableTagErrors, "push-ignore-immutable-tag-errors", false, "If true, known tag immutability errors are ignored and the push finishes with success.")
RootCmd.PersistentFlags().IntVar(&opts.ImageFSExtractRetry, "image-fs-extract-retry", 0, "Number of retries for image FS extraction")
RootCmd.PersistentFlags().StringVarP(&opts.KanikoDir, "kaniko-dir", "", constants.DefaultKanikoPath, "Path to the kaniko directory, this takes precedence over the KANIKO_DIR environment variable.")
RootCmd.PersistentFlags().StringVarP(&opts.TarPath, "tar-path", "", "", "Path to save the image in as a tarball instead of pushing")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type RegistryOptions struct {
InsecurePull bool
SkipTLSVerifyPull bool
PushRetry int
PushIgnoreImmutableTagErrors bool
}

// KanikoOptions are options that are set by command line arguments
Expand Down
23 changes: 22 additions & 1 deletion pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ const (
DummyDestination = "docker.io/unset-repo/unset-image-name"
)

var (
// known tag immutability errors
errTagImmutable = []string{
// https://cloud.google.com/artifact-registry/docs/docker/troubleshoot#push
"The repository has enabled tag immutability",
}
)

func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
ua := []string{fmt.Sprintf("kaniko/%s", version.Version())}
if upstream := os.Getenv(UpstreamClientUaKey); upstream != "" {
Expand Down Expand Up @@ -269,10 +277,23 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error {
if err != nil {
return err
}
digest := destRef.Context().Digest(dig.String())
if err := remote.Write(destRef, image, remote.WithAuth(pushAuth), remote.WithTransport(rt)); err != nil {
if !opts.PushIgnoreImmutableTagErrors {
return err
}

// check for known "tag immutable" errors
errStr := err.Error()
for _, candidate := range errTagImmutable {
if strings.Contains(errStr, candidate) {
logrus.Infof("Immutable tag error ignored for %s", digest)
return nil
}
}
return err
}
logrus.Infof("Pushed %s", destRef.Context().Digest(dig.String()))
logrus.Infof("Pushed %s", digest)
return nil
}

Expand Down

0 comments on commit 500272c

Please sign in to comment.