Skip to content

Commit 8bbd69d

Browse files
authored
Add --push-ignore-immutable-tag-errors boolean CLI option (#2774)
1 parent 47d7f7e commit 8bbd69d

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,16 @@ _Note: Depending on the built image, the media type of the image manifest might
962962
be either `application/vnd.oci.image.manifest.v1+json` or
963963
`application/vnd.docker.distribution.manifest.v2+json`._
964964

965+
#### Flag `--push-ignore-immutable-tag-errors`
966+
967+
Set this boolean flag to `true` if you want the Kaniko process to exit with
968+
success when a push error related to tag immutability occurs.
969+
970+
This is useful for example if you have parallel builds pushing the same tag
971+
and do not care which one actually succeeds.
972+
973+
Defaults to `false`.
974+
965975
#### Flag `--push-retry`
966976

967977
Set this flag to the number of retries that should happen for the push of an

Diff for: cmd/executor/cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func addKanikoOptionsFlags() {
237237
RootCmd.PersistentFlags().BoolVarP(&opts.InsecurePull, "insecure-pull", "", false, "Pull from insecure registry using plain HTTP")
238238
RootCmd.PersistentFlags().BoolVarP(&opts.SkipTLSVerifyPull, "skip-tls-verify-pull", "", false, "Pull from insecure registry ignoring TLS verify")
239239
RootCmd.PersistentFlags().IntVar(&opts.PushRetry, "push-retry", 0, "Number of retries for the push operation")
240+
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.")
240241
RootCmd.PersistentFlags().IntVar(&opts.ImageFSExtractRetry, "image-fs-extract-retry", 0, "Number of retries for image FS extraction")
241242
RootCmd.PersistentFlags().IntVar(&opts.ImageDownloadRetry, "image-download-retry", 0, "Number of retries for downloading the remote image")
242243
RootCmd.PersistentFlags().StringVarP(&opts.KanikoDir, "kaniko-dir", "", constants.DefaultKanikoPath, "Path to the kaniko directory, this takes precedence over the KANIKO_DIR environment variable.")

Diff for: pkg/config/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type RegistryOptions struct {
4343
SkipTLSVerify bool
4444
InsecurePull bool
4545
SkipTLSVerifyPull bool
46+
PushIgnoreImmutableTagErrors bool
4647
PushRetry int
4748
ImageDownloadRetry int
4849
}

Diff for: pkg/executor/push.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ const (
6262
DummyDestination = "docker.io/unset-repo/unset-image-name"
6363
)
6464

65+
var (
66+
// known tag immutability errors
67+
errTagImmutable = []string{
68+
// https://cloud.google.com/artifact-registry/docs/docker/troubleshoot#push
69+
"The repository has enabled tag immutability",
70+
}
71+
)
72+
6573
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
6674
ua := []string{fmt.Sprintf("kaniko/%s", version.Version())}
6775
if upstream := os.Getenv(UpstreamClientUaKey); upstream != "" {
@@ -280,10 +288,23 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error {
280288
if err != nil {
281289
return err
282290
}
291+
digest := destRef.Context().Digest(dig.String())
283292
if err := remote.Write(destRef, image, remote.WithAuth(pushAuth), remote.WithTransport(rt)); err != nil {
293+
if !opts.PushIgnoreImmutableTagErrors {
294+
return err
295+
}
296+
297+
// check for known "tag immutable" errors
298+
errStr := err.Error()
299+
for _, candidate := range errTagImmutable {
300+
if strings.Contains(errStr, candidate) {
301+
logrus.Infof("Immutable tag error ignored for %s", digest)
302+
return nil
303+
}
304+
}
284305
return err
285306
}
286-
logrus.Infof("Pushed %s", destRef.Context().Digest(dig.String()))
307+
logrus.Infof("Pushed %s", digest)
287308
return nil
288309
}
289310

0 commit comments

Comments
 (0)