Skip to content

Commit

Permalink
Add helmfile_release_set selectors (list of "key=value" strings)
Browse files Browse the repository at this point in the history
It is for OR list of selectors like `key=value,key!=value` that supercedes `selector`, which is the singular version of `selectors` that supports only OR-ed simple `key=value` selectors
  • Loading branch information
mumoshu committed Nov 28, 2020
1 parent b24131f commit 9c2f865
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
37 changes: 27 additions & 10 deletions pkg/helmfile/release_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ import (
)

type ReleaseSet struct {
Bin string
Values []interface{}
ValuesFiles []interface{}
HelmBin string
Path string
Content string
DiffOutput string
ApplyOutput string
Environment string
Selector map[string]interface{}
Bin string
Values []interface{}
ValuesFiles []interface{}
HelmBin string
Path string
Content string
DiffOutput string
ApplyOutput string
Environment string

// Selector is a helmfile label selector that is a AND list of label key-value pairs
Selector map[string]interface{}

// Selectors is a OR list of selectors
Selectors []interface{}

EnvironmentVariables map[string]interface{}
WorkingDirectory string
ReleasesValues map[string]interface{}
Expand Down Expand Up @@ -81,6 +87,12 @@ func NewReleaseSet(d ResourceRead) (*ReleaseSet, error) {
f.Selector = selector.(map[string]interface{})
}

if selectors := d.Get(KeySelectors); selectors != nil {
for _, s := range selectors.([]interface{}) {
f.Selectors = append(f.Selectors, s)
}
}

if valuesFiles := d.Get(KeyValuesFiles); valuesFiles != nil {
f.ValuesFiles = valuesFiles.([]interface{})
}
Expand Down Expand Up @@ -177,6 +189,11 @@ func NewCommandWithKubeconfig(fs *ReleaseSet, args ...string) (*exec.Cmd, error)
for k, v := range fs.Selector {
flags = append(flags, "--selector", fmt.Sprintf("%s=%s", k, v))
}

for _, selector := range fs.Selectors {
flags = append(flags, "--selector", fmt.Sprintf("%s", selector))
}

for _, f := range fs.ValuesFiles {
flags = append(flags, "--state-values-file", fmt.Sprintf("%v", f))
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/helmfile/resource_release_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
const KeyValuesFiles = "values_files"
const KeyValues = "values"
const KeySelector = "selector"
const KeySelectors = "selectors"
const KeyEnvironmentVariables = "environment_variables"
const KeyWorkingDirectory = "working_directory"
const KeyPath = "path"
Expand Down Expand Up @@ -61,6 +62,14 @@ var ReleaseSetSchema = map[string]*schema.Schema{
Optional: true,
ForceNew: false,
},
KeySelectors: {
Type: schema.TypeList,
Optional: true,
ForceNew: false,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
KeyEnvironmentVariables: {
Type: schema.TypeMap,
Optional: true,
Expand Down

0 comments on commit 9c2f865

Please sign in to comment.