diff --git a/test/config/config-features.yaml b/test/config/config-features.yaml deleted file mode 100644 index 30194a008de..00000000000 --- a/test/config/config-features.yaml +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2024 The Knative Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-features - namespace: knative-eventing - labels: -data: - # ALPHA feature: The kreference-group allows you to use the Group field in KReferences. - # For more details: https://github.com/knative/eventing/issues/5086 - kreference-group: "disabled" - - # ALPHA feature: The delivery-retryafter allows you to use the RetryAfter field in DeliverySpec. - # For more details: https://github.com/knative/eventing/issues/5811 - delivery-retryafter: "disabled" - - # BETA feature: The delivery-timeout allows you to use the Timeout field in DeliverySpec. - # For more details: https://github.com/knative/eventing/issues/5148 - delivery-timeout: "enabled" - - # ALPHA feature: The kreference-mapping allows you to map kreference onto templated URI - # For more details: https://github.com/knative/eventing/issues/5593 - kreference-mapping: "disabled" - - # BETA 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: "enabled" - - # ALPHA feature: The transport-encryption flag allows you to encrypt events in transit using the transport layer security (TLS) protocol. - # For more details: https://github.com/knative/eventing/issues/5957 - transport-encryption: "disabled" - - # ALPHA feature: The eventtype-auto-create flag allows automatic creation of Even Type instances based on Event's type being processed. - # For more details: https://github.com/knative/eventing/issues/6909 - eventtype-auto-create: "disabled" - - # ALPHA feature: The aauthentication-oidc flag allows you to use OIDC authentication for Eventing. - # For more details: https://github.com/knative/eventing/issues/7174 - authentication-oidc: "disabled" - - # ALPHA feature: The cross-namespace-event-links flag allows you to use cross-namespace referencing for Eventing. - # For more details: https://github.com/knative/eventing/issues/7739 - cross-namespace-event-links: "disabled" - - # ALPHA feature: The new-apiserversource-filters flag allows you to use the new `filters` field - # in APIServerSource objects with its rich filtering capabilities. - new-apiserversource-filters: "enabled" diff --git a/test/e2e-common.sh b/test/e2e-common.sh index 20e052c9335..6a91baa2f8b 100755 --- a/test/e2e-common.sh +++ b/test/e2e-common.sh @@ -89,8 +89,6 @@ function knative_setup() { enable_sugar || fail_test "Could not enable Sugar Controller Injection" unleash_duck || fail_test "Could not unleash the chaos duck" - - install_feature_cm || fail_test "Could not install features configmap" } function scale_controlplane() { @@ -277,14 +275,6 @@ function unleash_duck() { if (( SCALE_CHAOSDUCK_TO_ZERO )); then kubectl -n "${SYSTEM_NAMESPACE}" scale deployment/chaosduck --replicas=0; fi } -function install_feature_cm() { - KO_FLAGS="${KO_FLAGS:-}" - echo "install feature configmap" - cat test/config/config-features.yaml | \ - sed "s/namespace: ${KNATIVE_DEFAULT_NAMESPACE}/namespace: ${SYSTEM_NAMESPACE}/g" | \ - ko apply "${KO_FLAGS}" -f - || return $? -} - # Teardown the Knative environment after tests finish. function knative_teardown() { echo ">> Stopping Knative Eventing" diff --git a/test/experimental/apiserversource_newfilters_test.go b/test/experimental/apiserversource_newfilters_test.go new file mode 100644 index 00000000000..fbb7b05f1d5 --- /dev/null +++ b/test/experimental/apiserversource_newfilters_test.go @@ -0,0 +1,46 @@ +//go:build e2e +// +build e2e + +/* +Copyright 2024 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package experimental + +import ( + "testing" + + "knative.dev/pkg/system" + "knative.dev/reconciler-test/pkg/k8s" + "knative.dev/reconciler-test/pkg/knative" + + "knative.dev/eventing/test/experimental/features/apiserversource_newfilters" + _ "knative.dev/pkg/system/testing" + "knative.dev/reconciler-test/pkg/environment" +) + +func TestApiServerSourceNewFiltersFeature(t *testing.T) { + t.Parallel() + + ctx, env := global.Environment( + knative.WithKnativeNamespace(system.Namespace()), + knative.WithLoggingConfig, + knative.WithTracingConfig, + k8s.WithEventListener, + environment.Managed(t), + ) + + env.TestSet(ctx, t, apiserversource_newfilters.NewFiltersFeature()) +} diff --git a/test/experimental/config/features.yaml b/test/experimental/config/features.yaml index 8968e320835..f7d83ebc0bb 100644 --- a/test/experimental/config/features.yaml +++ b/test/experimental/config/features.yaml @@ -26,3 +26,4 @@ data: delivery-timeout: "enabled" new-trigger-filters: "enabled" eventtype-auto-create: "enabled" + new-apiserversource-filters: "enabled" diff --git a/test/experimental/features/apiserversource_newfilters/subscription_api_filters.go b/test/experimental/features/apiserversource_newfilters/subscription_api_filters.go new file mode 100644 index 00000000000..a4c79772007 --- /dev/null +++ b/test/experimental/features/apiserversource_newfilters/subscription_api_filters.go @@ -0,0 +1,116 @@ +/* +Copyright 2024 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package apiserversource_newfilters + +import ( + "fmt" + + rbacv1 "k8s.io/api/rbac/v1" + "knative.dev/eventing/test/rekt/resources/account_role" + + "github.com/cloudevents/sdk-go/v2/test" + eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" + v1 "knative.dev/eventing/pkg/apis/sources/v1" + "knative.dev/eventing/test/rekt/resources/apiserversource" + _ "knative.dev/pkg/system/testing" + "knative.dev/reconciler-test/pkg/eventshub" + eventassert "knative.dev/reconciler-test/pkg/eventshub/assert" + "knative.dev/reconciler-test/pkg/feature" + "knative.dev/reconciler-test/pkg/manifest" + "knative.dev/reconciler-test/pkg/resources/pod" + "knative.dev/reconciler-test/pkg/resources/service" +) + +const ( + exampleImage = "ko://knative.dev/eventing/test/test_images/print" +) + +func NewFiltersFeature() *feature.FeatureSet { + fs := &feature.FeatureSet{ + Name: "Knative ApiServerSource - Features - New Filter", + Features: []*feature.Feature{ + EventsAreFilteredOut(), + }, + } + return fs +} + +func EventsAreFilteredOut() *feature.Feature { + source := feature.MakeRandomK8sName("apiserversource") + sink := feature.MakeRandomK8sName("sink") + f := feature.NewFeatureNamed("Filters properly the messages") + + f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver)) + + sacmName := feature.MakeRandomK8sName("apiserversource") + f.Setup("Create Service Account for ApiServerSource with RBAC for v1.Pod resources", + setupAccountAndRoleForPods(sacmName)) + + cfg := []manifest.CfgFn{ + apiserversource.WithServiceAccountName(sacmName), + apiserversource.WithEventMode(v1.ResourceMode), + apiserversource.WithSink(service.AsDestinationRef(sink)), + apiserversource.WithFilters([]eventingv1.SubscriptionsAPIFilter{{ + Exact: map[string]string{ + "type": "dev.knative.apiserver.resource.update", + }, + }}), + apiserversource.WithResources(v1.APIVersionKindSelector{ + APIVersion: "v1", + Kind: "Pod", + }), + } + + f.Setup("install ApiServerSource", apiserversource.Install(source, cfg...)) + f.Setup("ApiServerSource goes ready", apiserversource.IsReady(source)) + + examplePodName := feature.MakeRandomK8sName("example") + + // create a pod so that ApiServerSource delivers an event to its sink + // event body is similar to this: + // {"kind":"Pod","namespace":"test-wmbcixlv","name":"example-axvlzbvc","apiVersion":"v1"} + f.Requirement("install example pod", pod.Install(examplePodName, exampleImage)) + + f.Stable("ApiServerSource as event source"). + Must("delivers events", + eventassert.OnStore(sink).MatchEvent( + test.HasType("dev.knative.apiserver.resource.add"), + test.HasExtensions(map[string]interface{}{"apiversion": "v1"}), + test.DataContains(`"kind":"Pod"`), + test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)), + ).Exact(0)). + Must("delivers events", + eventassert.OnStore(sink).MatchEvent( + test.HasType("dev.knative.apiserver.resource.update"), + test.HasExtensions(map[string]interface{}{"apiversion": "v1"}), + test.DataContains(`"kind":"Pod"`), + test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)), + ).AtLeast(1)) + + return f +} + +func setupAccountAndRoleForPods(sacmName string) feature.StepFn { + return account_role.Install(sacmName, + account_role.WithRole(sacmName+"-clusterrole"), + account_role.WithRules(rbacv1.PolicyRule{ + APIGroups: []string{""}, + Resources: []string{"events", "pods"}, + Verbs: []string{"get", "list", "watch"}, + }), + ) +} diff --git a/test/rekt/apiserversource_test.go b/test/rekt/apiserversource_test.go index f9ff6f9094e..e2641fc3ba8 100644 --- a/test/rekt/apiserversource_test.go +++ b/test/rekt/apiserversource_test.go @@ -212,17 +212,3 @@ func TestApiServerSourceDeployment(t *testing.T) { env.Test(ctx, t, apiserversourcefeatures.DeployAPIServerSourceWithNodeSelector()) } - -func TestApiServerSourceNewFiltersFeature(t *testing.T) { - t.Parallel() - - ctx, env := global.Environment( - knative.WithKnativeNamespace(system.Namespace()), - knative.WithLoggingConfig, - knative.WithTracingConfig, - k8s.WithEventListener, - environment.Managed(t), - ) - - env.TestSet(ctx, t, apiserversourcefeatures.NewFiltersFeature()) -} diff --git a/test/rekt/features/apiserversource/data_plane.go b/test/rekt/features/apiserversource/data_plane.go index 40b31c6fa73..01661db1716 100644 --- a/test/rekt/features/apiserversource/data_plane.go +++ b/test/rekt/features/apiserversource/data_plane.go @@ -21,7 +21,6 @@ import ( "fmt" "github.com/cloudevents/sdk-go/v2/test" - eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/network" @@ -948,68 +947,3 @@ func SendsEventsWithBrokerAsSinkTLS() *feature.Feature { return f } - -func NewFiltersFeature() *feature.FeatureSet { - fs := &feature.FeatureSet{ - Name: "Knative ApiServerSource - Features - New Filter", - Features: []*feature.Feature{ - EventsAreFilteredOut(), - }, - } - return fs -} - -func EventsAreFilteredOut() *feature.Feature { - source := feature.MakeRandomK8sName("apiserversource") - sink := feature.MakeRandomK8sName("sink") - f := feature.NewFeatureNamed("Filters properly the messages") - - f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver)) - - sacmName := feature.MakeRandomK8sName("apiserversource") - f.Setup("Create Service Account for ApiServerSource with RBAC for v1.Pod resources", - setupAccountAndRoleForPods(sacmName)) - - cfg := []manifest.CfgFn{ - apiserversource.WithServiceAccountName(sacmName), - apiserversource.WithEventMode(v1.ResourceMode), - apiserversource.WithSink(service.AsDestinationRef(sink)), - apiserversource.WithFilters([]eventingv1.SubscriptionsAPIFilter{{ - Exact: map[string]string{ - "type": "dev.knative.apiserver.resource.update", - }, - }}), - apiserversource.WithResources(v1.APIVersionKindSelector{ - APIVersion: "v1", - Kind: "Pod", - }), - } - - f.Setup("install ApiServerSource", apiserversource.Install(source, cfg...)) - f.Setup("ApiServerSource goes ready", apiserversource.IsReady(source)) - - examplePodName := feature.MakeRandomK8sName("example") - - // create a pod so that ApiServerSource delivers an event to its sink - // event body is similar to this: - // {"kind":"Pod","namespace":"test-wmbcixlv","name":"example-axvlzbvc","apiVersion":"v1"} - f.Requirement("install example pod", pod.Install(examplePodName, exampleImage)) - - f.Stable("ApiServerSource as event source"). - Must("delivers events", - eventassert.OnStore(sink).MatchEvent( - test.HasType("dev.knative.apiserver.resource.add"), - test.HasExtensions(map[string]interface{}{"apiversion": "v1"}), - test.DataContains(`"kind":"Pod"`), - test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)), - ).Exact(0)). - Must("delivers events", - eventassert.OnStore(sink).MatchEvent( - test.HasType("dev.knative.apiserver.resource.update"), - test.HasExtensions(map[string]interface{}{"apiversion": "v1"}), - test.DataContains(`"kind":"Pod"`), - test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)), - ).AtLeast(1)) - - return f -}