Skip to content

Commit 2660663

Browse files
committed
Move new-apiserversource-filters test to experimental folder
1 parent 1e6e235 commit 2660663

7 files changed

Lines changed: 162 additions & 151 deletions

File tree

test/config/config-features.yaml

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/e2e-common.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ function knative_setup() {
8787
enable_sugar || fail_test "Could not enable Sugar Controller Injection"
8888

8989
unleash_duck || fail_test "Could not unleash the chaos duck"
90-
91-
install_feature_cm || fail_test "Could not install features configmap"
9290
}
9391

9492
function scale_controlplane() {
@@ -273,14 +271,6 @@ function unleash_duck() {
273271
if (( SCALE_CHAOSDUCK_TO_ZERO )); then kubectl -n "${SYSTEM_NAMESPACE}" scale deployment/chaosduck --replicas=0; fi
274272
}
275273

276-
function install_feature_cm() {
277-
KO_FLAGS="${KO_FLAGS:-}"
278-
echo "install feature configmap"
279-
cat test/config/config-features.yaml | \
280-
sed "s/namespace: ${KNATIVE_DEFAULT_NAMESPACE}/namespace: ${SYSTEM_NAMESPACE}/g" | \
281-
ko apply "${KO_FLAGS}" -f - || return $?
282-
}
283-
284274
# Teardown the Knative environment after tests finish.
285275
function knative_teardown() {
286276
echo ">> Stopping Knative Eventing"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//go:build e2e
2+
// +build e2e
3+
4+
/*
5+
Copyright 2024 The Knative Authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package rekt
21+
22+
import (
23+
"testing"
24+
25+
"knative.dev/pkg/system"
26+
"knative.dev/reconciler-test/pkg/k8s"
27+
"knative.dev/reconciler-test/pkg/knative"
28+
29+
"knative.dev/eventing/test/experimental/features/apiserversource_newfilters"
30+
_ "knative.dev/pkg/system/testing"
31+
"knative.dev/reconciler-test/pkg/environment"
32+
)
33+
34+
func TestApiServerSourceNewFiltersFeature(t *testing.T) {
35+
t.Parallel()
36+
37+
ctx, env := global.Environment(
38+
knative.WithKnativeNamespace(system.Namespace()),
39+
knative.WithLoggingConfig,
40+
knative.WithTracingConfig,
41+
k8s.WithEventListener,
42+
environment.Managed(t),
43+
)
44+
45+
env.TestSet(ctx, t, apiserversource_newfilters.NewFiltersFeature())
46+
}

test/experimental/config/features.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ data:
2626
delivery-timeout: "enabled"
2727
new-trigger-filters: "enabled"
2828
eventtype-auto-create: "enabled"
29+
new-apiserversource-filters: "enabled"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Copyright 2024 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package apiserversource_newfilters
18+
19+
import (
20+
"fmt"
21+
rbacv1 "k8s.io/api/rbac/v1"
22+
"knative.dev/eventing/test/rekt/resources/account_role"
23+
24+
"github.com/cloudevents/sdk-go/v2/test"
25+
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
26+
v1 "knative.dev/eventing/pkg/apis/sources/v1"
27+
"knative.dev/eventing/test/rekt/resources/apiserversource"
28+
_ "knative.dev/pkg/system/testing"
29+
"knative.dev/reconciler-test/pkg/eventshub"
30+
eventassert "knative.dev/reconciler-test/pkg/eventshub/assert"
31+
"knative.dev/reconciler-test/pkg/feature"
32+
"knative.dev/reconciler-test/pkg/manifest"
33+
"knative.dev/reconciler-test/pkg/resources/pod"
34+
"knative.dev/reconciler-test/pkg/resources/service"
35+
)
36+
37+
const (
38+
exampleImage = "ko://knative.dev/eventing/test/test_images/print"
39+
)
40+
41+
func NewFiltersFeature() *feature.FeatureSet {
42+
fs := &feature.FeatureSet{
43+
Name: "Knative ApiServerSource - Features - New Filter",
44+
Features: []*feature.Feature{
45+
EventsAreFilteredOut(),
46+
},
47+
}
48+
return fs
49+
}
50+
51+
func EventsAreFilteredOut() *feature.Feature {
52+
source := feature.MakeRandomK8sName("apiserversource")
53+
sink := feature.MakeRandomK8sName("sink")
54+
f := feature.NewFeatureNamed("Filters properly the messages")
55+
56+
f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))
57+
58+
sacmName := feature.MakeRandomK8sName("apiserversource")
59+
f.Setup("Create Service Account for ApiServerSource with RBAC for v1.Pod resources",
60+
setupAccountAndRoleForPods(sacmName))
61+
62+
cfg := []manifest.CfgFn{
63+
apiserversource.WithServiceAccountName(sacmName),
64+
apiserversource.WithEventMode(v1.ResourceMode),
65+
apiserversource.WithSink(service.AsDestinationRef(sink)),
66+
apiserversource.WithFilters([]eventingv1.SubscriptionsAPIFilter{{
67+
Exact: map[string]string{
68+
"type": "dev.knative.apiserver.resource.update",
69+
},
70+
}}),
71+
apiserversource.WithResources(v1.APIVersionKindSelector{
72+
APIVersion: "v1",
73+
Kind: "Pod",
74+
}),
75+
}
76+
77+
f.Setup("install ApiServerSource", apiserversource.Install(source, cfg...))
78+
f.Setup("ApiServerSource goes ready", apiserversource.IsReady(source))
79+
80+
examplePodName := feature.MakeRandomK8sName("example")
81+
82+
// create a pod so that ApiServerSource delivers an event to its sink
83+
// event body is similar to this:
84+
// {"kind":"Pod","namespace":"test-wmbcixlv","name":"example-axvlzbvc","apiVersion":"v1"}
85+
f.Requirement("install example pod", pod.Install(examplePodName, exampleImage))
86+
87+
f.Stable("ApiServerSource as event source").
88+
Must("delivers events",
89+
eventassert.OnStore(sink).MatchEvent(
90+
test.HasType("dev.knative.apiserver.resource.add"),
91+
test.HasExtensions(map[string]interface{}{"apiversion": "v1"}),
92+
test.DataContains(`"kind":"Pod"`),
93+
test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)),
94+
).Exact(0)).
95+
Must("delivers events",
96+
eventassert.OnStore(sink).MatchEvent(
97+
test.HasType("dev.knative.apiserver.resource.update"),
98+
test.HasExtensions(map[string]interface{}{"apiversion": "v1"}),
99+
test.DataContains(`"kind":"Pod"`),
100+
test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)),
101+
).AtLeast(1))
102+
103+
return f
104+
}
105+
106+
func setupAccountAndRoleForPods(sacmName string) feature.StepFn {
107+
return account_role.Install(sacmName,
108+
account_role.WithRole(sacmName+"-clusterrole"),
109+
account_role.WithRules(rbacv1.PolicyRule{
110+
APIGroups: []string{""},
111+
Resources: []string{"events", "pods"},
112+
Verbs: []string{"get", "list", "watch"},
113+
}),
114+
)
115+
}

test/rekt/apiserversource_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,3 @@ func TestApiServerSourceDeployment(t *testing.T) {
212212

213213
env.Test(ctx, t, apiserversourcefeatures.DeployAPIServerSourceWithNodeSelector())
214214
}
215-
216-
func TestApiServerSourceNewFiltersFeature(t *testing.T) {
217-
t.Parallel()
218-
219-
ctx, env := global.Environment(
220-
knative.WithKnativeNamespace(system.Namespace()),
221-
knative.WithLoggingConfig,
222-
knative.WithTracingConfig,
223-
k8s.WithEventListener,
224-
environment.Managed(t),
225-
)
226-
227-
env.TestSet(ctx, t, apiserversourcefeatures.NewFiltersFeature())
228-
}

test/rekt/features/apiserversource/data_plane.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
"github.com/cloudevents/sdk-go/v2/test"
24-
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
2524
"knative.dev/pkg/apis"
2625
duckv1 "knative.dev/pkg/apis/duck/v1"
2726
"knative.dev/pkg/network"
@@ -948,68 +947,3 @@ func SendsEventsWithBrokerAsSinkTLS() *feature.Feature {
948947

949948
return f
950949
}
951-
952-
func NewFiltersFeature() *feature.FeatureSet {
953-
fs := &feature.FeatureSet{
954-
Name: "Knative ApiServerSource - Features - New Filter",
955-
Features: []*feature.Feature{
956-
EventsAreFilteredOut(),
957-
},
958-
}
959-
return fs
960-
}
961-
962-
func EventsAreFilteredOut() *feature.Feature {
963-
source := feature.MakeRandomK8sName("apiserversource")
964-
sink := feature.MakeRandomK8sName("sink")
965-
f := feature.NewFeatureNamed("Filters properly the messages")
966-
967-
f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))
968-
969-
sacmName := feature.MakeRandomK8sName("apiserversource")
970-
f.Setup("Create Service Account for ApiServerSource with RBAC for v1.Pod resources",
971-
setupAccountAndRoleForPods(sacmName))
972-
973-
cfg := []manifest.CfgFn{
974-
apiserversource.WithServiceAccountName(sacmName),
975-
apiserversource.WithEventMode(v1.ResourceMode),
976-
apiserversource.WithSink(service.AsDestinationRef(sink)),
977-
apiserversource.WithFilters([]eventingv1.SubscriptionsAPIFilter{{
978-
Exact: map[string]string{
979-
"type": "dev.knative.apiserver.resource.update",
980-
},
981-
}}),
982-
apiserversource.WithResources(v1.APIVersionKindSelector{
983-
APIVersion: "v1",
984-
Kind: "Pod",
985-
}),
986-
}
987-
988-
f.Setup("install ApiServerSource", apiserversource.Install(source, cfg...))
989-
f.Setup("ApiServerSource goes ready", apiserversource.IsReady(source))
990-
991-
examplePodName := feature.MakeRandomK8sName("example")
992-
993-
// create a pod so that ApiServerSource delivers an event to its sink
994-
// event body is similar to this:
995-
// {"kind":"Pod","namespace":"test-wmbcixlv","name":"example-axvlzbvc","apiVersion":"v1"}
996-
f.Requirement("install example pod", pod.Install(examplePodName, exampleImage))
997-
998-
f.Stable("ApiServerSource as event source").
999-
Must("delivers events",
1000-
eventassert.OnStore(sink).MatchEvent(
1001-
test.HasType("dev.knative.apiserver.resource.add"),
1002-
test.HasExtensions(map[string]interface{}{"apiversion": "v1"}),
1003-
test.DataContains(`"kind":"Pod"`),
1004-
test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)),
1005-
).Exact(0)).
1006-
Must("delivers events",
1007-
eventassert.OnStore(sink).MatchEvent(
1008-
test.HasType("dev.knative.apiserver.resource.update"),
1009-
test.HasExtensions(map[string]interface{}{"apiversion": "v1"}),
1010-
test.DataContains(`"kind":"Pod"`),
1011-
test.DataContains(fmt.Sprintf(`"name":"%s"`, examplePodName)),
1012-
).AtLeast(1))
1013-
1014-
return f
1015-
}

0 commit comments

Comments
 (0)