Closed ale9412 closed 1 month ago
You might notice that during the first reconcile loops the observed resources might be empty. Anyway I guess it's safer to use the helper getComposedResource
and wrap altogether in an if
/with
clause.
You can use the dig function to look for index keys that may or may not be there yet and return a default value if they aren't.
It can be problematic to use index values for resource names and composition-resource-names because if the list ever changes size the resources can reshuffle and delete/recreate unintentionally. It's usually better to use some unique attribute or combination of attributes of the resource you are creating for the name so you know it will never change.
The dig suggestion worked perfectly
Something like this did the job:
{{ dig "resources" (print "crossplane-instance-" $i) "resource" "status" "atProvider" "id" $.observed }}
Thanks very much
Crossplane version 1.15.1 function-go-tem,plate version: v0.5.0 openstack-provider version: v0.3.0
I am new using this function, I mainly using it for creating openstack resources. I am trying to create a composition with a range loop, that will iterate over a variable provided by the composite resource. However there is no way that I can make the index function work inside the range loop.
XR
Composition
I had assumed that with this config. The keypair will be created then the VMs and volumes and for last th Volumes Attach resources, but XR complains that the index is nil:
cannot compose resources: pipeline step "attach-volumes" returned a fatal result: cannot execute template: template: manifests:10:18: executing "manifests" at <index $.observed.resources (print "crossplane-instance-" $i)>: error calling index: index of untyped nil
I understand that this error occurs when the resource does not exist yet, hence there is notobserved.resources
yet, but what I expect is that the resources get created in the order describe above and eventually the index stop beingnil
and can actually be called using the resource name.If i remove the step attach-volume, everything is deployed successfully What Am i doing wrong? What is the correct way of setting the index in order to work. Thanks for your time