From 9c2f865f9135ca666ddf8036d9ca7f0c16dd0b9b Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sat, 28 Nov 2020 14:52:45 +0900 Subject: [PATCH] Add helmfile_release_set selectors (list of "key=value" strings) 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 --- pkg/helmfile/release_set.go | 37 ++++++++++++++++++++-------- pkg/helmfile/resource_release_set.go | 9 +++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/pkg/helmfile/release_set.go b/pkg/helmfile/release_set.go index e39f1ee..fab5762 100644 --- a/pkg/helmfile/release_set.go +++ b/pkg/helmfile/release_set.go @@ -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{} @@ -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{}) } @@ -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)) } diff --git a/pkg/helmfile/resource_release_set.go b/pkg/helmfile/resource_release_set.go index dfa9ccf..6e8fd70 100644 --- a/pkg/helmfile/resource_release_set.go +++ b/pkg/helmfile/resource_release_set.go @@ -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" @@ -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,