Skip to content

Commit 2535533

Browse files
authored
Merge pull request #103 from ravilr/wildcarded_merge_patch
pass down mergeOptions for wildcarded toField patches
2 parents bd61696 + f861ff1 commit 2535533

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

patches.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ func ApplyFromFieldPathPatch(p PatchInterface, from, to runtime.Object) error {
7777
return err
7878
}
7979

80-
// ComposedPatch all expanded fields if the ToFieldPath contains wildcards
81-
if strings.Contains(p.GetToFieldPath(), "[*]") {
82-
return patchFieldValueToMultiple(p.GetToFieldPath(), out, to)
83-
}
84-
8580
mo, err := toMergeOption(p)
8681
if err != nil {
8782
return err
8883
}
8984

85+
// ComposedPatch all expanded fields if the ToFieldPath contains wildcards
86+
if strings.Contains(p.GetToFieldPath(), "[*]") {
87+
return patchFieldValueToMultiple(p.GetToFieldPath(), out, to, mo)
88+
}
89+
9090
return errors.Wrap(patchFieldValueToObject(p.GetToFieldPath(), out, to, mo), "cannot patch to object")
9191
}
9292

@@ -350,7 +350,7 @@ func patchFieldValueToObject(fieldPath string, value any, to runtime.Object, mo
350350
// patchFieldValueToMultiple, given a path with wildcards in an array index,
351351
// expands the arrays paths in the "to" object and patches the value into each
352352
// of the resulting fields, returning any errors as they occur.
353-
func patchFieldValueToMultiple(fieldPath string, value any, to runtime.Object) error {
353+
func patchFieldValueToMultiple(fieldPath string, value any, to runtime.Object, mo *xpv1.MergeOptions) error {
354354
paved, err := fieldpath.PaveObject(to)
355355
if err != nil {
356356
return err
@@ -366,7 +366,7 @@ func patchFieldValueToMultiple(fieldPath string, value any, to runtime.Object) e
366366
}
367367

368368
for _, field := range arrayFieldPaths {
369-
if err := paved.SetValue(field, value); err != nil {
369+
if err := paved.MergeValue(field, value, mo); err != nil {
370370
return err
371371
}
372372
}

0 commit comments

Comments
 (0)