[Kpack] How to Prevent 'kp image save' from Pushing Extra Build Tags (Setting imageTaggingStrategy to None)
search cancel

[Kpack] How to Prevent 'kp image save' from Pushing Extra Build Tags (Setting imageTaggingStrategy to None)

book

Article ID: 420855

calendar_today

Updated On:

Products

VMware Tanzu Build Service VMware Tanzu Application Platform

Issue/Introduction

When creating or updating a kpack Image resource using the 'kp image save' command, the built image is often pushed to the registry with three (3) tags, even if only one tag is specified using the --tag flag.

This is the expected default behavior when the imageTaggingStrategy is set to BuildNumber.

Attempting to override this default directly within the kp image save command using the expected flag fails:

kp image save <IMAGE_NAME> --tag <TAG> --image-tagging-strategy None

Error: unknown flag: -image-tagging-strategy

Environment

KP: 0.13.x
TBS: 1.15.x
TAP: 1.12.x

Cause

The BuildNumber tagging strategy is the default for kpack Image resources created because it provides a unique tag for every successful build, which is crucial for preventing images from being inadvertently garbage collected by the container registry.

The current versions of the kp CLI lack direct support for setting the imageTaggingStrategy via a dedicated command-line flag. This field must be set directly on the underlying kpack Image Custom Resource (CRD).

Resolution

Since the kp CLI cannot set the imageTaggingStrategy flag, you must modify the Image resource YAML. Basically it just gets kp to do the image uploading of the local source and then pass of the resource yaml for yq to add the field.

kp image save samples-java \
  --tag registry.example.com/project/sample-java-app \
  --dry-run-with-image-upload \
  --output yaml \
| yq '.imageTaggingStrategy = "None"' \
| kubectl apply -f-