Skip to content

Commit 7719445

Browse files
authored
Merge pull request #37 from microsoft/eedorenko/merge-config-objects
Merge config objects
2 parents 4ba2b9b + 79799b9 commit 7719445

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

controllers/assignment_controller.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,30 @@ func (r *AssignmentReconciler) mergeObjects(existingObject interface{}, newObjec
393393
if existingArray, ok := existingObject.([]interface{}); ok {
394394
newArray, ok := newObject.([]interface{})
395395
if ok {
396-
// append the new array to the existing array
397-
return append(existingArray, newArray...)
396+
// iterate over the new array and merge the values
397+
for i := 0; i < len(newArray); i++ {
398+
value := newArray[i]
399+
matched := false
400+
// check if the value is a map
401+
if valueMap, ok := value.(map[interface{}]interface{}); ok {
402+
// check if the map with same "name" key exists in the existing array
403+
for j := 0; j < len(existingArray); j++ {
404+
existingValue := existingArray[j]
405+
if existingValueMap, ok := existingValue.(map[interface{}]interface{}); ok {
406+
if existingValueMap["name"] == valueMap["name"] {
407+
// merge the maps
408+
existingArray[j] = r.mergeObjects(existingValue, value)
409+
matched = true
410+
}
411+
}
412+
}
413+
}
414+
if !matched {
415+
existingArray = append(existingArray, value)
416+
}
417+
}
418+
419+
return existingArray
398420

399421
}
400422
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/xeipuuv/gojsonschema v1.2.0
1818
golang.org/x/oauth2 v0.13.0
1919
gopkg.in/yaml.v2 v2.4.0
20+
gopkg.in/yaml.v3 v3.0.1
2021
k8s.io/api v0.28.3
2122
k8s.io/apimachinery v0.28.3
2223
k8s.io/client-go v0.28.3
@@ -81,7 +82,6 @@ require (
8182
google.golang.org/appengine v1.6.7 // indirect
8283
google.golang.org/protobuf v1.33.0 // indirect
8384
gopkg.in/inf.v0 v0.9.1 // indirect
84-
gopkg.in/yaml.v3 v3.0.1 // indirect
8585
k8s.io/apiextensions-apiserver v0.28.3 // indirect
8686
k8s.io/component-base v0.28.3 // indirect
8787
k8s.io/klog/v2 v2.100.1 // indirect

scheduler/templater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/Masterminds/sprig"
2828
kalypsov1alpha1 "github.com/microsoft/kalypso-scheduler/api/v1alpha1"
2929
"github.com/mitchellh/hashstructure"
30-
"gopkg.in/yaml.v2"
30+
"gopkg.in/yaml.v3"
3131
"sigs.k8s.io/controller-runtime/pkg/log"
3232
)
3333

0 commit comments

Comments
 (0)