From b18f3a09d84c5661c4c66af4488dcd1e98a72067 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 21 Dec 2023 18:09:06 +0000 Subject: [PATCH] Deep Copy Helm Globals If a Helm Chart defines globals as follows: ``` global: foo: bar: baz: 1 subcharta: global: foo: bar: qux: 2 subchartb: a: true ``` Then subchartb may incorrectly see global.foo.bar.qux set to 2, even though that definition is scoped to subcharta. This is caused by a lack of deep copy of globals when performing colesce. Signed-off-by: Richard Whitehouse --- pkg/chartutil/coalesce.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pkg/chartutil/coalesce.go b/pkg/chartutil/coalesce.go index 6cf23a122..322c58fc5 100644 --- a/pkg/chartutil/coalesce.go +++ b/pkg/chartutil/coalesce.go @@ -152,7 +152,8 @@ func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix st // tables in globals. for key, val := range sg { if istable(val) { - vv := copyMap(val.(map[string]interface{})) + valCopy, _ := copystructure.Copy(val) + vv := valCopy.(map[string]interface{}) if destv, ok := dg[key]; !ok { // Here there is no merge. We're just adding. dg[key] = vv @@ -181,14 +182,6 @@ func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix st dest[GlobalKey] = dg } -func copyMap(src map[string]interface{}) map[string]interface{} { - m := make(map[string]interface{}, len(src)) - for k, v := range src { - m[k] = v - } - return m -} - // coalesceValues builds up a values map for a particular chart. // // Values in v will override the values in the chart.