-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add extended functions for data manipulation in CEL expressions #22
base: main
Are you sure you want to change the base?
Conversation
0b89d13
to
6617bdc
Compare
Signed-off-by: Mateusz Puczyński <[email protected]>
Signed-off-by: Mateusz Puczyński <[email protected]>
6617bdc
to
494483d
Compare
fn.go
Outdated
ext.Encoders(), | ||
ext.Lists(), | ||
ext.Math(), | ||
cel.ExtendedValidations(), | ||
cel.EagerlyValidateDeclarations(true), | ||
cel.DefaultUTCTimeZone(true), | ||
cel.CrossTypeNumericComparisons(true), | ||
cel.OptionalTypes(), | ||
ext.Strings(ext.StringsVersion(2)), | ||
ext.Sets(), | ||
library.URLs(), | ||
library.Lists(), | ||
library.Regex(), | ||
library.Quantity(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you land on this set of options? Is it pretty much what the Kubernetes API server uses? I'm wondering if there's some good way to document them without necessarily going so far as a comment for each option.
Also, do you know if these are all backward compatible? Could any of them break an existing function usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah it's still a draft PR and in a miserable shape, I'm still experimenting 😅. But ok, my current thought process is to add all extended functions from k8s codebase, because then writing CEL expressions would match the dev experience of writing CEL rules for CRDs. So I'd add all/most of functions from k8s.io/apiserver/pkg/cel/library
and some from github.com/google/cel-go/cel
and github.com/google/cel-go/ext
, at least those that you can find in this slice: https://github.com/kubernetes/kubernetes/blob/v1.29.3/staging/src/k8s.io/apiserver/pkg/cel/environment/base.go#L49
I'm not sure whether adding more validation rules would be a breaking change, probably yeah but this project is still at v0.1.1 so I guess it's good time for that 🤷🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha no pressure, I was just curious. 🙂
By the way we definitely need more maintainers on this function. I'd be happy to add you if it's something you're passionate about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not experienced in CEL expressions at all and neither in cel-go library :P I just used it in my private project once, in a custom crossplane provider-k8s where I used it to allow users to derive readiness of underlying object by passing a CEL expression, see https://github.com/aerfio/provider-k8s/blob/4610c123ea33f8c3faa45036318681eb817aa492/examples/sample/deploy.yaml#L33. In my project the CEL environment creation is almost the same as here, it's a bit worse because I dont reuse cel.Env
. But that was only a PoC project, made for fun with 0 users :P
So back to the point: I think I dont have enough experience in CEL related stuff to get maintainer status, but feel free to ping me in the future 👍🏻
Signed-off-by: Mateusz Puczyński <[email protected]>
There were some compilation errors because of new dependency on k8s.io/[email protected] that itself depends on github.com/google/[email protected], and downgrading cel-go to v0.17.7 downgrades the function-sdk-go package to v0.2.0-rc.0: Edit: yeah, I played with function-sdk-go for a couple of minutes and it seems like the github.com/bufbuild/buf is the culprit there. Offtopic: the habit of putting various tools into the same go.mod as the main deps bit me few times with crossplane deps, wouldnt it be better to do something like https://github.com/goph/licensei#installation? |
k8s.io/api v0.29.1 // indirect | ||
k8s.io/apiextensions-apiserver v0.29.1 // indirect | ||
k8s.io/client-go v0.29.1 // indirect | ||
k8s.io/api v0.29.3 // indirect | ||
k8s.io/apiextensions-apiserver v0.29.3 // indirect | ||
k8s.io/client-go v0.29.3 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped those to match direct dependecy on k8s.io/[email protected]
Yeah buf specifically has been quite a pain in this regard recently. We switched to using I like having tools in Edit: I was reading |
Like the inability to force renovate to update those Either way, this PR is now undrafted |
Description of your changes
This PR adds a few of extended functions for data manipulation in CEL expressions. Most of those functions are already in use in k8s codebase here: https://github.com/kubernetes/kubernetes/blob/v1.29.3/staging/src/k8s.io/apiserver/pkg/cel/environment/base.go#L49. I've also added few additional ones from the
github.com/google/cel-go/cel
and"github.com/google/cel-go/ext
.Fixes #
I have: