New trigger filters

Flag name: new-apiserversource-filters

Stage: Alpha, disabled by default

Tracking issue: #7791

Overview

This feature enables a new filters field in APIServerSource that conforms to the filters API field defined in the CloudEvents Subscriptions API. It allows users to specify a set of powerful filter expressions, where each expression evaluates to either true or false for each event.

The following example shows a APIServerSource using the new filters field:

  1. ---
  2. apiVersion: sources.knative.dev/v1
  3. kind: ApiServerSource
  4. metadata:
  5. name: my-apiserversource
  6. namespace: default
  7. spec:
  8. filters:
  9. - any:
  10. - exact:
  11. type: dev.knative.apiserver.ref.add
  12. serviceAccountName: apiserversource
  13. mode: Reference
  14. resources: ...
  15. sink: ...

About the filters field

  • An array of filter expressions that evaluates to true or false. If any filter expression in the array evaluates to false, the event will not be sent to the sink.
  • Each filter expression follows a dialect that defines the type of filter and the set of additional properties that are allowed within the filter expression.

Supported filter dialects

The filters field supports the following dialects:

exact

CloudEvent attribute String value must exactly match the specified String value. Matching is case-sensitive.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - exact:
  9. type: com.github.push

prefix

CloudEvent attribute String value must start with the specified String value. Matching is case-sensitive.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - prefix:
  9. type: com.github.

suffix

CloudEvent attribute String value must end with the specified String value. Matching is case-sensitive.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - suffix:
  9. type: .created

all

All nested filter expressions must evaluate to true.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - all:
  9. - exact:
  10. type: com.github.push
  11. - exact:
  12. subject: https://github.com/cloudevents/spec

any

At least one nested filter expression must evaluate to true.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - any:
  9. - exact:
  10. type: com.github.push
  11. - exact:
  12. subject: https://github.com/cloudevents/spec

not

The nested expression evaluated must evaluate to false.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - not:
  9. exact:
  10. type: com.github.push

cesql

The provided CloudEvents SQL Expression must evaluate to true.

  1. apiVersion: sources.knative.dev/v1
  2. kind: APIServerSource
  3. metadata:
  4. ...
  5. spec:
  6. ...
  7. filters:
  8. - cesql: "source LIKE '%commerce%' AND type IN ('order.created', 'order.updated', 'order.canceled')"

FAQ

Which are the event types APIServerSource provide?

  • dev.knative.apiserver.resource.add
  • dev.knative.apiserver.resource.update
  • dev.knative.apiserver.resource.delete
  • dev.knative.apiserver.ref.add
  • dev.knative.apiserver.ref.update
  • dev.knative.apiserver.ref.delete