Skip to content

Commit

Permalink
adding args to be added in helmfile along with context to be set in h…
Browse files Browse the repository at this point in the history
…elmspec (#171)

Ref #114 

Changelog:

* adding args to be added in helmfile along with context to be set in helmspec

* making command args take precedence
  • Loading branch information
rmartinez3 authored and mumoshu committed Jun 26, 2018
1 parent af1914c commit 58bc2a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
35 changes: 23 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func main() {
},
Action: func(c *cli.Context) error {
return eachDesiredStateDo(c, func(state *state.HelmState, helm helmexec.Interface) []error {
args := c.String("args")
args := getArgs(c, state)
if len(args) > 0 {
helm.SetExtraArgs(strings.Split(args, " ")...)
helm.SetExtraArgs(args...)
}

return state.SyncRepos(helm)
Expand Down Expand Up @@ -100,9 +100,9 @@ func main() {
},
Action: func(c *cli.Context) error {
return eachDesiredStateDo(c, func(state *state.HelmState, helm helmexec.Interface) []error {
args := c.String("args")
args := getArgs(c, state)
if len(args) > 0 {
helm.SetExtraArgs(strings.Split(args, " ")...)
helm.SetExtraArgs(args...)
}

values := c.StringSlice("values")
Expand Down Expand Up @@ -137,9 +137,9 @@ func main() {
},
Action: func(c *cli.Context) error {
return eachDesiredStateDo(c, func(state *state.HelmState, helm helmexec.Interface) []error {
args := c.String("args")
args := getArgs(c, state)
if len(args) > 0 {
helm.SetExtraArgs(strings.Split(args, " ")...)
helm.SetExtraArgs(args...)
}

if c.Bool("sync-repos") {
Expand Down Expand Up @@ -217,9 +217,9 @@ func main() {
return errs
}

args := c.String("args")
args := getArgs(c, state)
if len(args) > 0 {
helm.SetExtraArgs(strings.Split(args, " ")...)
helm.SetExtraArgs(args...)
}

values := c.StringSlice("values")
Expand Down Expand Up @@ -248,9 +248,9 @@ func main() {
return eachDesiredStateDo(c, func(state *state.HelmState, helm helmexec.Interface) []error {
workers := c.Int("concurrency")

args := c.String("args")
args := getArgs(c, state)
if len(args) > 0 {
helm.SetExtraArgs(strings.Split(args, " ")...)
helm.SetExtraArgs(args...)
}

return state.ReleaseStatuses(helm, workers)
Expand Down Expand Up @@ -298,9 +298,9 @@ func main() {
cleanup := c.Bool("cleanup")
timeout := c.Int("timeout")

args := c.String("args")
args := getArgs(c, state)
if len(args) > 0 {
helm.SetExtraArgs(strings.Split(args, " ")...)
helm.SetExtraArgs(args...)
}

return state.TestReleases(helm, cleanup, timeout)
Expand Down Expand Up @@ -408,6 +408,7 @@ func loadDesiredStateFromFile(c *cli.Context, file string) (*state.HelmState, he
log.Printf("err: Cannot use option --kube-context and set attribute context.")
os.Exit(1)
}

kubeContext = st.Context
}
if namespace != "" {
Expand All @@ -417,6 +418,7 @@ func loadDesiredStateFromFile(c *cli.Context, file string) (*state.HelmState, he
}
st.Namespace = namespace
}

if len(labels) > 0 {
err = st.FilterReleases(labels)
if err != nil {
Expand Down Expand Up @@ -459,3 +461,12 @@ func clean(state *state.HelmState, errs []error) error {
}
return nil
}

func getArgs(c *cli.Context, state *state.HelmState) []string {
args := c.String("args")
if len(args) > 0 {
state.HelmDefaults.Args = strings.Split(args, " ")
}

return state.HelmDefaults.Args
}
6 changes: 6 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ import (
// HelmState structure for the helmfile
type HelmState struct {
BaseChartPath string
HelmDefaults HelmSpec `yaml:"helmDefaults"`
Context string `yaml:"context"`
DeprecatedReleases []ReleaseSpec `yaml:"charts"`
Namespace string `yaml:"namespace"`
Repositories []RepositorySpec `yaml:"repositories"`
Releases []ReleaseSpec `yaml:"releases"`
}

// HelmSpec to defines helmDefault values
type HelmSpec struct {
Args []string `yaml:"args"`
}

// RepositorySpec that defines values for a helm repo
type RepositorySpec struct {
Name string `yaml:"name"`
Expand Down

0 comments on commit 58bc2a2

Please sign in to comment.