Adding merging for helmDefaults args and --args, adding tillerNamspace and kubeContext to helmDefaults (#186)
Add tillerNamespace and kubeContext to helmDefaults. Also add merging of args capability. People can start adding additional fields under helmDefaults on top of this. The additional fields are merged to args as long as they are implemented using the framework introduced by this commit. Changelog: * adding merging for helm defaults args and --args, adding tillernamspace, kubecontext to helmdefaults, adding getargs to lint command * adding docs for helmdefaults * checking if empty default values
This commit is contained in:
parent
06a1d245ae
commit
01fe5b4213
11
README.md
11
README.md
|
|
@ -39,6 +39,17 @@ repositories:
|
||||||
|
|
||||||
context: kube-context # kube-context (--kube-context)
|
context: kube-context # kube-context (--kube-context)
|
||||||
|
|
||||||
|
#default values to set for args along with dedicated keys that can be set by contributers, cli args take precedence overe these
|
||||||
|
helmDefaults:
|
||||||
|
tillerNamespace: tiller-namespace #dedicated default key for tiller-namespace
|
||||||
|
kubeContext: kube-context #dedicated default key for kube-context
|
||||||
|
args:
|
||||||
|
- "--wait"
|
||||||
|
- "--recreate-pods"
|
||||||
|
- "--timeout=600"
|
||||||
|
- "--force"
|
||||||
|
- "--reset-values"
|
||||||
|
|
||||||
releases:
|
releases:
|
||||||
# Published chart example
|
# Published chart example
|
||||||
- name: vault # name of this release
|
- name: vault # name of this release
|
||||||
|
|
|
||||||
62
main.go
62
main.go
|
|
@ -5,11 +5,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/roboll/helmfile/helmexec"
|
"github.com/roboll/helmfile/helmexec"
|
||||||
"github.com/roboll/helmfile/state"
|
"github.com/roboll/helmfile/state"
|
||||||
|
|
@ -218,9 +217,9 @@ func main() {
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
return eachDesiredStateDo(c, func(state *state.HelmState, helm helmexec.Interface) []error {
|
return eachDesiredStateDo(c, func(state *state.HelmState, helm helmexec.Interface) []error {
|
||||||
args := c.String("args")
|
args := getArgs(c, state)
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
helm.SetExtraArgs(strings.Split(args, " ")...)
|
helm.SetExtraArgs(args...)
|
||||||
}
|
}
|
||||||
if c.GlobalString("helm-binary") != "" {
|
if c.GlobalString("helm-binary") != "" {
|
||||||
helm.SetHelmBinary(c.GlobalString("helm-binary"))
|
helm.SetHelmBinary(c.GlobalString("helm-binary"))
|
||||||
|
|
@ -518,9 +517,60 @@ func clean(state *state.HelmState, errs []error) error {
|
||||||
|
|
||||||
func getArgs(c *cli.Context, state *state.HelmState) []string {
|
func getArgs(c *cli.Context, state *state.HelmState) []string {
|
||||||
args := c.String("args")
|
args := c.String("args")
|
||||||
|
argsMap := map[string]string{}
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
state.HelmDefaults.Args = strings.Split(args, " ")
|
argsVals := strings.Split(args, " ")
|
||||||
|
for _, arg := range argsVals {
|
||||||
|
argVal := strings.SplitN(arg, "=", 2)
|
||||||
|
if len(argVal) > 1 {
|
||||||
|
arg := argVal[0]
|
||||||
|
value := argVal[1]
|
||||||
|
argsMap[arg] = value
|
||||||
|
} else {
|
||||||
|
arg := argVal[0]
|
||||||
|
argsMap[arg] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if len(state.HelmDefaults.Args) > 0 {
|
||||||
|
for _, arg := range state.HelmDefaults.Args {
|
||||||
|
argVal := strings.SplitN(arg, "=", 2)
|
||||||
|
arg := argVal[0]
|
||||||
|
if _, exists := argsMap[arg]; !exists {
|
||||||
|
if len(argVal) > 1 {
|
||||||
|
argsMap[arg] = argVal[1]
|
||||||
|
} else {
|
||||||
|
argsMap[arg] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if state.HelmDefaults.TillerNamespace != "" {
|
||||||
|
setDefaultValue(argsMap, "--tiller-namespace", state.HelmDefaults.TillerNamespace)
|
||||||
|
}
|
||||||
|
if state.HelmDefaults.KubeContext != "" {
|
||||||
|
setDefaultValue(argsMap, "--kube-context", state.HelmDefaults.KubeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
var argArr []string
|
||||||
|
|
||||||
|
for key, val := range argsMap {
|
||||||
|
if val != "" {
|
||||||
|
argArr = append(argArr, fmt.Sprintf("%s=%s", key, val))
|
||||||
|
} else {
|
||||||
|
argArr = append(argArr, fmt.Sprintf("%s", key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state.HelmDefaults.Args = argArr
|
||||||
|
|
||||||
return state.HelmDefaults.Args
|
return state.HelmDefaults.Args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setDefaultValue(argsMap map[string]string, flag string, value string) {
|
||||||
|
if _, exists := argsMap[flag]; !exists {
|
||||||
|
argsMap[flag] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ type HelmState struct {
|
||||||
|
|
||||||
// HelmSpec to defines helmDefault values
|
// HelmSpec to defines helmDefault values
|
||||||
type HelmSpec struct {
|
type HelmSpec struct {
|
||||||
Args []string `yaml:"args"`
|
KubeContext string `yaml:"kubeContext"`
|
||||||
|
TillerNamespace string `yaml:"tillerNamespace"`
|
||||||
|
Args []string `yaml:"args"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepositorySpec that defines values for a helm repo
|
// RepositorySpec that defines values for a helm repo
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue