crossplane-contrib / provider-kubernetes

Crossplane provider to provision and manage Kubernetes objects on (remote) Kubernetes clusters.
Apache License 2.0
140 stars 82 forks source link

feat: adds derive from cel query readiness policy #247

Closed zach-source closed 4 months ago

zach-source commented 4 months ago

Description of your changes

Adds new readiness policy called "DeriveFromCelQuery". This policy allows the use of a cel query to check if an object is ready. This is handy to check conditions on objects with non-standard methods of determining if it ready such as the argocd applictation object.

Probably closes https://github.com/crossplane-contrib/provider-kubernetes/issues/192

I have:

How has this code been tested

I've written several test caes that cover the usage of the new feature.

bobh66 commented 4 months ago

@zach-source this looks great - do you have an example of how to reference a status condition with a specific type in a CEL query? I have been looking at CEL examples and I haven't found an equivalent syntax to the JSONPath $.status.conditions[?(@.type=="Completed")].status syntax.

bobh66 commented 4 months ago

@zach-source this looks great - do you have an example of how to reference a status condition with a specific type in a CEL query? I have been looking at CEL examples and I haven't found an equivalent syntax to the JSONPath $.status.conditions[?(@.type=="Completed")].status syntax.

I think I figured it out:

status.conditions.exists(w, w.type=='Foo' && w.status == 'True')

zach-source commented 4 months ago

Ah yea, exactly. And you can combine them if you want multiple. I've pushed up changes to make it pass all the reviewable checks. It's been a minute since I worked on a provider and I always have a hard time getting that submodule to sync correctly. You can see the list of all the available macros here: https://github.com/google/cel-spec/blob/master/doc/langdef.md#macros

I'll add a test case for ya.

bobh66 commented 4 months ago

@zach-source Please run go mod tidy and make generate and commit the results.

zach-source commented 4 months ago

Should be good to go now @bobh66

bobh66 commented 4 months ago

@turkenh can you take a look at this? It would be great to get this into the next release if possible - thanks!

zach-source commented 4 months ago

Looking good! A few minor comments

Thanks for the review - I'll do a bit of work on it this weekend and push it up. Probably tomorrow.

zach-source commented 4 months ago

@phisco comments have been addressed.

zach-source commented 4 months ago

@phisco Added your recommended changes/nits.