Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CrossNamespace: e2e test to verify event delivery for broker and trigger #7933

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
49aa6bc
data plane changes
yijie-04 May 10, 2024
9a4b65f
Merge branch 'main' of https://github.com/knative/eventing into broke…
yijie-04 May 17, 2024
ba4d1e5
moved global variables inside function
yijie-04 May 17, 2024
d164904
updated other functions
yijie-04 May 17, 2024
f1f37b3
feature flag
yijie-04 May 22, 2024
5d7cf6b
verifying events get delivered
yijie-04 May 22, 2024
1e5a8de
main test
yijie-04 May 22, 2024
2c76de4
test for broker in different namespace
yijie-04 May 22, 2024
384d975
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 May 22, 2024
f8a08b0
changed to two environments
yijie-04 May 23, 2024
2d6913c
updated namespace variables
yijie-04 May 23, 2024
911471b
moved feature flag prerequisite
yijie-04 May 23, 2024
1265d25
fix global undefined problem
yijie-04 May 23, 2024
0350342
updated creating namespace
yijie-04 May 28, 2024
d1e876b
ctx variable name update
yijie-04 May 28, 2024
1c21962
getting rid of trigger goes ready since it's done in feature
yijie-04 May 28, 2024
0c94399
adding withbrokerref option for trigger install
yijie-04 May 28, 2024
a95985c
changing the way parameter is passed in
yijie-04 May 28, 2024
b2ef591
refactor brokername parameter
yijie-04 May 28, 2024
a6aa91e
clean up unused variables
yijie-04 May 28, 2024
598d93f
added missing broker name
yijie-04 May 29, 2024
470818b
deleted unused parameter
yijie-04 May 29, 2024
c0a0264
enabling feature flag
yijie-04 May 29, 2024
323573a
fixed argument
yijie-04 May 29, 2024
8793618
cleaned up unused variable
yijie-04 May 29, 2024
025823f
manually resolving URL for sending events
yijie-04 May 30, 2024
3f180e4
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 May 30, 2024
9b87955
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 May 31, 2024
a150d6e
use StartSenderToNamespacedResource
yijie-04 May 31, 2024
03b3c7d
Update code
yijie-04 May 31, 2024
0021ca1
comments clean up
yijie-04 May 31, 2024
5e00587
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 Jun 3, 2024
d6ccf4d
Update go.mod
yijie-04 Jun 3, 2024
ba0b2ee
Update go.sum
yijie-04 Jun 3, 2024
29750bf
Update modules.txt
yijie-04 Jun 3, 2024
6372d3e
Update forwarder.go
yijie-04 Jun 3, 2024
a23aed0
update codegen
yijie-04 Jun 3, 2024
e40f580
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 Jun 6, 2024
139a729
debug unit test
yijie-04 Jun 7, 2024
a1d3e88
comments clean up
yijie-04 Jun 7, 2024
3e0c2b7
clean up unused variables
yijie-04 Jun 7, 2024
cddcd55
updated trigger install function
yijie-04 Jun 7, 2024
3f78cc6
undo changes to owners_aliases
yijie-04 Jun 7, 2024
e4d9e7d
updated broker filter handler
yijie-04 Jun 7, 2024
0e5096e
install broker
yijie-04 Jun 7, 2024
c6b05d3
install trigger and broker
yijie-04 Jun 7, 2024
1d22470
adding subscriber to triggerCfg
yijie-04 Jun 10, 2024
bb23183
added withbrokerref function
yijie-04 Jun 10, 2024
829dedd
updated filter handler checks
yijie-04 Jun 11, 2024
fb94381
updated broker in reportArgs
yijie-04 Jun 11, 2024
ae3367d
updated broker handling in handleDispatchToSubscribeRequest
yijie-04 Jun 11, 2024
955d6f8
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 Jun 11, 2024
a2ceb52
updated brokerref in handleDispatchToReplyRequest
yijie-04 Jun 11, 2024
8c07a7a
updated WithBrokerRef fcn
yijie-04 Jun 11, 2024
a3a7c4a
fix(test): the crossnamespace e2e test passes now (#1)
Cali0707 Jun 27, 2024
c1448e6
Merge branch 'main' of https://github.com/knative/eventing into e2e_test
yijie-04 Jun 27, 2024
a809b24
Merge branch 'e2e_test' of github.com:yijie-04/eventing into e2e_test
yijie-04 Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions test/rekt/crossnamespace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//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

Check failure on line 11 in test/rekt/crossnamespace_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: test/rekt/crossnamespace_test.go:11: found mismatched boilerplate lines: {[]string}[0]: -: "\thttp://www.apache.org/licenses/LICENSE-2.0" +: " 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 rekt

import (
"testing"

"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/knative"

"knative.dev/eventing/test/rekt/features/broker"
"knative.dev/eventing/test/rekt/features/trigger"
)

func TestBrokerTriggerCrossNamespaceReference(t *testing.T) {
t.Parallel()

// namespaces and names for the broker and trigger
brokerNamespace := feature.MakeRandomK8sName("broker-namespace")
triggerNamespace := feature.MakeRandomK8sName("trigger-namespace")
brokerName := feature.MakeRandomK8sName("broker")
triggerName := feature.MakeRandomK8sName("trigger")

brokerEnvCtx, brokerEnv := global.Environment(
knative.WithKnativeNamespace(brokerNamespace),
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
)

triggerEnvCtx, triggerEnv := global.Environment(
knative.WithKnativeNamespace(triggerNamespace),
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
)

brokerEnv.Test(brokerEnvCtx, t, broker.GoesReadyInDifferentNamespace(brokerName, brokerNamespace))
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved
brokerEnv.Test(brokerEnvCtx, t, broker.TriggerGoesReady(triggerName, brokerName))
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved
triggerEnv.Test(triggerEnvCtx, t, trigger.CrossNamespaceEventLinks(brokerEnvCtx, brokerNamespace, brokerName, triggerNamespace, triggerName))
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved
}
41 changes: 41 additions & 0 deletions test/rekt/features/broker/crossnamespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2020 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

Check failure on line 8 in test/rekt/features/broker/crossnamespace.go

View workflow job for this annotation

GitHub Actions / style / Golang / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: test/rekt/features/broker/crossnamespace.go:8: found mismatched boilerplate lines: {[]string}[0]: -: "\thttp://www.apache.org/licenses/LICENSE-2.0" +: " 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 broker

import (
"fmt"

"knative.dev/eventing/test/rekt/features/featureflags"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
)

func GoesReadyInDifferentNamespace(name, namespace string, cfg ...manifest.CfgFn) *feature.Feature {
f := new(feature.Feature)
f.Prerequisite("Cross Namespace Event Links is enabled", featureflags.CrossEventLinksEnabled())

// Add the namespace configuration
namespaceCfg := broker.WithConfigNamespace(namespace)
cfg = append(cfg, namespaceCfg)

f.Setup(fmt.Sprintf("install broker %q in namespace %q", name, namespace), broker.Install(name, cfg...))
f.Setup("Broker is ready", broker.IsReady(name))
f.Setup("Broker is addressable", broker.IsAddressable(name))

return f
}
14 changes: 14 additions & 0 deletions test/rekt/features/featureflags/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ func AuthenticationOIDCEnabled() feature.ShouldRun {
}
}

func CrossEventLinksEnabled() feature.ShouldRun {
return func(ctx context.Context, t feature.T) (feature.PrerequisiteResult, error) {
flags, err := getFeatureFlags(ctx, "config-features")
if err != nil {
return feature.PrerequisiteResult{}, err
}

return feature.PrerequisiteResult{
ShouldRun: flags.IsCrossNamespaceEventLinks(),
Reason: flags.String(),
}, nil
}
}

func IstioDisabled() feature.ShouldRun {
return func(ctx context.Context, t feature.T) (feature.PrerequisiteResult, error) {
flags, err := getFeatureFlags(ctx, "config-features")
Expand Down
57 changes: 57 additions & 0 deletions test/rekt/features/trigger/crossnamespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
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

Check failure on line 8 in test/rekt/features/trigger/crossnamespace.go

View workflow job for this annotation

GitHub Actions / style / Golang / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: test/rekt/features/trigger/crossnamespace.go:8: found mismatched boilerplate lines: {[]string}[0]: -: "\thttp://www.apache.org/licenses/LICENSE-2.0" +: " 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 trigger

import (
"context"

cetest "github.com/cloudevents/sdk-go/v2/test"
"github.com/stretchr/testify/require"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
eventingclient "knative.dev/eventing/pkg/client/injection/client"
"knative.dev/eventing/test/rekt/features/featureflags"
"knative.dev/eventing/test/rekt/resources/broker"
)

func CrossNamespaceEventLinks(ctx context.Context, brokerNamespace, brokerName, triggerNamespace, triggerName string) *feature.Feature {
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved
f := feature.NewFeature()

f.Prerequisite("Cross Namespace Event Links is enabled", featureflags.CrossEventLinksEnabled())

sourceName := feature.MakeRandomK8sName("source")
subscriberName := feature.MakeRandomK8sName("subscriber")

ev := cetest.FullEvent()

f.Setup("install subscriber", eventshub.Install(subscriberName, eventshub.StartReceiver))
f.Setup("install event source", eventshub.Install(sourceName, eventshub.StartSenderToResource(broker.GVR(), brokerName), eventshub.InputEvent(ev)))
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved

f.Requirement("trigger is ready", func(ctx context.Context, t feature.T) {
client := eventingclient.Get(ctx)
trig, err := client.EventingV1().Triggers(triggerNamespace).Get(ctx, triggerName, metav1.GetOptions{})
require.NoError(t, err)
require.Equal(t, trig.Status.IsReady(), true)
})
yijie-04 marked this conversation as resolved.
Show resolved Hide resolved

f.Assert("event is received by subscriber", assert.OnStore(subscriberName).MatchEvent(cetest.HasId(ev.ID())).Exact(1))

return f
}
Loading