Allows Helm parameters that contains arrays or maps. (#2525)

This commit is contained in:
Alex Collins 2019-10-18 15:30:46 -07:00 committed by GitHub
parent 6c93047367
commit cf5d9db5bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 8 deletions

View file

@ -10,9 +10,8 @@ import (
"regexp"
"strings"
"github.com/ghodss/yaml"
argoexec "github.com/argoproj/pkg/exec"
"github.com/ghodss/yaml"
"github.com/argoproj/argo-cd/util/config"
)
@ -138,12 +137,17 @@ func (h *helm) GetParameters(valuesFiles []string) (map[string]string, error) {
return output, nil
}
func flatVals(input map[string]interface{}, output map[string]string, prefixes ...string) {
for key, val := range input {
if subMap, ok := val.(map[string]interface{}); ok {
flatVals(subMap, output, append(prefixes, fmt.Sprintf("%v", key))...)
} else {
output[strings.Join(append(prefixes, fmt.Sprintf("%v", key)), ".")] = fmt.Sprintf("%v", val)
func flatVals(input interface{}, output map[string]string, prefixes ...string) {
switch i := input.(type) {
case map[string]interface{}:
for k, v := range i {
flatVals(v, output, append(prefixes, k)...)
}
case []interface{}:
for j, v := range i {
flatVals(v, output, append(prefixes[0:len(prefixes)-1], fmt.Sprintf("%s[%v]", prefixes[len(prefixes)-1], j))...)
}
default:
output[strings.Join(prefixes, ".")] = fmt.Sprintf("%v", i)
}
}

View file

@ -164,3 +164,27 @@ func TestVersion(t *testing.T) {
re := regexp.MustCompile(SemverRegexValidation)
assert.True(t, re.MatchString(ver))
}
func Test_flatVals(t *testing.T) {
t.Run("Map", func(t *testing.T) {
output := map[string]string{}
flatVals(map[string]interface{}{"foo": map[string]interface{}{"bar": "baz"}}, output)
assert.Equal(t, map[string]string{"foo.bar": "baz"}, output)
})
t.Run("Array", func(t *testing.T) {
output := map[string]string{}
flatVals(map[string]interface{}{"foo": []interface{}{"bar"}}, output)
assert.Equal(t, map[string]string{"foo[0]": "bar"}, output)
})
t.Run("Val", func(t *testing.T) {
output := map[string]string{}
flatVals(map[string]interface{}{"foo": 1}, output)
assert.Equal(t, map[string]string{"foo": "1"}, output)
})
}