Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues appending to an array with patch policy #127

Open
annapurnachunduri opened this issue Jun 7, 2024 · 1 comment
Open

Issues appending to an array with patch policy #127

annapurnachunduri opened this issue Jun 7, 2024 · 1 comment

Comments

@annapurnachunduri
Copy link

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 it item-1). There after, we have a 2nd step in the pipeline which implements function P&T to append spec.forProvider.items field/array with one more item listed in the XR/Claim (lets call it item-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:

  1. Without the transforms applied to the patch we see the error cannot apply composed resource "resource-1": failed to create typed patch object: .spec.forProvider.items: expected list, got &{item-2}
  2. With the transforms applied we see the error 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 {}
  3. When trying to look around the repo I noticed patches_test.go doesn't test this case. Just one test case to test de-duplication.
  4. When testing this with crossplane beta render we noticed when the transforms are not applied the output is generated but with the default Replace policy applied to the patch (output is items: item-2) instead of the output items: [item-1, item-2].
@annapurnachunduri annapurnachunduri changed the title Issues appending to an Array with policy Issues appending to an Array with a policy Jun 7, 2024
@annapurnachunduri annapurnachunduri changed the title Issues appending to an Array with a policy Issues appending to an array with patch policy Jun 7, 2024
@gschei
Copy link
Contributor

gschei commented Aug 12, 2024

The mergeOptions are not considered for CombineFromComposite, I created a PR for this: #141

@phisco I think it was forgotten, please check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants