Skip to content

Commit

Permalink
Adding feature flag
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
  • Loading branch information
devguyio committed Nov 10, 2021
1 parent 97f9ef1 commit 61fc963
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 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"
18 changes: 10 additions & 8 deletions pkg/apis/eventing/v1/trigger_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"regexp"

"knative.dev/eventing/pkg/apis/feature"

"knative.dev/eventing/pkg/apis/eventing"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -55,7 +57,7 @@ func (ts *TriggerSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
return errs.Also(
ValidateAttributeFilters(ts.Filter).ViaField("filter"),
).Also(
ValidateSubscriptionAPIFiltersList(ts.Filters).ViaField("filters"),
ValidateSubscriptionAPIFiltersList(ctx, ts.Filters).ViaField("filters"),
).Also(
ts.Subscriber.Validate(ctx).ViaField("subscriber"),
).Also(
Expand Down Expand Up @@ -181,19 +183,19 @@ func ValidateSingleAttributeMap(expr map[string]string) (errs *apis.FieldError)
return errs
}

func ValidateSubscriptionAPIFiltersList(filters []SubscriptionsAPIFilter) (errs *apis.FieldError) {
if filters == nil {
func ValidateSubscriptionAPIFiltersList(ctx context.Context, filters []SubscriptionsAPIFilter) (errs *apis.FieldError) {
if filters == nil || !feature.FromContext(ctx).IsEnabled(feature.NewTriggerFilters) {
return nil
}

for i, f := range filters {
f := f
errs = errs.Also(ValidateSubscriptionAPIFilter(&f)).ViaIndex(i)
errs = errs.Also(ValidateSubscriptionAPIFilter(ctx, &f)).ViaIndex(i)
}
return errs
}

func ValidateSubscriptionAPIFilter(filter *SubscriptionsAPIFilter) (errs *apis.FieldError) {
func ValidateSubscriptionAPIFilter(ctx context.Context, filter *SubscriptionsAPIFilter) (errs *apis.FieldError) {
if filter == nil {
return nil
}
Expand All @@ -206,10 +208,10 @@ func ValidateSubscriptionAPIFilter(filter *SubscriptionsAPIFilter) (errs *apis.F
).Also(
ValidateSingleAttributeMap(filter.Suffix).ViaField("suffix"),
).Also(
ValidateSubscriptionAPIFiltersList(filter.All).ViaField("all"),
ValidateSubscriptionAPIFiltersList(ctx, filter.All).ViaField("all"),
).Also(
ValidateSubscriptionAPIFiltersList(filter.Any).ViaField("any"),
).Also(ValidateSubscriptionAPIFilter(filter.Not).ViaField("not"))
ValidateSubscriptionAPIFiltersList(ctx, filter.Any).ViaField("any"),
).Also(ValidateSubscriptionAPIFilter(ctx, filter.Not).ViaField("not"))
return errs
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/eventing/v1/trigger_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"testing"

"knative.dev/eventing/pkg/apis/feature"

"github.com/google/go-cmp/cmp"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -488,6 +490,9 @@ func TestTriggerSpecValidation(t *testing.T) {
}

func TestFilterSpecValidation(t *testing.T) {
newTriggerFiltersEnabledCtx := feature.ToContext(context.TODO(), feature.Flags{
feature.NewTriggerFilters: feature.Enabled,
})
tests := []struct {
name string
filter *TriggerFilter
Expand Down Expand Up @@ -727,7 +732,7 @@ func TestFilterSpecValidation(t *testing.T) {
Filters: test.filters,
Subscriber: validSubscriber,
}
got := ts.Validate(context.TODO())
got := ts.Validate(newTriggerFiltersEnabledCtx)
if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" {
t.Errorf("Validate TriggerSpec (-want, +got) =\n%s", diff)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/feature/flag_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ const (
DeliveryTimeout = "delivery-timeout"
KReferenceMapping = "kreference-mapping"
StrictSubscriber = "strict-subscriber"
NewTriggerFilters = "new-trigger-filters"
)

0 comments on commit 61fc963

Please sign in to comment.