Use regexp in set imagetag

This commit is contained in:
Jingfang Liu
2018-07-31 15:35:10 -07:00
parent 6a834b6262
commit 4471b75912
2 changed files with 10 additions and 6 deletions

View File

@@ -18,20 +18,22 @@ package commands
import (
"errors"
"strings"
"regexp"
"sort"
"github.com/spf13/cobra"
"github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/types"
"sort"
)
type setImageTagOptions struct {
imageTagMap map[string]string
}
var pattern = regexp.MustCompile("^(.*):([a-zA-Z0-9._-]*)$")
// newCmdSetImageTag sets the new tags for images in the kustomization.
func newCmdSetImageTag(fsys fs.FileSystem) *cobra.Command {
var o setImageTagOptions
@@ -71,11 +73,11 @@ func (o *setImageTagOptions) Validate(args []string) error {
}
o.imageTagMap = make(map[string]string)
for _, arg := range args {
imagetag := strings.Split(arg, ":")
if len(imagetag) != 2 {
imagetag := pattern.FindStringSubmatch(arg)
if len(imagetag) != 3 {
return errors.New("Invalid format of imagetag, must specify it as <image>:<newtag>")
}
o.imageTagMap[imagetag[0]] = imagetag[1]
o.imageTagMap[imagetag[1]] = imagetag[2]
}
return nil
}