Skip to content

Commit

Permalink
fix(test): the crossnamespace e2e test passes now (knative#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <cmurray@redhat.com>
  • Loading branch information
Cali0707 authored Jun 27, 2024
1 parent 8c07a7a commit a3a7c4a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/reconciler/broker/trigger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func filterTriggers(featureStore *feature.Store, lister eventinglisters.BrokerLi
return false
}

var broker string
var brokerNamespace string
if featureStore.IsEnabled(feature.CrossNamespaceEventLinks) && trigger.Spec.BrokerRef != nil {
broker = trigger.Spec.BrokerRef.Name
brokerNamespace = trigger.Spec.BrokerRef.Namespace
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/broker/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import (
)

var brokerGVK = eventingv1.SchemeGroupVersion.WithKind("Broker")
var brokerNamespace string
var broker string

const (
// Name of the corev1.Events emitted from the Trigger reconciliation process.
Expand Down Expand Up @@ -91,6 +89,8 @@ type Reconciler struct {
func (r *Reconciler) ReconcileKind(ctx context.Context, t *eventingv1.Trigger) pkgreconciler.Event {
logging.FromContext(ctx).Infow("Reconciling", zap.Any("Trigger", t))

var broker string
var brokerNamespace string
if t.Spec.BrokerRef != nil && feature.FromContext(ctx).IsEnabled(feature.CrossNamespaceEventLinks) {
broker = t.Spec.BrokerRef.Name
brokerNamespace = t.Spec.BrokerRef.Namespace
Expand Down
13 changes: 12 additions & 1 deletion test/rekt/features/trigger/crossnamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"

cetest "github.com/cloudevents/sdk-go/v2/test"
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"
"knative.dev/eventing/test/rekt/resources/trigger"
Expand Down Expand Up @@ -62,9 +64,18 @@ func CrossNamespaceEventLinks(brokerEnvCtx context.Context) *feature.Feature {
f.Setup("install trigger", trigger.Install(triggerName, triggerCfg...))

f.Setup("install subscriber", eventshub.Install(subscriberName, eventshub.StartReceiver))
f.Setup("install event source", eventshub.Install(sourceName, eventshub.StartSenderToNamespacedResource(broker.GVR(), brokerName, brokerNamespace), eventshub.InputEvent(ev)))

// <resource>.IsReady uses the environment in the context to find the resource, hence we can only check the trigger
// However, the trigger being ready implies the broker is ready, so we are okay
f.Setup("trigger is ready", trigger.IsReady(triggerName))
f.Requirement("install event source", eventshub.Install(sourceName, eventshub.StartSenderToNamespacedResource(broker.GVR(), brokerName, brokerNamespace), eventshub.InputEvent(ev)))

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

f.Teardown("delete trigger", func(ctx context.Context, t feature.T) {
env := environment.FromContext(ctx)
eventingclient.Get(ctx).EventingV1().Triggers(env.Namespace()).Delete(ctx, triggerName, metav1.DeleteOptions{})
})

return f
}
2 changes: 2 additions & 0 deletions test/rekt/resources/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func WithBrokerRef(ref *duckv1.KReference) manifest.CfgFn {
brokerRef["name"] = ref.Name
brokerRef["namespace"] = ref.Namespace
}

cfg["brokerRef"] = brokerRef
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/rekt/resources/trigger/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec:
{{ if .brokerName }}
broker: {{ .brokerName }}
{{ end }}
{{ if .brokerRef }}
brokerRef:
kind: {{ .brokerRef.kind }}
namespace: {{ .brokerRef.namespace }}
name: {{ .brokerRef.name }}
apiVersion: {{ .brokerRef.apiVersion }}
{{ end }}
{{ if .filter }}
filter:
attributes:
Expand Down

0 comments on commit a3a7c4a

Please sign in to comment.