From 3062979c1c77611ed2e72d35e5dfc751493cd40e Mon Sep 17 00:00:00 2001 From: Magesh Dhasayyan Date: Fri, 29 Jul 2022 07:53:57 +0530 Subject: [PATCH] Add support to kustomize edit set image with both tag and digest Currently kustomize edit set image supports images specified with tag OR digest, but NOT both. This change allows specifying images with both tag and digest. --- kustomize/commands/edit/set/setimage.go | 10 +++++++++- kustomize/commands/edit/set/setimage_test.go | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kustomize/commands/edit/set/setimage.go b/kustomize/commands/edit/set/setimage.go index e68d7b1912..87922904f6 100644 --- a/kustomize/commands/edit/set/setimage.go +++ b/kustomize/commands/edit/set/setimage.go @@ -229,8 +229,16 @@ func parse(arg string) (types.Image, error) { // parseOverwrite parses the overwrite parameters // from the given arg into a struct func parseOverwrite(arg string, overwriteImage bool) (overwrite, error) { - // match @ + // match @ if d := strings.Split(arg, "@"); len(d) > 1 { + // match :@ + if t := strings.Split(d[0], ":"); len(t) > 1 { + return overwrite{ + name: t[0], + tag: t[1], + digest: d[1], + }, nil + } return overwrite{ name: d[0], digest: d[1], diff --git a/kustomize/commands/edit/set/setimage_test.go b/kustomize/commands/edit/set/setimage_test.go index 9dce4e45de..44c99ce55d 100644 --- a/kustomize/commands/edit/set/setimage_test.go +++ b/kustomize/commands/edit/set/setimage_test.go @@ -96,6 +96,19 @@ func TestSetImage(t *testing.T) { " name: image1", }}, }, + { + description: "image with tag and digest", + given: given{ + args: []string{"org/image1:tag@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3"}, + }, + expected: expected{ + fileOutput: []string{ + "images:", + "- digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3", + " name: org/image1", + " newTag: tag", + }}, + }, { description: "=", given: given{