mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-16 17:33:14 +00:00
Apply code review recommendations
This commit is contained in:
@@ -72,28 +72,27 @@ and overwrite the previous ones if the image tag exists.
|
|||||||
// Validate validates setImageTag command.
|
// Validate validates setImageTag command.
|
||||||
func (o *setImageTagOptions) Validate(args []string) error {
|
func (o *setImageTagOptions) Validate(args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return errors.New("no image and newTag specified")
|
return errors.New("no image specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.imageTagMap = make(map[string]types.ImageTag)
|
o.imageTagMap = make(map[string]types.ImageTag)
|
||||||
|
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
if strings.Contains(arg, "@") {
|
if s := strings.Split(arg, "@"); len(s) > 1 {
|
||||||
img := strings.Split(arg, "@")
|
o.imageTagMap[s[0]] = types.ImageTag{
|
||||||
o.imageTagMap[img[0]] = types.ImageTag{
|
Name: s[0],
|
||||||
Name: img[0],
|
Digest: s[1],
|
||||||
Digest: img[1],
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
imagetag := pattern.FindStringSubmatch(arg)
|
s := pattern.FindStringSubmatch(arg)
|
||||||
if len(imagetag) != 3 {
|
if len(s) != 3 {
|
||||||
return errors.New("invalid format of imagetag, must specify it as <image>:<newtag> or <image>@<digest>")
|
return errors.New("invalid format of imagetag, must specify it as <image>:<newtag> or <image>@<digest>")
|
||||||
}
|
}
|
||||||
o.imageTagMap[imagetag[1]] = types.ImageTag{
|
o.imageTagMap[s[1]] = types.ImageTag{
|
||||||
Name: imagetag[1],
|
Name: s[1],
|
||||||
NewTag: imagetag[2],
|
NewTag: s[2],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func TestSetImageTagsNoArgs(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected error: %v", err)
|
t.Errorf("expected error: %v", err)
|
||||||
}
|
}
|
||||||
if err.Error() != "no image and newTag specified" {
|
if err.Error() != "no image specified" {
|
||||||
t.Errorf("incorrect error: %v", err.Error())
|
t.Errorf("incorrect error: %v", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user