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

Function toMergeOption

patches.go:118–142  ·  view source on GitHub ↗

toMergeOption returns the MergeOptions from the PatchPolicy's ToFieldPathPolicy, if defined.

(p PatchInterface)

Source from the content-addressed store, hash-verified

116
117// toMergeOption returns the MergeOptions from the PatchPolicy's ToFieldPathPolicy, if defined.
118func toMergeOption(p PatchInterface) (mo *xpv1.MergeOptions, err error) {
119 if p == nil {
120 return nil, nil
121 }
122 pp := p.GetPolicy()
123 if pp == nil {
124 return nil, nil
125 }
126 switch pp.GetToFieldPathPolicy() {
127 case v1beta1.ToFieldPathPolicyReplace:
128 // nothing to do, this is the default
129 case v1beta1.ToFieldPathPolicyMergeObjects, v1beta1.ToFieldPathPolicyMergeObject: //nolint:staticcheck // MergeObject is deprecated but we must still support it.
130 mo = &xpv1.MergeOptions{KeepMapValues: ptr.To(true)}
131 case v1beta1.ToFieldPathPolicyMergeObjectsAppendArrays:
132 mo = &xpv1.MergeOptions{KeepMapValues: ptr.To(true), AppendSlice: ptr.To(true)}
133 case v1beta1.ToFieldPathPolicyForceMergeObjects:
134 mo = &xpv1.MergeOptions{KeepMapValues: ptr.To(false)}
135 case v1beta1.ToFieldPathPolicyForceMergeObjectsAppendArrays, v1beta1.ToFieldPathPolicyAppendArray: //nolint:staticcheck // AppendArray is deprecated but we must still support it.
136 mo = &xpv1.MergeOptions{AppendSlice: ptr.To(true)}
137 default:
138 // should never happen
139 return nil, errors.Errorf(errFmtInvalidPatchPolicy, pp.GetToFieldPathPolicy())
140 }
141 return mo, nil
142}
143
144// ApplyCombineFromVariablesPatch patches the "to" resource, taking a list of
145// input variables and combining them into a single output value. The single

Callers 2

ApplyFromFieldPathPatchFunction · 0.85

Calls 2

GetToFieldPathPolicyMethod · 0.80
GetPolicyMethod · 0.65

Tested by

no test coverage detected