crossplane-contrib / function-auto-ready

A composition function that automatically detects when resources are ready
https://crossplane.io
Apache License 2.0
16 stars 8 forks source link

Composition marked as Ready while conditional resources are to be deployed #25

Closed fernandezcuesta closed 5 months ago

fernandezcuesta commented 8 months ago

What problem are you facing?

When working with function-go-templating, I'm conditionally rendering some resources based on a condition (e.g. another resource is created and dumps an ARN into its status). When this is the case, function-auto-ready is marking the whole composition as Ready, even though there might be missing resources (which may or not eventually succeed).

How could this Function help solve your problem?

Either this or function-go-templating should include a mechanism to mimic the behaviour on P&T when policy.fromFieldPath is Required but the condition fails.

phisco commented 6 months ago

function-auto-ready marks composed resources as ready only if they were not previously explicitly set not to be ready.

With function-go-templating you can explicitly mark a resource as not ready by setting the gotemplating.fn.crossplane.io/ready condition to False, so you can set it wrapping it with the same condition you are using to create the second resource, e.g.:

apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
metadata:
  annotations:
    gotemplating.fn.crossplane.io/composition-resource-name: bucket
    {{- if not (... your condition, e.g. ARN in status is not set ... ) }}
    gotemplating.fn.crossplane.io/ready: "False"
    {{- end }}
...

This way your "source" resource won't be marked as ready, preventing the composite resource from becoming ready, until the second resource is ready too.

fernandezcuesta commented 5 months ago

Thanks! it works like a charm, closing this issue.