You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 <[email protected]>
Copy file name to clipboardExpand all lines: docs/spec/v1/receivers.md
+111Lines changed: 111 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -700,6 +700,117 @@ resources:
700
700
**Note:** Cross-namespace references [can be disabled for security
701
701
reasons](#disabling-cross-namespace-selectors).
702
702
703
+
#### Filtering reconciled objects with CEL
704
+
705
+
To filter the resources that are reconciled you can use [Common Expression Language (CEL)](https://cel.dev/).
706
+
707
+
For example to trigger `ImageRepositories` on notifications from [Google Artifact Regisry](https://cloud.google.com/artifact-registry/docs/configure-notifications#examples) you can define a receiver.
708
+
709
+
```yaml
710
+
apiVersion: notification.toolkit.fluxcd.io/v1
711
+
kind: Receiver
712
+
metadata:
713
+
name: gar-receiver
714
+
namespace: apps
715
+
spec:
716
+
type: gcr
717
+
secretRef:
718
+
name: flux-gar-token
719
+
resources:
720
+
- apiVersion: image.toolkit.fluxcd.io/v1beta2
721
+
kind: ImageRepository
722
+
name: "*"
723
+
matchLabels:
724
+
registry: gar
725
+
```
726
+
727
+
This will trigger the reconciliation of all `ImageRepositories` with matching labels `registry: gar`, but if you want to only notify `ImageRepository` resources that are referenced from the incoming hook you can use CEL to filter the resources.
This would look for an annotation "update-image" on the resource, and match it to the `hello-world` part of the tag name.
767
+
768
+
**NOTE**: Currently the `resource` value in the CEL expression only provides the object metadata, this means you can access things like `resource.metadata.labels` and `resource.metadata.annotations`.
769
+
770
+
There are a number of functions available to the CEL expressions beyond the basic CEL functionality.
771
+
772
+
The [Strings extension](https://github.com/google/cel-go/tree/master/ext#strings) is available.
773
+
774
+
In addition the notifications-controller CEL implementation provides the following functions:
775
+
776
+
#### first
777
+
778
+
Returns the first element of a CEL array expression.
779
+
780
+
```
781
+
<list<any>>.first() -> <any>
782
+
```
783
+
784
+
This is syntactic sugar for `['hello', 'mellow'][0]`
785
+
786
+
Examples:
787
+
788
+
```
789
+
['hello', 'mellow'].first() // returns 'hello'
790
+
[].first() // returns nil
791
+
'this/test'.split('/').first() // returns 'this'
792
+
```
793
+
794
+
#### last
795
+
796
+
Returns the last element of a CEL array expression.
797
+
798
+
```
799
+
<list<any>>.last() -> <any>
800
+
```
801
+
802
+
Examples:
803
+
804
+
```
805
+
['hello', 'mellow'].last() // returns 'mellow'
806
+
[].last() // returns nil
807
+
'this/test'.split('/').last() // returns 'test'
808
+
```
809
+
810
+
This is syntactic sugar for `['hello', 'mellow'][size(['hello, 'mellow'])-1]`
811
+
812
+
For zero-length array values, these will both return `nil`.
813
+
703
814
### Secret reference
704
815
705
816
`.spec.secretRef.name` is a required field to specify a name reference to a
0 commit comments