crossplane-contrib / crossplane-contrib/function-patch-and-transform

Issues appending to an array with patch policy

Aperta
#127 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
46
Fork
41
Merge medio
1g 10h
PR unite (30g)
3

Descrizione

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]`.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia da patches_test.go e riproduci il caso CombineFromComposite segnalato utilizzando la policy delle patch e le trasformazioni mostrate nell’issue. Confronta l’output renderizzato e gli errori con l’array items previsto, contenente item-1 e item-2; il lavoro è completato quando il comportamento di append è coperto da un test e produce quel risultato senza gli errori di conversione segnalati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.