-
Notifications
You must be signed in to change notification settings - Fork 137
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
Implement Receiver resource filtering with CEL #948
base: main
Are you sure you want to change the base?
Conversation
@stefanprodan @matheuscscp I reworked it to filter the resources using CEL. I'm not quite sure that this is really that valuable, I suspect label filtering is also more efficient? There's some optimisation of the CEL that could be done within |
4969c46
to
1fe996b
Compare
d87dbfd
to
b1c4e7e
Compare
45bd724
to
1e6929c
Compare
1e6929c
to
d658d4a
Compare
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.
Thanks again for all the work here, @bigkevmcd! I'm very excited for this feature 😄
This is just a preliminary review. I will try to review this again soon.
5a22c4f
to
bddfd56
Compare
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.
LGTM
Thanks @bigkevmcd 🥇
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.
LGTM! Thanks @bigkevmcd! Pretty cool contribution 👍
8e892ef
to
18c1f31
Compare
@bigkevmcd this is good to go, please signoff all your commits and force push. |
8a9e435
to
57c36b0
Compare
That's 3MiB, I've definitely seen GitHub hook notifications that were > 1.5MiB. |
757f96d
to
1645796
Compare
1645796
to
f79599e
Compare
CEL for Receiver notification filtering This introduces CEL for filtering CEL resources in a Receiver. Users can define a CEL expression that is applied as a filter for resources that are identified for notification. A CEL expression that returns false means that a resource will not be annotated. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
This moves the JSON body to request.body from request to allow for future expansion with the headers. Add documentation for the CEL functionality to the receivers doc. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Refactor to reduce duplication. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
If the .spec.resourceFilter is provided, and can't be parsed by the CEL environment, the resource will not be ready, and an appropriate error indicated. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
In the event of a CEL expresion error, this doesn't return the error to the controller-runtime reconciler mechanism. This means that the reconciliation will not be retried until there's a change to the resource. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
* Don't pass log through - get it from the context * Use ContextEval - need to set a timeout on the context that's passed Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
This adds more testing for the CEL evaluation mechanism for resource filtering. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
f79599e
to
e438ca1
Compare
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.
New batch of comments ❤️
@@ -67,6 +67,11 @@ type ReceiverSpec struct { | |||
// +required | |||
Resources []CrossNamespaceObjectReference `json:"resources"` | |||
|
|||
// ResourceFilter is a CEL expression that is applied to each Resource | |||
// referenced in the Resources. If the expression returns false then the |
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.
// referenced in the Resources. If the expression returns false then the | |
// referenced in the Resources field. If the expression returns false then the |
|
||
To filter the resources that are reconciled you can use [Common Expression Language (CEL)](https://cel.dev/). | ||
|
||
For example to trigger `ImageRepositories` on notifications from [Google Artifact Registry](https://cloud.google.com/artifact-registry/docs/configure-notifications#examples) you can define a receiver. |
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.
For example to trigger `ImageRepositories` on notifications from [Google Artifact Registry](https://cloud.google.com/artifact-registry/docs/configure-notifications#examples) you can define a receiver. | |
For example, to trigger `ImageRepositories` on notifications from [Google Artifact Registry](https://cloud.google.com/artifact-registry/docs/configure-notifications#examples) you can define the following receiver: |
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.
Still need to go over internal/server/receiver_handlers.go
once again
docs/spec/v1/receivers.md
Outdated
There are a number of functions available to the CEL expressions beyond the basic CEL functionality. | ||
|
||
The [Strings extension](https://github.com/google/cel-go/tree/master/ext#strings) is available. | ||
|
||
In addition the notifications-controller CEL implementation provides the following functions: | ||
|
||
#### first | ||
|
||
Returns the first element of a CEL array expression. | ||
|
||
``` | ||
<list<any>>.first() -> <any> | ||
``` | ||
|
||
This is syntactic sugar for `['hello', 'mellow'][0]` | ||
|
||
Examples: | ||
|
||
``` | ||
['hello', 'mellow'].first() // returns 'hello' | ||
[].first() // returns nil | ||
'this/test'.split('/').first() // returns 'this' | ||
``` | ||
|
||
#### last | ||
|
||
Returns the last element of a CEL array expression. | ||
|
||
``` | ||
<list<any>>.last() -> <any> | ||
``` | ||
|
||
Examples: | ||
|
||
``` | ||
['hello', 'mellow'].last() // returns 'mellow' | ||
[].last() // returns nil | ||
'this/test'.split('/').last() // returns 'test' | ||
``` | ||
|
||
This is syntactic sugar for `['hello', 'mellow'][size(['hello, 'mellow'])-1]` | ||
|
||
For zero-length array values, these will both return `nil`. | ||
|
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 think we can remove all of this since now these functions are in the upstream CEL library.
if filter := obj.Spec.ResourceFilter; filter != "" { | ||
err := server.ValidateCELExpression(filter) | ||
if err != nil { | ||
conditions.MarkFalse(obj, meta.ReadyCondition, apiv1.InvalidCELExpressionReason, "%s", err) |
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.
+1 on this
internal/server/cel.go
Outdated
// ValidateCELEXpression accepts a CEL expression and will parse and check that | ||
// it's valid, if it's not valid an error is returned. | ||
func ValidateCELExpression(s string) error { | ||
_, err := newCELProgram(s) |
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.
Let's use the library as discussed (still needs to be merged/released, will happen soon):
@@ -0,0 +1,194 @@ | |||
/* |
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.
Most of this file can be removed in favor of fluxcd/pkg#858
@@ -0,0 +1,131 @@ | |||
package server |
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.
This test file can be removed in favor of fluxcd/pkg#858
@bigkevmcd we have released the
🙏 Edit: Like Stefan said below, just need to rebase. |
@bigkevmcd if you rebase with main, you'll find |
Co-authored-by: Matheus Pimenta <matheuscscp@gmail.com> Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
15d0f16
to
eb6f1ce
Compare
Co-authored-by: Matheus Pimenta <matheuscscp@gmail.com> Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com> Strip out unnecessary documentation.
7183c3c
to
fc59218
Compare
This implementation allows filtering of wildcarded resources for receivers using CEL expressions.
Closes: #491
Spec: #491 (comment)