Skip to content

Commit

Permalink
fix(merge): ensure unique default values for each key in convertIntoM…
Browse files Browse the repository at this point in the history
…apping

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
  • Loading branch information
idsulik authored and ndeloof committed Jul 22, 2024
1 parent 769147e commit c69a570
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions override/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,33 @@ func mergeIPAMConfig(c any, o any, path tree.Path) (any, error) {
return ipamConfigs, nil
}

func convertIntoMapping(a any, defaultValue any) map[string]any {
func convertIntoMapping(a any, defaultValue map[string]any) map[string]any {
switch v := a.(type) {
case map[string]any:
return v
case []any:
converted := map[string]any{}
for _, s := range v {
converted[s.(string)] = defaultValue
if defaultValue == nil {
converted[s.(string)] = nil
} else {
// Create a new map for each key
converted[s.(string)] = copyMap(defaultValue)
}
}
return converted
}
return nil
}

func copyMap(m map[string]any) map[string]any {
c := make(map[string]any)
for k, v := range m {
c[k] = v
}
return c
}

func override(_ any, other any, _ tree.Path) (any, error) {
return other, nil
}

0 comments on commit c69a570

Please sign in to comment.