Skip to content

Commit

Permalink
Add support to kustomize edit set image with both tag and digest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgsh committed Jul 29, 2022
1 parent 30843e2 commit 3062979
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kustomize/commands/edit/set/setimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <image>@<digest>
// match <image[:tag]>@<digest>
if d := strings.Split(arg, "@"); len(d) > 1 {
// match <image>:<tag>@<digest>
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],
Expand Down
13 changes: 13 additions & 0 deletions kustomize/commands/edit/set/setimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<image>=<image>",
given: given{
Expand Down

0 comments on commit 3062979

Please sign in to comment.