Fix panic while loading environment secrets (#1164)
This fixes a regression in #1160
This commit is contained in:
parent
6643a41ea3
commit
51ecd12360
|
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultHelmBinary = "helm"
|
DefaultHelmBinary = state.DefaultHelmBinary
|
||||||
)
|
)
|
||||||
|
|
||||||
type desiredStateLoader struct {
|
type desiredStateLoader struct {
|
||||||
|
|
@ -79,10 +79,6 @@ func (ld *desiredStateLoader) Load(f string, opts LoadOpts) (*state.HelmState, e
|
||||||
st.HelmDefaults.KubeContext = ld.overrideKubeContext
|
st.HelmDefaults.KubeContext = ld.overrideKubeContext
|
||||||
}
|
}
|
||||||
|
|
||||||
if ld.overrideHelmBinary != DefaultHelmBinary || st.DefaultHelmBinary == "" {
|
|
||||||
st.DefaultHelmBinary = ld.overrideHelmBinary
|
|
||||||
}
|
|
||||||
|
|
||||||
if ld.namespace != "" {
|
if ld.namespace != "" {
|
||||||
if st.OverrideNamespace != "" {
|
if st.OverrideNamespace != "" {
|
||||||
return nil, errors.New("err: Cannot use option --namespace and set attribute namespace.")
|
return nil, errors.New("err: Cannot use option --namespace and set attribute namespace.")
|
||||||
|
|
@ -151,7 +147,7 @@ func (ld *desiredStateLoader) loadFileWithOverrides(inheritedEnv, overrodeEnv *e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *desiredStateLoader) underlying() *state.StateCreator {
|
func (a *desiredStateLoader) underlying() *state.StateCreator {
|
||||||
c := state.NewCreator(a.logger, a.readFile, a.fileExists, a.abs, a.glob, a.valsRuntime, a.getHelm)
|
c := state.NewCreator(a.logger, a.readFile, a.fileExists, a.abs, a.glob, a.valsRuntime, a.getHelm, a.overrideHelmBinary)
|
||||||
c.LoadFile = a.loadFile
|
c.LoadFile = a.loadFile
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ import (
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultHelmBinary = "helm"
|
||||||
|
)
|
||||||
|
|
||||||
type StateLoadError struct {
|
type StateLoadError struct {
|
||||||
msg string
|
msg string
|
||||||
Cause error
|
Cause error
|
||||||
|
|
@ -46,9 +50,11 @@ type StateCreator struct {
|
||||||
LoadFile func(inheritedEnv *environment.Environment, baseDir, file string, evaluateBases bool) (*HelmState, error)
|
LoadFile func(inheritedEnv *environment.Environment, baseDir, file string, evaluateBases bool) (*HelmState, error)
|
||||||
|
|
||||||
getHelm func(*HelmState) helmexec.Interface
|
getHelm func(*HelmState) helmexec.Interface
|
||||||
|
|
||||||
|
overrideHelmBinary string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCreator(logger *zap.SugaredLogger, readFile func(string) ([]byte, error), fileExists func(string) (bool, error), abs func(string) (string, error), glob func(string) ([]string, error), valsRuntime vals.Evaluator, getHelm func(*HelmState) helmexec.Interface) *StateCreator {
|
func NewCreator(logger *zap.SugaredLogger, readFile func(string) ([]byte, error), fileExists func(string) (bool, error), abs func(string) (string, error), glob func(string) ([]string, error), valsRuntime vals.Evaluator, getHelm func(*HelmState) helmexec.Interface, overrideHelmBinary string) *StateCreator {
|
||||||
return &StateCreator{
|
return &StateCreator{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
readFile: readFile,
|
readFile: readFile,
|
||||||
|
|
@ -58,6 +64,8 @@ func NewCreator(logger *zap.SugaredLogger, readFile func(string) ([]byte, error)
|
||||||
Strict: true,
|
Strict: true,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
getHelm: getHelm,
|
getHelm: getHelm,
|
||||||
|
|
||||||
|
overrideHelmBinary: overrideHelmBinary,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,6 +112,13 @@ func (c *StateCreator) Parse(content []byte, baseDir, file string) (*HelmState,
|
||||||
state.HelmDefaults.KubeContext = state.DeprecatedContext
|
state.HelmDefaults.KubeContext = state.DeprecatedContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.overrideHelmBinary != "" && c.overrideHelmBinary != DefaultHelmBinary {
|
||||||
|
state.DefaultHelmBinary = c.overrideHelmBinary
|
||||||
|
} else if state.DefaultHelmBinary == "" {
|
||||||
|
// Let `helmfile --helm-binary ""` not break this helmfile run
|
||||||
|
state.DefaultHelmBinary = DefaultHelmBinary
|
||||||
|
}
|
||||||
|
|
||||||
state.logger = c.logger
|
state.logger = c.logger
|
||||||
|
|
||||||
state.readFile = c.readFile
|
state.readFile = c.readFile
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ bar: {{ readFile "bar.txt" }}
|
||||||
})
|
})
|
||||||
testFs.Cwd = "/example/path/to"
|
testFs.Cwd = "/example/path/to"
|
||||||
|
|
||||||
state, err := NewCreator(logger, testFs.ReadFile, testFs.FileExists, testFs.Abs, testFs.Glob, nil, nil).ParseAndLoad(yamlContent, filepath.Dir(yamlFile), yamlFile, "production", true, nil)
|
state, err := NewCreator(logger, testFs.ReadFile, testFs.FileExists, testFs.Abs, testFs.Glob, nil, nil, "").ParseAndLoad(yamlContent, filepath.Dir(yamlFile), yamlFile, "production", true, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue