-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conditional function execution using the Common Expression Language #26
Conversation
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Some thoughts:
|
@stevendborrelli what are you thinking WRT pursuing getting this merged here vs experimenting with a separate CEL function? |
To add a bit more on what I said on slack. I could see this go in 3 directions: Crossplane native supportCEL feels like the right tool for the job given the wide adoption, so we could think of directly adding an
This looks similar to what github actions do and have the benefit of completely avoiding calling the function, but on the other hand we would be adding yet another feature to Compositions, kind of overlapping with the fieldpaths syntax. Use the Context and a well-known key
|
Adds conditional to the resources
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
@phisco I'm not sure what the right API is for conditionals, I lean towards having it part of the core function runtime and having CEL be part of function-sdk-go. @negz Right now I have that fork https://github.com/stevendborrelli/function-conditional-patch-and-transform that a few people are testing, I would love to get their feedback and then have a path to get this functionality merged into the this patch-and-transform function. |
So, "Crossplane native support":
Yes, I'm torn between that and giving functions control over successive functions calls through the context too. Probably native support would make it easier to understand at the cost of having to introduce CEL into the Composition API. |
What obstacles are preventing progress here? Resolving this will greatly benefit folks, and I don't see a need for a fork. Additionally, this is an optional feature, and I believe it will boost the use of composition functions once it's integrated into the crossplane ecosystem. |
@phisco Given this is already implemented(and tested!) in the P&T function scope, and multiple customers and community members highly desire conditionals, it would be great to accept it to this function codebase and (optionally) in parallel work on Crossplane-native implementation... This functionality is highly desired to the level that we will have to run and maintain separate patch-and-transform function fork to enable people... It is obviously an unwanted possible outcome of this discussion, and we would love to converge on the same codebase. |
This is working as intended. Let's try it in a fork for a little while and see how the feature works before we commit to bringing it "upstream" into this function. It's easier to drop the fork and have folks move back to this function than it is to change or remove the functionality from this function once it's been added. |
@negz I generally agree with this approach but am concerned with creating more confusion in the community with multiple instances of the same stuff(we already have community/official providers, etc). "A little while" is not really defined in this case so in practice, it can lead to a long-term fork with the associated maintenance price. |
Closing in favor of PR #84. |
Note: there is now a forked version of function-patch-and-transform supporting Conditionals at https://github.com/stevendborrelli/function-conditional-patch-and-transform.
This is a test of evaluating expressions with Common Expression Language (CEL). This is inspired by work from @ytsarev and @avalanche123 in developing a function that only executes after matching an expr conditional at https://github.com/ytsarev/function-if (see closed PR #14 for the expr implementation).
Composition authors express a CEL condition, and if it returns
true
, patch-and-tranfsforms defined in theinput
will be processed.An amd64 Function is available for testing available at:
Using the following XR and RunFunctionRequest inputs (click to expand):
You can use the CEL Playground to test various queries.
Here are some example queries on the XR and RunFunctionRequest:
desired.composite.resource.spec.env == "dev"
evaluates totrue
desired.composite.resource.spec.render == true,
evaluates totrue
desired.composite.resource.spec.render == false"
evaluates tofalse
observed.composite.resource.status.ready == true"
evaluates tofalse
size(desired.resources) == 0
evaluates tofalse
"test" in desired.resources
evaluates totrue
"bad-resource" in desired.resources
evaluates tofalse