Skip to content

Commit

Permalink
Implement CE Subscriptions filters (#5715)
Browse files Browse the repository at this point in the history
* Implement CE Subscriptions filters

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* add oneof validation to filters

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* Removing field schema

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* Adding feature flag

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* Organize imports

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* update codegen

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* change filters oneOf validation

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>

* fix formatting

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
  • Loading branch information
devguyio authored Nov 11, 2021
1 parent 62219cc commit 1e9f9f1
Show file tree
Hide file tree
Showing 8 changed files with 790 additions and 89 deletions.
5 changes: 5 additions & 0 deletions config/core/configmaps/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ data:
# ALPHA feature: The subscriber-strict flag force subscriptions to define a subscriber
# For more details: https://github.com/knative/eventing/issues/5756
strict-subscriber: "disabled"

# ALPHA feature: The new-trigger-filters flag allows you to use the new `filters` field
# in Trigger objects with its rich filtering capabilities.
# For more details: https://github.com/knative/eventing/issues/5204
new-trigger-filters: "disabled"
1 change: 1 addition & 0 deletions config/core/resources/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ spec:
spec:
description: Spec defines the desired state of the Trigger.
type: object
x-kubernetes-preserve-unknown-fields: true
properties:
broker:
description: Broker is the broker that this trigger receives events from.
Expand Down
196 changes: 188 additions & 8 deletions docs/eventing-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,29 @@ filter will be sent to the Subscriber. If not specified, will default to allowin
</tr>
<tr>
<td>
<code>filters</code><br/>
<em>
<a href="#eventing.knative.dev/v1.SubscriptionsAPIFilter">
[]SubscriptionsAPIFilter
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Filters is an experimental field that conforms to the CNCF CloudEvents Subscriptions
API. It&rsquo;s an array of filter expressions that evaluate to true or false.
If any filter expression in the array evaluates to false, the event MUST
NOT be sent to the Subscriber. If all the filter expressions in the array
evaluate to true, the event MUST be attempted to be delivered. Absence of
a filter or empty array implies a value of true. In the event of users
specifying both Filter and Filters, then the latter will override the former.
This will allow users to try out the effect of the new Filters field
without compromising the existing attribute-based Filter and try it out on existing
Trigger objects.</p>
</td>
</tr>
<tr>
<td>
<code>subscriber</code><br/>
<em>
<a href="https://pkg.go.dev/knative.dev/pkg/apis/duck/v1#Destination">
Expand All @@ -1772,8 +1795,8 @@ knative.dev/pkg/apis/duck/v1.Destination
</em>
</td>
<td>
<p>Subscriber is the addressable that receives events from the Broker that pass the Filter. It
is required.</p>
<p>Subscriber is the addressable that receives events from the Broker that pass
the Filter. It is required.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -1927,6 +1950,140 @@ resolved delivery options.</p>
</tr>
</tbody>
</table>
<h3 id="eventing.knative.dev/v1.SubscriptionsAPIFilter">SubscriptionsAPIFilter
</h3>
<p>
(<em>Appears on:</em><a href="#eventing.knative.dev/v1.SubscriptionsAPIFilter">SubscriptionsAPIFilter</a>, <a href="#eventing.knative.dev/v1.TriggerSpec">TriggerSpec</a>)
</p>
<p>
<p>SubscriptionsAPIFilter allows defining a filter expression using CloudEvents
Subscriptions API. If multiple filters are specified, then the same semantics
of SubscriptionsAPIFilter.All is applied. If no filter dialect or empty
object is specified, then the filter always accept the events.</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>all</code><br/>
<em>
<a href="#eventing.knative.dev/v1.SubscriptionsAPIFilter">
[]SubscriptionsAPIFilter
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>All evaluates to true if all the nested expressions evaluate to true.
It must contain at least one filter expression.</p>
</td>
</tr>
<tr>
<td>
<code>any</code><br/>
<em>
<a href="#eventing.knative.dev/v1.SubscriptionsAPIFilter">
[]SubscriptionsAPIFilter
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Any evaluates to true if at least one of the nested expressions evaluates
to true. It must contain at least one filter expression.</p>
</td>
</tr>
<tr>
<td>
<code>not</code><br/>
<em>
<a href="#eventing.knative.dev/v1.SubscriptionsAPIFilter">
SubscriptionsAPIFilter
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Not evaluates to true if the nested expression evaluates to false.</p>
</td>
</tr>
<tr>
<td>
<code>exact</code><br/>
<em>
map[string]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Exact evaluates to true if the value of the matching CloudEvents
attribute matches exactly the String value specified (case-sensitive).
Exact must contain exactly one property, where the key is the name of the
CloudEvents attribute to be matched, and its value is the String value to
use in the comparison. The attribute name and value specified in the filter
expression cannot be empty strings.</p>
</td>
</tr>
<tr>
<td>
<code>prefix</code><br/>
<em>
map[string]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Prefix evaluates to true if the value of the matching CloudEvents
attribute starts with the String value specified (case-sensitive). Prefix
must contain exactly one property, where the key is the name of the
CloudEvents attribute to be matched, and its value is the String value to
use in the comparison. The attribute name and value specified in the filter
expression cannot be empty strings.</p>
</td>
</tr>
<tr>
<td>
<code>suffix</code><br/>
<em>
map[string]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Suffix evaluates to true if the value of the matching CloudEvents
attribute ends with the String value specified (case-sensitive). Suffix
must contain exactly one property, where the key is the name of the
CloudEvents attribute to be matched, and its value is the String value to
use in the comparison. The attribute name and value specified in the filter
expression cannot be empty strings.</p>
</td>
</tr>
<tr>
<td>
<code>Extensions</code><br/>
<em>
map[string]*k8s.io/apimachinery/pkg/runtime.RawExtension
</em>
</td>
<td>
<p>
(Members of <code>Extensions</code> are embedded into this type.)
</p>
<em>(Optional)</em>
<p>Extensions includes the list of additional filter dialects supported by
specific broker implementations. Check out the documentation of the
broker implementation you&rsquo;re using to know about what additional filters
are supported.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="eventing.knative.dev/v1.TriggerFilter">TriggerFilter
</h3>
<p>
Expand Down Expand Up @@ -1956,8 +2113,8 @@ TriggerFilterAttributes
<p>Attributes filters events by exact match on event context attributes.
Each key in the map is compared with the equivalent key in the event
context. An event passes the filter if all values are equal to the
specified values.</p>
<p>Nested context attributes are not supported as keys. Only string values are supported.</p>
specified values. Nested context attributes are not supported as keys. Only
string values are supported.</p>
</td>
</tr>
</tbody>
Expand All @@ -1969,8 +2126,8 @@ specified values.</p>
</p>
<p>
<p>TriggerFilterAttributes is a map of context attribute names to values for
filtering by equality. Only exact matches will pass the filter. You can use the value &ldquo;
to indicate all strings match.</p>
filtering by equality. Only exact matches will pass the filter. You can use
the value &ldquo; to indicate all strings match.</p>
</p>
<h3 id="eventing.knative.dev/v1.TriggerSpec">TriggerSpec
</h3>
Expand Down Expand Up @@ -2015,6 +2172,29 @@ filter will be sent to the Subscriber. If not specified, will default to allowin
</tr>
<tr>
<td>
<code>filters</code><br/>
<em>
<a href="#eventing.knative.dev/v1.SubscriptionsAPIFilter">
[]SubscriptionsAPIFilter
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Filters is an experimental field that conforms to the CNCF CloudEvents Subscriptions
API. It&rsquo;s an array of filter expressions that evaluate to true or false.
If any filter expression in the array evaluates to false, the event MUST
NOT be sent to the Subscriber. If all the filter expressions in the array
evaluate to true, the event MUST be attempted to be delivered. Absence of
a filter or empty array implies a value of true. In the event of users
specifying both Filter and Filters, then the latter will override the former.
This will allow users to try out the effect of the new Filters field
without compromising the existing attribute-based Filter and try it out on existing
Trigger objects.</p>
</td>
</tr>
<tr>
<td>
<code>subscriber</code><br/>
<em>
<a href="https://pkg.go.dev/knative.dev/pkg/apis/duck/v1#Destination">
Expand All @@ -2023,8 +2203,8 @@ knative.dev/pkg/apis/duck/v1.Destination
</em>
</td>
<td>
<p>Subscriber is the addressable that receives events from the Broker that pass the Filter. It
is required.</p>
<p>Subscriber is the addressable that receives events from the Broker that pass
the Filter. It is required.</p>
</td>
</tr>
<tr>
Expand Down
88 changes: 81 additions & 7 deletions pkg/apis/eventing/v1/trigger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,22 @@ type TriggerSpec struct {
// +optional
Filter *TriggerFilter `json:"filter,omitempty"`

// Subscriber is the addressable that receives events from the Broker that pass the Filter. It
// is required.
// Filters is an experimental field that conforms to the CNCF CloudEvents Subscriptions
// API. It's an array of filter expressions that evaluate to true or false.
// If any filter expression in the array evaluates to false, the event MUST
// NOT be sent to the Subscriber. If all the filter expressions in the array
// evaluate to true, the event MUST be attempted to be delivered. Absence of
// a filter or empty array implies a value of true. In the event of users
// specifying both Filter and Filters, then the latter will override the former.
// This will allow users to try out the effect of the new Filters field
// without compromising the existing attribute-based Filter and try it out on existing
// Trigger objects.
//
// +optional
Filters []SubscriptionsAPIFilter `json:"filters,omitempty"`

// Subscriber is the addressable that receives events from the Broker that pass
// the Filter. It is required.
Subscriber duckv1.Destination `json:"subscriber"`

// Delivery contains the delivery spec for this specific trigger.
Expand All @@ -96,17 +110,77 @@ type TriggerFilter struct {
// Attributes filters events by exact match on event context attributes.
// Each key in the map is compared with the equivalent key in the event
// context. An event passes the filter if all values are equal to the
// specified values.
//
// Nested context attributes are not supported as keys. Only string values are supported.
// specified values. Nested context attributes are not supported as keys. Only
// string values are supported.
//
// +optional
Attributes TriggerFilterAttributes `json:"attributes,omitempty"`
}

// SubscriptionsAPIFilter allows defining a filter expression using CloudEvents
// Subscriptions API. If multiple filters are specified, then the same semantics
// of SubscriptionsAPIFilter.All is applied. If no filter dialect or empty
// object is specified, then the filter always accept the events.
type SubscriptionsAPIFilter struct {
// All evaluates to true if all the nested expressions evaluate to true.
// It must contain at least one filter expression.
//
// +optional
All []SubscriptionsAPIFilter `json:"all,omitempty"`

// Any evaluates to true if at least one of the nested expressions evaluates
// to true. It must contain at least one filter expression.
//
// +optional
Any []SubscriptionsAPIFilter `json:"any,omitempty"`

// Not evaluates to true if the nested expression evaluates to false.
//
// +optional
Not *SubscriptionsAPIFilter `json:"not,omitempty"`

// Exact evaluates to true if the value of the matching CloudEvents
// attribute matches exactly the String value specified (case-sensitive).
// Exact must contain exactly one property, where the key is the name of the
// CloudEvents attribute to be matched, and its value is the String value to
// use in the comparison. The attribute name and value specified in the filter
// expression cannot be empty strings.
//
// +optional
Exact map[string]string `json:"exact,omitempty"`

// Prefix evaluates to true if the value of the matching CloudEvents
// attribute starts with the String value specified (case-sensitive). Prefix
// must contain exactly one property, where the key is the name of the
// CloudEvents attribute to be matched, and its value is the String value to
// use in the comparison. The attribute name and value specified in the filter
// expression cannot be empty strings.
//
// +optional
Prefix map[string]string `json:"prefix,omitempty"`

// Suffix evaluates to true if the value of the matching CloudEvents
// attribute ends with the String value specified (case-sensitive). Suffix
// must contain exactly one property, where the key is the name of the
// CloudEvents attribute to be matched, and its value is the String value to
// use in the comparison. The attribute name and value specified in the filter
// expression cannot be empty strings.
//
// +optional
Suffix map[string]string `json:"suffix,omitempty"`

// Extensions includes the list of additional filter dialects supported by
// specific broker implementations. Check out the documentation of the
// broker implementation you're using to know about what additional filters
// are supported.
//
// +optional
Extensions map[string]*runtime.RawExtension `json:",inline"`
}

// TriggerFilterAttributes is a map of context attribute names to values for
// filtering by equality. Only exact matches will pass the filter. You can use the value ''
// to indicate all strings match.
// filtering by equality. Only exact matches will pass the filter. You can use
// the value '' to indicate all strings match.
type TriggerFilterAttributes map[string]string

// TriggerStatus represents the current state of a Trigger.
Expand Down
Loading

0 comments on commit 1e9f9f1

Please sign in to comment.