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 <richard.whitehouse@microsoft.com>
pull/12661/head
Richard Whitehouse 2 years ago
parent 276121c869
commit b18f3a09d8

@ -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.

Loading…
Cancel
Save