Open annapurnachunduri opened 5 months ago
The mergeOptions are not considered for CombineFromComposite, I created a PR for this: https://github.com/crossplane-contrib/function-patch-and-transform/pull/141
@phisco I think it was forgotten, please check
Hi all,
I am new to crossplane and usage of functions so looking for some guidance here. Thank you in advance!
In our composition, we have a resource created in the first pipeline step using go-templating. The resource has
spec.forProvider.items
field which expects an array input. When the resource is first created in the go-templating step there exists one item in the array (lets call ititem-1
). There after, we have a 2nd step in the pipeline which implements function P&T to appendspec.forProvider.items
field/array with one more item listed in the XR/Claim (lets call ititem-2
).Here is the code for the function P&T step:
step: policy patch
functionRef:
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:
- name: resource-1
patches:
- type: CombineFromComposite
toFieldPath: spec.forProvider.items
combine:
variables:
- fromFieldPath: spec.parameters.newItem
strategy: string
string:
fmt: "%s-2"
transforms:
- type: string
string:
type: Convert
convert: "ToJson"
- type: convert
convert:
toType: array
format: json
policy:
toFieldPath: ForceMergeObjectsAppendArrays
Snapshot of the expected output in the resource:
spec:
forProvider:
items:
- item-1
- item-2
Output/Errors encountered:
cannot apply composed resource "resource-1": failed to create typed patch object: .spec.forProvider.items: expected list, got &{item-2}
cannot compose resources: pipeline step returned a fatal result: cannot render composed resource "resource-1" "CombineFromComposite" patch at index 0 : transform at index 1 returned error: convert transform could not resolve: json: cannot unmarshal string into Go value of type []interface {}
patches_test.go
doesn't test this case. Just one test case to test de-duplication.Replace
policy applied to the patch (output isitems: item-2
) instead of the outputitems: [item-1, item-2]
.