From e8a748d3003faaa4846d2a9f30f7225d232b76d5 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Tue, 25 Jul 2023 09:52:46 -0400 Subject: [PATCH] Updated per feedback from gjenkins8 Signed-off-by: Matt Farina --- pkg/chartutil/coalesce.go | 25 ++++++++++++++++--------- pkg/chartutil/dependencies_test.go | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/chartutil/coalesce.go b/pkg/chartutil/coalesce.go index b8d3a875b..6cf23a122 100644 --- a/pkg/chartutil/coalesce.go +++ b/pkg/chartutil/coalesce.go @@ -43,16 +43,10 @@ func concatPrefix(a, b string) string { // - A chart has access to all of the variables for it, as well as all of // the values destined for its dependencies. func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) { - v, err := copystructure.Copy(vals) + valsCopy, err := copyValues(vals) if err != nil { return vals, err } - - valsCopy := v.(map[string]interface{}) - // if we have an empty map, make sure it is initialized - if valsCopy == nil { - valsCopy = make(map[string]interface{}) - } return coalesce(log.Printf, chrt, valsCopy, "", false) } @@ -71,6 +65,14 @@ func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, err // logic need to retain them for when Coalescing will happen again later in the // business logic. func MergeValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) { + valsCopy, err := copyValues(vals) + if err != nil { + return vals, err + } + return coalesce(log.Printf, chrt, valsCopy, "", true) +} + +func copyValues(vals map[string]interface{}) (Values, error) { v, err := copystructure.Copy(vals) if err != nil { return vals, err @@ -81,14 +83,19 @@ func MergeValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) if valsCopy == nil { valsCopy = make(map[string]interface{}) } - return coalesce(log.Printf, chrt, valsCopy, "", true) + + return valsCopy, nil } type printFn func(format string, v ...interface{}) // coalesce coalesces the dest values and the chart values, giving priority to the dest values. // -// This is a helper function for CoalesceValues. +// This is a helper function for CoalesceValues and MergeValues. +// +// Note, the merge argument specifies whether this is being used by MergeValues +// or CoalesceValues. Coalescing removes null values and their keys in some +// situations while merging keeps the null values. func coalesce(printf printFn, ch *chart.Chart, dest map[string]interface{}, prefix string, merge bool) (map[string]interface{}, error) { coalesceValues(printf, ch, dest, prefix, merge) return coalesceDeps(printf, ch, dest, prefix, merge) diff --git a/pkg/chartutil/dependencies_test.go b/pkg/chartutil/dependencies_test.go index 7a932c344..34ae12f95 100644 --- a/pkg/chartutil/dependencies_test.go +++ b/pkg/chartutil/dependencies_test.go @@ -321,7 +321,7 @@ func TestProcessDependencyImportValuesForEnabledCharts(t *testing.T) { c := loadChart(t, "testdata/import-values-from-enabled-subchart/parent-chart") nameOverride := "parent-chart-prod" - if err := processDependencyImportValues(c, false); err != nil { + if err := processDependencyImportValues(c, true); err != nil { t.Fatalf("processing import values dependencies %v", err) }