mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-06 19:07:39 +02:00
feat: inject cli state values (--state-values-set) into environment templating context (#1917)
* feat: inject cli state values (--state-values-set) into environment templating context Signed-off-by: Vincent Chenal <vincent.chenal@protonmail.com> * test: added envvals_loader unit test for environment values Signed-off-by: Vincent Chenal <vincent.chenal@protonmail.com> * test: added 'state values set cli args in environments' integration test Signed-off-by: Vincent Chenal <vincent.chenal@protonmail.com> * fix: merge environments before loadValuesEntries Signed-off-by: Vincent Chenal <vincent.chenal@protonmail.com> * fix: 'state values set cli args in environments' integration test Signed-off-by: Vincent Chenal <vincent.chenal@protonmail.com> --------- Signed-off-by: Vincent Chenal <vincent.chenal@protonmail.com>
This commit is contained in:
+5
-1
@@ -278,7 +278,11 @@ func (c *StateCreator) loadEnvValues(st *HelmState, name string, failOnMissingEn
|
||||
valuesFiles = append(valuesFiles, f)
|
||||
}
|
||||
envValuesEntries := append(valuesFiles, envSpec.Values...)
|
||||
valuesVals, err = st.loadValuesEntries(envSpec.MissingFileHandler, envValuesEntries, c.remote, ctxEnv, name)
|
||||
loadValuesEntriesEnv, err := ctxEnv.Merge(overrode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valuesVals, err = st.loadValuesEntries(envSpec.MissingFileHandler, envValuesEntries, c.remote, loadValuesEntriesEnv, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (ld *EnvironmentValuesLoader) LoadEnvironmentValues(missingFileHandler *str
|
||||
if strings.HasSuffix(f, ".hcl") {
|
||||
hclLoader.AddFile(f)
|
||||
} else {
|
||||
tmplData := NewEnvironmentTemplateData(env, "", map[string]any{})
|
||||
tmplData := NewEnvironmentTemplateData(env, "", env.Values)
|
||||
r := tmpl.NewFileRenderer(ld.fs, filepath.Dir(f), tmplData)
|
||||
bytes, err := r.RenderToBytes(f)
|
||||
if err != nil {
|
||||
|
||||
@@ -228,3 +228,22 @@ func TestEnvValsLoad_MultiHCL(t *testing.T) {
|
||||
t.Error(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvValsLoad_EnvironmentValues(t *testing.T) {
|
||||
l := newLoader()
|
||||
env := environment.New("test")
|
||||
env.Values["foo"] = "bar"
|
||||
|
||||
actual, err := l.LoadEnvironmentValues(nil, []any{"testdata/values.9.yaml.gotmpl"}, env, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := map[string]any{
|
||||
"foo": "bar",
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(expected, actual); diff != "" {
|
||||
t.Error(diff)
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
foo: {{ .Values.foo }}
|
||||
Reference in New Issue
Block a user