github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/cmd/common.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "io" 6 "strings" 7 8 "github.com/apprenda/kismatic/pkg/inspector/rule" 9 ) 10 11 func getNodeRoles(commaSepRoles string) ([]string, error) { 12 roles := strings.Split(commaSepRoles, ",") 13 for _, r := range roles { 14 if r != "etcd" && r != "master" && r != "worker" && r != "ingress" && r != "storage" { 15 return nil, fmt.Errorf("%s is not a valid node role", r) 16 } 17 } 18 return roles, nil 19 } 20 21 func getRulesFromFileOrDefault(out io.Writer, file string, useUpgradeRules bool, vars map[string]string) ([]rule.Rule, error) { 22 if file != "" { 23 rules, err := rule.ReadFromFile(file, vars) 24 if err != nil { 25 return nil, err 26 } 27 if ok := validateRules(out, rules); !ok { 28 return nil, fmt.Errorf("rules read from %q did not pass validation", file) 29 } 30 return rules, nil 31 } 32 if useUpgradeRules { 33 return rule.UpgradeRules(vars), nil 34 } 35 return rule.DefaultRules(vars), nil 36 } 37 38 func validateOutputType(outputType string) error { 39 if outputType != "json" && outputType != "table" { 40 return fmt.Errorf("output type %q not supported", outputType) 41 } 42 return nil 43 }