MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / patchFieldValueToMultiple

Function patchFieldValueToMultiple

patches.go:379–401  ·  view source on GitHub ↗

patchFieldValueToMultiple, given a path with wildcards in an array index, expands the arrays paths in the "to" object and patches the value into each of the resulting fields, returning any errors as they occur.

(fieldPath string, value any, to runtime.Object, mo *xpv1.MergeOptions)

Source from the content-addressed store, hash-verified

377// expands the arrays paths in the "to" object and patches the value into each
378// of the resulting fields, returning any errors as they occur.
379func patchFieldValueToMultiple(fieldPath string, value any, to runtime.Object, mo *xpv1.MergeOptions) error {
380 paved, err := fieldpath.PaveObject(to)
381 if err != nil {
382 return err
383 }
384
385 arrayFieldPaths, err := paved.ExpandWildcards(fieldPath)
386 if err != nil {
387 return err
388 }
389
390 if len(arrayFieldPaths) == 0 {
391 return errors.Errorf(errFmtExpandingArrayFieldPaths, fieldPath)
392 }
393
394 for _, field := range arrayFieldPaths {
395 if err := paved.MergeValue(field, value, mo); err != nil {
396 return err
397 }
398 }
399
400 return runtime.DefaultUnstructuredConverter.FromUnstructured(paved.UnstructuredContent(), to)
401}

Callers 1

ApplyFromFieldPathPatchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected