mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
allow to set image without a tag
This commit is contained in:
@@ -160,7 +160,7 @@ func parse(arg string) (image.Image, error) {
|
||||
// matches if there is an image name to overwrite
|
||||
// <image>=<new-image><:|@><new-tag>
|
||||
if s := strings.Split(arg, separator); len(s) == 2 {
|
||||
p, err := parseOverwrite(s[1])
|
||||
p, err := parseOverwrite(s[1], true)
|
||||
return image.Image{
|
||||
Name: s[0],
|
||||
NewName: p.name,
|
||||
@@ -171,7 +171,7 @@ func parse(arg string) (image.Image, error) {
|
||||
|
||||
// matches only for <tag|digest> overwrites
|
||||
// <image><:|@><new-tag>
|
||||
p, err := parseOverwrite(arg)
|
||||
p, err := parseOverwrite(arg, false)
|
||||
return image.Image{
|
||||
Name: p.name,
|
||||
NewTag: p.tag,
|
||||
@@ -181,7 +181,7 @@ func parse(arg string) (image.Image, error) {
|
||||
|
||||
// parseOverwrite parses the overwrite parameters
|
||||
// from the given arg into a struct
|
||||
func parseOverwrite(arg string) (overwrite, error) {
|
||||
func parseOverwrite(arg string, overwriteImage bool) (overwrite, error) {
|
||||
// match <image>@<digest>
|
||||
if d := strings.Split(arg, "@"); len(d) > 1 {
|
||||
return overwrite{
|
||||
@@ -197,5 +197,12 @@ func parseOverwrite(arg string) (overwrite, error) {
|
||||
tag: t[2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
// match <image>
|
||||
if len(arg) > 0 && overwriteImage {
|
||||
return overwrite{
|
||||
name: arg,
|
||||
}, nil
|
||||
}
|
||||
return overwrite{}, errImageInvalidArgs
|
||||
}
|
||||
|
||||
@@ -84,6 +84,18 @@ func TestSetImage(t *testing.T) {
|
||||
" name: image1",
|
||||
}},
|
||||
},
|
||||
{
|
||||
description: "<image>=<image>",
|
||||
given: given{
|
||||
args: []string{"ngnix=localhost:5000/my-project/ngnix"},
|
||||
},
|
||||
expected: expected{
|
||||
fileOutput: []string{
|
||||
"images:",
|
||||
"- name: ngnix",
|
||||
" newName: localhost:5000/my-project/ngnix",
|
||||
}},
|
||||
},
|
||||
{
|
||||
given: given{
|
||||
args: []string{"ngnix=localhost:5000/my-project/ngnix:dev-01"},
|
||||
|
||||
Reference in New Issue
Block a user