From 0016ff59e71017352dfcdf7831767d52b2b4051b Mon Sep 17 00:00:00 2001 From: Aditya Menon Date: Sat, 17 Jan 2026 09:16:38 +0530 Subject: [PATCH] fix: ensure templates access merged values via .Environment.Values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a regression in the CLIOverrides integration where templates accessing .Environment.Values couldn't see CLI override values. Changes: - Remove CLIOverrides-into-Values merge from Merge() to keep proper layering order (Defaults → Values → CLIOverrides) in GetMergedValues() - Update NewEnvironmentTemplateData to set envCopy.Values to the merged values, ensuring templates see the same values via both .Values and .Environment.Values This ensures: - Issue #2353: Layer arrays still replace entirely (Sparse strategy) - Issue #2281: CLI sparse arrays still merge element-by-element - Templates can access CLI overrides via .Environment.Values Signed-off-by: Aditya Menon --- pkg/environment/environment.go | 12 +++++------- pkg/state/types.go | 9 +++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index 3ccfa9e4..faf84582 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -85,9 +85,8 @@ func (e *Environment) Merge(other *Environment) (*Environment, error) { if e == nil { if other != nil { copy := other.DeepCopy() - // Also merge CLIOverrides into Values for template access via .Environment.Values - copy.Values = maputil.MergeMaps(copy.Values, copy.CLIOverrides, - maputil.MergeOptions{ArrayStrategy: maputil.ArrayMergeStrategyMerge}) + // Don't merge CLIOverrides into Values here - keep them separate. + // The proper merge happens in GetMergedValues() with correct layering. return ©, nil } return nil, nil @@ -101,15 +100,14 @@ func (e *Environment) Merge(other *Environment) (*Environment, error) { if other.KubeContext != "" { copy.KubeContext = other.KubeContext } - // Merge Values - layer values replace arrays + // Merge Values - layer values replace arrays (using default Sparse strategy) copy.Values = maputil.MergeMaps(copy.Values, other.Values) copy.Defaults = maputil.MergeMaps(copy.Defaults, other.Defaults) // Merge CLIOverrides using element-by-element array merging copy.CLIOverrides = maputil.MergeMaps(copy.CLIOverrides, other.CLIOverrides, maputil.MergeOptions{ArrayStrategy: maputil.ArrayMergeStrategyMerge}) - // Also merge CLIOverrides into Values for template access via .Environment.Values - copy.Values = maputil.MergeMaps(copy.Values, copy.CLIOverrides, - maputil.MergeOptions{ArrayStrategy: maputil.ArrayMergeStrategyMerge}) + // Don't merge CLIOverrides into Values here - keep them separate. + // The proper merge happens in GetMergedValues() with correct layering. } return ©, nil } diff --git a/pkg/state/types.go b/pkg/state/types.go index b6085f48..b210bf19 100644 --- a/pkg/state/types.go +++ b/pkg/state/types.go @@ -20,8 +20,13 @@ type EnvironmentTemplateData struct { StateValues *map[string]any } -func NewEnvironmentTemplateData(environment environment.Environment, namespace string, values map[string]any) *EnvironmentTemplateData { - d := EnvironmentTemplateData{environment, namespace, values, nil} +func NewEnvironmentTemplateData(env environment.Environment, namespace string, values map[string]any) *EnvironmentTemplateData { + // Create a copy of the environment with merged values for template access. + // This ensures templates accessing .Environment.Values see the same merged values + // (Defaults + Values + CLIOverrides) as templates accessing .Values directly. + envCopy := env + envCopy.Values = values + d := EnvironmentTemplateData{envCopy, namespace, values, nil} d.StateValues = &d.Values return &d }