Skip to content

Commit

Permalink
Fix config tool merge panic (zilliztech#49)
Browse files Browse the repository at this point in the history
Signed-off-by: shaoyue.chen <[email protected]>
  • Loading branch information
haorenfsa authored Nov 21, 2023
1 parent e0927aa commit 4be02a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IMG ?= milvusdb/milvus-operator:dev-latest
TOOL_IMG ?= milvus-config-tool:dev-latest
SIT_IMG ?= milvus-operator:sit
VERSION ?= 0.8.5
TOOL_VERSION ?= 0.1.1
TOOL_VERSION ?= 0.2.0
MILVUS_HELM_VERSION ?= milvus-4.1.8
RELEASE_IMG ?= milvusdb/milvus-operator:v$(VERSION)
TOOL_RELEASE_IMG ?= milvusdb/milvus-config-tool:v$(TOOL_VERSION)
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func SetStringSlice(values map[string]interface{}, v []string, fields ...string)
unstructured.SetNestedStringSlice(values, v, fields...)
}

// MergeValues merges patch into origin, you have to make sure origin is not nil, otherwise it won't work
func MergeValues(origin, patch map[string]interface{}) {
if origin == nil || patch == nil {
return
}
for patchK, patchV := range patch {
if _, exist := origin[patchK]; !exist {
origin[patchK] = patchV
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ var mergeTests = []struct {
},
},
},
{
def: nil,
overrides: map[string]interface{}{
"foo": "bar",
},
expected: nil,
},
{
def: map[string]interface{}{
"foo": "bar",
},
overrides: nil,
expected: map[string]interface{}{
"foo": "bar",
},
},
}

func TestMergeValues(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions tool/merge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func main() {
if err != nil {
log.Fatal("read destination yaml failed: ", err)
}
if dst == nil {
dst = map[string]interface{}{}
}
util.MergeValues(dst, src)

// backward compatibility
Expand Down

0 comments on commit 4be02a4

Please sign in to comment.