fix: do not panic on merging env secrets (#713)

Fixes #712
This commit is contained in:
KUOKA Yusuke 2019-06-21 00:10:11 +09:00 committed by GitHub
parent 65818cd345
commit cfe309ec21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/imdario/mergo"
"github.com/roboll/helmfile/pkg/environment"
"github.com/roboll/helmfile/pkg/helmexec"
"github.com/roboll/helmfile/pkg/maputil"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
"io"
@ -222,7 +223,14 @@ func (st *HelmState) loadEnvValues(name string, ctxEnv *environment.Environment,
if err := yaml.Unmarshal(bytes, &m); err != nil {
return nil, fmt.Errorf("failed to load environment secrets file \"%s\": %v", path, err)
}
if err := mergo.Merge(&envVals, &m, mergo.WithOverride); err != nil {
// All the nested map key should be string. Otherwise we get strange errors due to that
// mergo or reflect is unable to merge map[interface{}]interface{} with map[string]interface{} or vice versa.
// See https://github.com/roboll/helmfile/issues/677
vals, err := maputil.CastKeysToStrings(m)
if err != nil {
return nil, err
}
if err := mergo.Merge(&envVals, &vals, mergo.WithOverride); err != nil {
return nil, fmt.Errorf("failed to load \"%s\": %v", path, err)
}
}