Skip to content

Commit

Permalink
[From review] Modify dest map in-place in the mergeMaps method
Browse files Browse the repository at this point in the history
  • Loading branch information
nialdaly committed Dec 5, 2024
1 parent 7001b9a commit 490a943
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pkg/provider/helm/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,26 +426,20 @@ func getOrCreateNestedMap(m map[string]any, key string) (map[string]any, error)

// mergeMaps merges the source map into the destination map, returning a new merged map.
func mergeMaps(dest, src map[string]any) map[string]any {
merged := make(map[string]any)

for key, value := range dest {
merged[key] = value
}

for key, value := range src {
if srcMap, isSrcMap := value.(map[string]any); isSrcMap {
if destMap, isDestMap := merged[key].(map[string]any); isDestMap {
merged[key] = mergeMaps(destMap, srcMap)
if destMap, isDestMap := dest[key].(map[string]any); isDestMap {
dest[key] = mergeMaps(destMap, srcMap)
} else {
merged[key] = srcMap
dest[key] = srcMap
}
} else {
// Always overwrite existing keys.
merged[key] = value
dest[key] = value
}
}

return merged
return dest
}

// shallowMerge flattens a slice of maps into a single map.
Expand Down

0 comments on commit 490a943

Please sign in to comment.