diff options
Diffstat (limited to 'ops/kontemplate/util/util.go')
-rw-r--r-- | ops/kontemplate/util/util.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ops/kontemplate/util/util.go b/ops/kontemplate/util/util.go index 56fa1e3fc9c5..f96f5c1d7aa4 100644 --- a/ops/kontemplate/util/util.go +++ b/ops/kontemplate/util/util.go @@ -29,13 +29,29 @@ func Merge(in1 *map[string]interface{}, in2 *map[string]interface{}) *map[string return in1 } + // The maps are map[string]interface{} with unknown depth. + // Loop over both maps into every level and merge them. new := make(map[string]interface{}) + for k, v := range *in1 { new[k] = v } for k, v := range *in2 { - new[k] = v + if existing, ok := new[k]; ok { + // If both values are maps, merge them recursively + if existingMap, ok := existing.(map[string]interface{}); ok { + if newMap, ok := v.(map[string]interface{}); ok { + new[k] = *Merge(&existingMap, &newMap) + } else { + new[k] = v + } + } else { + new[k] = v + } + } else { + new[k] = v + } } return &new |