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