diff --git a/plugins/discovery/discovery.go b/plugins/discovery/discovery.go index 2276686600..c0b77a0800 100644 --- a/plugins/discovery/discovery.go +++ b/plugins/discovery/discovery.go @@ -13,6 +13,7 @@ import ( "io" "os" "path/filepath" + "reflect" "strings" "sync" @@ -751,7 +752,7 @@ func mergeValuesAndListOverrides(dest map[string]interface{}, src map[string]int nextMap, ok := v.(map[string]interface{}) // If it isn't another map, overwrite the value if !ok { - if dest[k] != v { + if !reflect.DeepEqual(dest[k], v) { overriddenKeys = append(overriddenKeys, fullKey) } dest[k] = v diff --git a/plugins/discovery/discovery_test.go b/plugins/discovery/discovery_test.go index 6969b0cafc..2ee273ad72 100644 --- a/plugins/discovery/discovery_test.go +++ b/plugins/discovery/discovery_test.go @@ -1988,6 +1988,69 @@ func TestMergeValuesAndListOverrides(t *testing.T) { }, override: []string{}, }, + { + name: "Simple Non-map override -1", + dest: map[string]interface{}{ + "a": []interface{}{"bar"}, + "b": 2, + }, + src: map[string]interface{}{ + "a": 3, + }, + expected: map[string]interface{}{ + "a": 3, + "b": 2, + }, + override: []string{"a"}, + }, + { + name: "Simple Non-map override -2", + dest: map[string]interface{}{ + "a": 3, + "b": 2, + }, + src: map[string]interface{}{ + "a": []interface{}{"bar"}, + }, + expected: map[string]interface{}{ + "a": []interface{}{"bar"}, + "b": 2, + }, + override: []string{"a"}, + }, + { + name: "Non-map override -1", + dest: map[string]interface{}{ + "a": []interface{}{"bar"}, + "b": 2, + }, + src: map[string]interface{}{ + "a": []string{"foo"}, + }, + expected: map[string]interface{}{ + "a": []string{"foo"}, + "b": 2, + }, + override: []string{"a"}, + }, + { + name: "Non-map override -2", + dest: map[string]interface{}{ + "a": map[string]interface{}{ + "aa": 10, + "ab": 20, + }, + "b": 2, + }, + src: map[string]interface{}{ + "a": []interface{}{"foo"}, + }, + expected: map[string]interface{}{ + "a": []interface{}{"foo"}, + "b": 2, + }, + override: []string{"a"}, + }, { name: "Simple overridden keys", dest: map[string]interface{}{