-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.go
39 lines (31 loc) · 835 Bytes
/
merge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package util
import (
"encoding/json"
"k8s.io/apimachinery/pkg/util/strategicpatch"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)
// MergeTo will merge one workflow (the "patch" workflow) into another (the "target" workflow.
// If the target workflow defines a field, this take precedence over the patch.
func MergeTo(patch, target *wfv1.Workflow) error {
if target == nil || patch == nil {
return nil
}
patchWfBytes, err := json.Marshal(patch)
if err != nil {
return err
}
targetWfByte, err := json.Marshal(target)
if err != nil {
return err
}
var mergedWfByte []byte
mergedWfByte, err = strategicpatch.StrategicMergePatch(patchWfBytes, targetWfByte, wfv1.Workflow{})
if err != nil {
return err
}
err = json.Unmarshal(mergedWfByte, target)
if err != nil {
return err
}
return nil
}