Skip to content

Commit

Permalink
switch e2e test to use PingSource
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-satchi committed Jan 24, 2023
1 parent 4b09df8 commit c4163c3
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions test/rekt/features/apiserversource/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/eventtype"
"knative.dev/eventing/test/rekt/resources/namespace"
"knative.dev/eventing/test/rekt/resources/pingsource"
"knative.dev/eventing/test/rekt/resources/pod"
"knative.dev/eventing/test/rekt/resources/trigger"
"knative.dev/reconciler-test/pkg/eventshub"
Expand Down Expand Up @@ -355,7 +356,7 @@ func SendsEventsForAllResources() *feature.Feature {
func SendsEventsForAllResourcesWithNamespaceSelector() *feature.Feature {
source := feature.MakeRandomK8sName("apiserversource")
sink := feature.MakeRandomK8sName("sink")
f := feature.NewFeatureNamed("Send events for all resources within select namespaces")
f := feature.NewFeatureNamed("Send events for select resources within multiple namespaces")

f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))

Expand Down Expand Up @@ -435,13 +436,13 @@ func SendsEventsForAllResourcesWithNamespaceSelector() *feature.Feature {
func SendsEventsForAllResourcesWithEmptyNamespaceSelector() *feature.Feature {
source := feature.MakeRandomK8sName("apiserversource")
sink := feature.MakeRandomK8sName("sink")
f := feature.NewFeatureNamed("Send events for all resources within select namespaces")
f := feature.NewFeatureNamed("Send events for select resources within all namespaces")

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))
f.Setup("Create Service Account for ApiServerSource with RBAC for sources.knative.dev/v1 PingSources",
setupAccountAndRoleForPingSources(sacmName))

testNS1 := feature.MakeRandomK8sName("source-namespace-1")
testNS2 := feature.MakeRandomK8sName("source-namespace-2")
Expand All @@ -455,8 +456,8 @@ func SendsEventsForAllResourcesWithEmptyNamespaceSelector() *feature.Feature {
apiserversource.WithEventMode("Reference"),
apiserversource.WithSink(svc.AsKReference(sink), ""),
apiserversource.WithResources(v1.APIVersionKindSelector{
APIVersion: "v1",
Kind: "Pod",
APIVersion: "sources.knative.dev/v1",
Kind: "PingSource",
}),
apiserversource.WithNamespaceSelector(&metav1.LabelSelector{
MatchLabels: map[string]string{},
Expand All @@ -467,29 +468,29 @@ func SendsEventsForAllResourcesWithEmptyNamespaceSelector() *feature.Feature {
f.Setup("install ApiServerSource", apiserversource.Install(source, cfg...))
f.Setup("ApiServerSource goes ready", apiserversource.IsReady(source))

pod1 := feature.MakeRandomK8sName("example-pod-1")
pod2 := feature.MakeRandomK8sName("example-pod-2")
pingSource1 := feature.MakeRandomK8sName("ping-source-1")
pingSource2 := feature.MakeRandomK8sName("ping-source-2")

f.Requirement("install example pod 1",
pod.Install(pod1, pod.WithImage(exampleImage), pod.WithNamespace(testNS1)),
f.Requirement("install PingSource 1",
pingsource.Install(pingSource1, pingsource.WithSink(nil, "http://example.com")),
)
f.Requirement("install example pod 2",
pod.Install(pod2, pod.WithImage(exampleImage), pod.WithNamespace(testNS2)),
f.Requirement("install PingSource 2",
pingsource.Install(pingSource2, pingsource.WithSink(nil, "http://example.com")),
)

f.Stable("ApiServerSource as event source").
Must("delivers events from new namespace",
eventasssert.OnStore(sink).MatchEvent(
test.HasType("dev.knative.apiserver.ref.add"),
test.DataContains(`"kind":"Pod"`),
test.DataContains(fmt.Sprintf(`"name":"%s"`, pod1)),
test.DataContains(`"kind":"PingSource"`),
test.DataContains(fmt.Sprintf(`"name":"%s"`, pingSource1)),
).Exact(1))
f.Stable("ApiServerSource as event source").
Must("delivers events from new namespace",
eventasssert.OnStore(sink).MatchEvent(
test.HasType("dev.knative.apiserver.ref.add"),
test.DataContains(`"kind":"Pod"`),
test.DataContains(fmt.Sprintf(`"name":"%s"`, pod2)),
test.DataContains(`"kind":"PingSource"`),
test.DataContains(fmt.Sprintf(`"name":"%s"`, pingSource2)),
).Exact(1))

// Delete resources including temporary namespaces
Expand Down Expand Up @@ -650,6 +651,17 @@ func setupAccountAndRoleForPods(sacmName string) feature.StepFn {
)
}

func setupAccountAndRoleForPingSources(sacmName string) feature.StepFn {
return account_role.Install(sacmName,
account_role.WithRole(sacmName+"-clusterrole"),
account_role.WithRules(rbacv1.PolicyRule{
APIGroups: []string{"", "sources.knative.dev"},
Resources: []string{"events", "pingsources"},
Verbs: []string{"get", "list", "watch"},
}),
)
}

//// any matches any event
//func any() test.EventMatcher {
// return func(have cloudevent.Event) error {
Expand Down

0 comments on commit c4163c3

Please sign in to comment.