Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/discovery: Update comparison logic for overrides #6723

Merged
merged 1 commit into from Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/discovery/discovery.go
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"os"
"path/filepath"
"reflect"
"strings"
"sync"

Expand Down Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions plugins/discovery/discovery_test.go
Expand Up @@ -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{}{
Expand Down