diff --git a/config/core/resources/broker.yaml b/config/core/resources/broker.yaml index 200105755bc..d736fb2a302 100644 --- a/config/core/resources/broker.yaml +++ b/config/core/resources/broker.yaml @@ -54,6 +54,10 @@ spec: name: v1beta1 served: true storage: true + - << : *version + name: v1 + served: true + storage: false names: kind: Broker plural: brokers diff --git a/config/core/resources/trigger.yaml b/config/core/resources/trigger.yaml index 2805ba75775..db6d9460a3d 100644 --- a/config/core/resources/trigger.yaml +++ b/config/core/resources/trigger.yaml @@ -28,6 +28,34 @@ spec: storage: false subresources: status: {} + schema: + openAPIV3Schema: + type: object + # this is a work around so we don't need to flush out the + # schema for each version at this time + # + # see issue: https://github.com/knative/serving/issues/912 + x-kubernetes-preserve-unknown-fields: true + additionalPrinterColumns: + - name: Ready + type: string + jsonPath: ".status.conditions[?(@.type==\"Ready\")].status" + - name: Reason + type: string + jsonPath: ".status.conditions[?(@.type==\"Ready\")].reason" + - name: Broker + type: string + jsonPath: .spec.broker + - name: Subscriber_URI + type: string + jsonPath: .status.subscriberUri + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + - << : *version + name: v1beta1 + served: true + storage: true schema: openAPIV3Schema: type: object @@ -85,26 +113,10 @@ spec: status: type: object x-kubernetes-preserve-unknown-fields: true - additionalPrinterColumns: - - name: Ready - type: string - jsonPath: ".status.conditions[?(@.type==\"Ready\")].status" - - name: Reason - type: string - jsonPath: ".status.conditions[?(@.type==\"Ready\")].reason" - - name: Broker - type: string - jsonPath: .spec.broker - - name: Subscriber_URI - type: string - jsonPath: .status.subscriberUri - - name: Age - type: date - jsonPath: .metadata.creationTimestamp - << : *version - name: v1beta1 + name: v1 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object diff --git a/test/e2e/broker_channel_flow_test.go b/test/e2e/broker_channel_flow_test.go index 58aafbf7b60..ecf3c735f41 100644 --- a/test/e2e/broker_channel_flow_test.go +++ b/test/e2e/broker_channel_flow_test.go @@ -43,6 +43,15 @@ Trigger2 logs all events, Trigger3 filters the transformed event and sends it to Channel. */ -func TestBrokerChannelFlow(t *testing.T) { - helpers.BrokerChannelFlowWithTransformation(t, brokerClass, channelTestRunner) +func TestBrokerChannelFlowTriggerV1BrokerV1(t *testing.T) { + helpers.BrokerChannelFlowWithTransformation(t, brokerClass, "v1", "v1", channelTestRunner) +} +func TestBrokerChannelFlowV1Beta1BrokerV1(t *testing.T) { + helpers.BrokerChannelFlowWithTransformation(t, brokerClass, "v1", "v1beta1", channelTestRunner) +} +func TestBrokerChannelFlowTriggerV1Beta1BrokerV1Beta1(t *testing.T) { + helpers.BrokerChannelFlowWithTransformation(t, brokerClass, "v1beta1", "v1beta1", channelTestRunner) +} +func TestBrokerChannelFlowTriggerV1BrokerV1Beta1(t *testing.T) { + helpers.BrokerChannelFlowWithTransformation(t, brokerClass, "v1beta1", "v1", channelTestRunner) } diff --git a/test/e2e/broker_event_transformation_test.go b/test/e2e/broker_event_transformation_test.go index a16b12e4231..d7d2b67c484 100644 --- a/test/e2e/broker_event_transformation_test.go +++ b/test/e2e/broker_event_transformation_test.go @@ -37,6 +37,15 @@ EventSource ---> Broker ---> Trigger1 -------> Service(Transformation) Note: the number denotes the sequence of the event that flows in this test case. */ -func TestEventTransformationForTrigger(t *testing.T) { - helpers.EventTransformationForTriggerTestHelper(t, brokerClass, channelTestRunner) +func TestEventTransformationForTriggerV1BrokerV1(t *testing.T) { + helpers.EventTransformationForTriggerTestHelper(t, brokerClass, "v1", "v1", channelTestRunner) +} +func TestEventTransformationForTriggerV1Beta1BrokerV1(t *testing.T) { + helpers.EventTransformationForTriggerTestHelper(t, brokerClass, "v1", "v1beta1", channelTestRunner) +} +func TestEventTransformationForTriggerV1Beta1BrokerV1Beta1(t *testing.T) { + helpers.EventTransformationForTriggerTestHelper(t, brokerClass, "v1beta1", "v1beta1", channelTestRunner) +} +func TestEventTransformationForTriggerV1BrokerV1Beta1(t *testing.T) { + helpers.EventTransformationForTriggerTestHelper(t, brokerClass, "v1beta1", "v1", channelTestRunner) } diff --git a/test/e2e/helpers/broker_channel_flow_helper.go b/test/e2e/helpers/broker_channel_flow_helper.go index e5ac1b7a5bd..e562b1d3924 100644 --- a/test/e2e/helpers/broker_channel_flow_helper.go +++ b/test/e2e/helpers/broker_channel_flow_helper.go @@ -51,6 +51,8 @@ Trigger3 filters the transformed event and sends it to Channel. */ func BrokerChannelFlowWithTransformation(t *testing.T, brokerClass string, + brokerVersion string, + triggerVersion string, channelTestRunner testlib.ComponentsTestRunner, options ...testlib.SetupClientOption) { const ( @@ -85,7 +87,11 @@ func BrokerChannelFlowWithTransformation(t *testing.T, //&channel // create a new broker - client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config)) + if brokerVersion == "v1" { + client.CreateBrokerV1OrFail(brokerName, resources.WithBrokerClassForBrokerV1(brokerClass), resources.WithConfigForBrokerV1(config)) + } else { + client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config)) + } client.WaitForResourceReadyOrFail(brokerName, testlib.BrokerTypeMeta) // eventToSend is the event sent as input of the test @@ -107,25 +113,41 @@ func BrokerChannelFlowWithTransformation(t *testing.T, client.CreatePodOrFail(transformationPod, testlib.WithService(transformationPodName)) // create trigger1 to receive the original event, and do event transformation - client.CreateTriggerOrFailV1Beta1( - triggerName1, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(eventSource, eventType, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(transformationPodName), - ) - + if triggerVersion == "v1" { + client.CreateTriggerV1OrFail( + triggerName1, + resources.WithBrokerV1(brokerName), + resources.WithAttributesTriggerFilterV1(eventSource, eventType, nil), + resources.WithSubscriberServiceRefForTriggerV1(transformationPodName), + ) + } else { + client.CreateTriggerOrFailV1Beta1( + triggerName1, + resources.WithBrokerV1Beta1(brokerName), + resources.WithAttributesTriggerFilterV1Beta1(eventSource, eventType, nil), + resources.WithSubscriberServiceRefForTriggerV1Beta1(transformationPodName), + ) + } // create event tracker that should receive all sent events allEventTracker, _ := recordevents.StartEventRecordOrFail(client, allEventsRecorderPodName) defer allEventTracker.Cleanup() // create trigger to receive all the events - client.CreateTriggerOrFailV1Beta1( - triggerName2, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(any, any, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(allEventsRecorderPodName), - ) - + if triggerVersion == "v1" { + client.CreateTriggerV1OrFail( + triggerName2, + resources.WithBrokerV1(brokerName), + resources.WithAttributesTriggerFilterV1(any, any, nil), + resources.WithSubscriberServiceRefForTriggerV1(allEventsRecorderPodName), + ) + } else { + client.CreateTriggerOrFailV1Beta1( + triggerName2, + resources.WithBrokerV1Beta1(brokerName), + resources.WithAttributesTriggerFilterV1Beta1(any, any, nil), + resources.WithSubscriberServiceRefForTriggerV1Beta1(allEventsRecorderPodName), + ) + } // create channel for trigger3 client.CreateChannelOrFail(channelName, &channel) client.WaitForResourceReadyOrFail(channelName, &channel) @@ -135,12 +157,21 @@ func BrokerChannelFlowWithTransformation(t *testing.T, if err != nil { st.Fatalf("Failed to get the url for the channel %q: %+v", channelName, err) } - client.CreateTriggerOrFailV1Beta1( - triggerName3, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(transformedEventSource, transformedEventType, nil), - resources.WithSubscriberURIForTriggerV1Beta1(channelURL), - ) + if triggerVersion == "v1" { + client.CreateTriggerV1OrFail( + triggerName3, + resources.WithBrokerV1(brokerName), + resources.WithAttributesTriggerFilterV1(transformedEventSource, transformedEventType, nil), + resources.WithSubscriberURIForTriggerV1(channelURL), + ) + } else { + client.CreateTriggerOrFailV1Beta1( + triggerName3, + resources.WithBrokerV1Beta1(brokerName), + resources.WithAttributesTriggerFilterV1Beta1(transformedEventSource, transformedEventType, nil), + resources.WithSubscriberURIForTriggerV1Beta1(channelURL), + ) + } // create event tracker that should receive only transformed events transformedEventTracker, _ := recordevents.StartEventRecordOrFail(client, transformedEventsRecorderPodName) diff --git a/test/e2e/helpers/broker_event_transformation_test_helper.go b/test/e2e/helpers/broker_event_transformation_test_helper.go index ac984eae021..1a6b1ca010a 100644 --- a/test/e2e/helpers/broker_event_transformation_test_helper.go +++ b/test/e2e/helpers/broker_event_transformation_test_helper.go @@ -23,7 +23,6 @@ import ( "github.com/google/uuid" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/eventing/v1beta1" testlib "knative.dev/eventing/test/lib" "knative.dev/eventing/test/lib/recordevents" "knative.dev/eventing/test/lib/resources" @@ -45,13 +44,14 @@ Note: the number denotes the sequence of the event that flows in this test case. */ func EventTransformationForTriggerTestHelper(t *testing.T, brokerClass string, - channelTestRunner testlib.ComponentsTestRunner, + brokerVersion string, + triggerVersion string, + componentsTestRunner testlib.ComponentsTestRunner, options ...testlib.SetupClientOption) { const ( senderName = "e2e-eventtransformation-sender" brokerName = "e2e-eventtransformation-broker" - any = v1beta1.TriggerAnyFilter eventType = "type1" transformedEventType = "type2" eventSource = "source1" @@ -66,7 +66,7 @@ func EventTransformationForTriggerTestHelper(t *testing.T, recordEventsPodName = "recordevents-pod" ) - channelTestRunner.RunTests(t, testlib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { + componentsTestRunner.RunTests(t, testlib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { client := testlib.Setup(st, true, options...) defer testlib.TearDown(client) @@ -74,7 +74,11 @@ func EventTransformationForTriggerTestHelper(t *testing.T, config := client.CreateBrokerConfigMapOrFail(brokerName, &channel) // create a new broker - client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config)) + if brokerVersion == "v1" { + client.CreateBrokerV1OrFail(brokerName, resources.WithBrokerClassForBrokerV1(brokerClass), resources.WithConfigForBrokerV1(config)) + } else { + client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config)) + } client.WaitForResourceReadyOrFail(brokerName, testlib.BrokerTypeMeta) // create the transformation service @@ -87,24 +91,42 @@ func EventTransformationForTriggerTestHelper(t *testing.T, client.CreatePodOrFail(transformationPod, testlib.WithService(transformationPodName)) // create trigger1 for event transformation - client.CreateTriggerOrFailV1Beta1( - originalTriggerName, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(eventSource, eventType, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(transformationPodName), - ) + if triggerVersion == "v1" { + client.CreateTriggerV1OrFail( + originalTriggerName, + resources.WithBrokerV1(brokerName), + resources.WithAttributesTriggerFilterV1(eventSource, eventType, nil), + resources.WithSubscriberServiceRefForTriggerV1(transformationPodName), + ) + } else { + client.CreateTriggerOrFailV1Beta1( + originalTriggerName, + resources.WithBrokerV1Beta1(brokerName), + resources.WithAttributesTriggerFilterV1Beta1(eventSource, eventType, nil), + resources.WithSubscriberServiceRefForTriggerV1Beta1(transformationPodName), + ) + } // create logger pod and service eventTracker, _ := recordevents.StartEventRecordOrFail(client, recordEventsPodName) defer eventTracker.Cleanup() // create trigger2 for event receiving - client.CreateTriggerOrFailV1Beta1( - transformedTriggerName, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(transformedEventSource, transformedEventType, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(recordEventsPodName), - ) + if triggerVersion == "v1" { + client.CreateTriggerV1OrFail( + transformedTriggerName, + resources.WithBrokerV1(brokerName), + resources.WithAttributesTriggerFilterV1(transformedEventSource, transformedEventType, nil), + resources.WithSubscriberServiceRefForTriggerV1(recordEventsPodName), + ) + } else { + client.CreateTriggerOrFailV1Beta1( + transformedTriggerName, + resources.WithBrokerV1Beta1(brokerName), + resources.WithAttributesTriggerFilterV1Beta1(transformedEventSource, transformedEventType, nil), + resources.WithSubscriberServiceRefForTriggerV1Beta1(recordEventsPodName), + ) + } // wait for all test resources to be ready, so that we can start sending events client.WaitForAllTestResourcesReadyOrFail() diff --git a/test/lib/creation.go b/test/lib/creation.go index 9705f4b1e41..ea757169b90 100644 --- a/test/lib/creation.go +++ b/test/lib/creation.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" @@ -145,16 +146,16 @@ func (c *Client) CreateBrokerConfigMapOrFail(name string, channel *metav1.TypeMe } } -// CreateBrokerV1Beta1OrFail will create a Broker or fail the test if there is an error. +// CreateBrokerV1Beta1OrFail will create a v1beta1 Broker or fail the test if there is an error. func (c *Client) CreateBrokerV1Beta1OrFail(name string, options ...resources.BrokerV1Beta1Option) *v1beta1.Broker { namespace := c.Namespace broker := resources.BrokerV1Beta1(name, options...) brokers := c.Eventing.EventingV1beta1().Brokers(namespace) - c.T.Logf("Creating broker %s", name) + c.T.Logf("Creating v1beta1 broker %s", name) // update broker with the new reference broker, err := brokers.Create(broker) if err != nil { - c.T.Fatalf("Failed to create broker %q: %v", name, err) + c.T.Fatalf("Failed to create v1beta1 broker %q: %v", name, err) } c.Tracker.AddObj(broker) return broker @@ -175,6 +176,36 @@ func (c *Client) CreateTriggerOrFailV1Beta1(name string, options ...resources.Tr return trigger } +// CreateBrokerV1OrFail will create a v1 Broker or fail the test if there is an error. +func (c *Client) CreateBrokerV1OrFail(name string, options ...resources.BrokerV1Option) *eventingv1.Broker { + namespace := c.Namespace + broker := resources.BrokerV1(name, options...) + brokers := c.Eventing.EventingV1().Brokers(namespace) + c.T.Logf("Creating v1 broker %s", name) + // update broker with the new reference + broker, err := brokers.Create(broker) + if err != nil { + c.T.Fatalf("Failed to create v1 broker %q: %v", name, err) + } + c.Tracker.AddObj(broker) + return broker +} + +// CreateTriggerOrFailV1 will create a v1 Trigger or fail the test if there is an error. +func (c *Client) CreateTriggerV1OrFail(name string, options ...resources.TriggerOptionV1) *eventingv1.Trigger { + namespace := c.Namespace + trigger := resources.TriggerV1(name, options...) + triggers := c.Eventing.EventingV1().Triggers(namespace) + c.T.Logf("Creating v1 trigger %s", name) + // update trigger with the new reference + trigger, err := triggers.Create(trigger) + if err != nil { + c.T.Fatalf("Failed to create v1 trigger %q: %v", name, err) + } + c.Tracker.AddObj(trigger) + return trigger +} + // CreateFlowsSequenceOrFail will create a Sequence (in flows.knative.dev api group) or // fail the test if there is an error. func (c *Client) CreateFlowsSequenceOrFail(sequence *flowsv1beta1.Sequence) { diff --git a/test/lib/resources/eventing.go b/test/lib/resources/eventing.go index b4d374abb4e..d47dabc7a6c 100644 --- a/test/lib/resources/eventing.go +++ b/test/lib/resources/eventing.go @@ -27,17 +27,25 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" pkgTest "knative.dev/pkg/test" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" ) -// BrokerV1Beta1Option enables further configuration of a Broker. +// BrokerV1Beta1Option enables further configuration of a v1beta1 Broker. type BrokerV1Beta1Option func(*eventingv1beta1.Broker) // TriggerOptionV1Beta1 enables further configuration of a v1beta1 Trigger. type TriggerOptionV1Beta1 func(*eventingv1beta1.Trigger) +// BrokerV1Option enables further configuration of a v1 Broker. +type BrokerV1Option func(*eventingv1.Broker) + +// TriggerOptionV1 enables further configuration of a v1 Trigger. +type TriggerOptionV1 func(*eventingv1.Trigger) + // SubscriptionOptionV1Beta1 enables further configuration of a Subscription. type SubscriptionOptionV1Beta1 func(*messagingv1beta1.Subscription) @@ -176,6 +184,33 @@ func WithDeliveryForBrokerV1Beta1(delivery *eventingduckv1beta1.DeliverySpec) Br } } +func WithConfigForBrokerV1(config *duckv1.KReference) BrokerV1Option { + return func(b *eventingv1.Broker) { + b.Spec.Config = config + } +} + +// WithBrokerClassForBrokerV1 returns a function that adds a brokerClass +// annotation to the given v1 Broker. +func WithBrokerClassForBrokerV1(brokerClass string) BrokerV1Option { + return func(b *eventingv1.Broker) { + annotations := b.GetAnnotations() + if annotations == nil { + annotations = make(map[string]string, 1) + } + annotations["eventing.knative.dev/broker.class"] = brokerClass + b.SetAnnotations(annotations) + } +} + +// WithDeliveryForBrokerV1 returns a function that adds a Delivery for the given +// v1 Broker. +func WithDeliveryForBrokerV1(delivery *eventingduckv1.DeliverySpec) BrokerV1Option { + return func(b *eventingv1.Broker) { + b.Spec.Delivery = delivery + } +} + // ConfigMap returns a ConfigMap. func ConfigMap(name, namespace string, data map[string]string) *corev1.ConfigMap { return &corev1.ConfigMap{ @@ -191,7 +226,7 @@ func ConfigMap(name, namespace string, data map[string]string) *corev1.ConfigMap } } -// Broker returns a Broker. +// BrokerV1Beta1 returns a v1beta1 Broker. func BrokerV1Beta1(name string, options ...BrokerV1Beta1Option) *eventingv1beta1.Broker { broker := &eventingv1beta1.Broker{ ObjectMeta: metav1.ObjectMeta{ @@ -204,6 +239,19 @@ func BrokerV1Beta1(name string, options ...BrokerV1Beta1Option) *eventingv1beta1 return broker } +// BrokerV1 returns a v1 Broker. +func BrokerV1(name string, options ...BrokerV1Option) *eventingv1.Broker { + broker := &eventingv1.Broker{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + } + for _, option := range options { + option(broker) + } + return broker +} + // WithAttributesTriggerFilter returns an option that adds a TriggerFilter with Attributes for the given Trigger. func WithAttributesTriggerFilterV1Beta1(eventSource, eventType string, extensions map[string]interface{}) TriggerOptionV1Beta1 { attrs := make(map[string]string) @@ -227,6 +275,29 @@ func WithAttributesTriggerFilterV1Beta1(eventSource, eventType string, extension } } +// WithAttributesTriggerFilter returns an option that adds a TriggerFilter with Attributes for the given Trigger. +func WithAttributesTriggerFilterV1(eventSource, eventType string, extensions map[string]interface{}) TriggerOptionV1 { + attrs := make(map[string]string) + if eventType != "" { + attrs["type"] = eventType + } else { + attrs["type"] = eventingv1.TriggerAnyFilter + } + if eventSource != "" { + attrs["source"] = eventSource + } else { + attrs["source"] = eventingv1.TriggerAnyFilter + } + for k, v := range extensions { + attrs[k] = fmt.Sprintf("%v", v) + } + return func(t *eventingv1.Trigger) { + t.Spec.Filter = &eventingv1.TriggerFilter{ + Attributes: eventingv1.TriggerFilterAttributes(attrs), + } + } +} + // WithDependencyAnnotationTrigger returns an option that adds a dependency annotation to the given Trigger. func WithDependencyAnnotationTriggerV1Beta1(dependencyAnnotation string) TriggerOptionV1Beta1 { return func(t *eventingv1beta1.Trigger) { @@ -237,7 +308,7 @@ func WithDependencyAnnotationTriggerV1Beta1(dependencyAnnotation string) Trigger } } -// WithSubscriberServiceRefForTriggerV1Beta1 returns an option that adds a Subscriber Knative Service Ref for the given Trigger. +// WithSubscriberServiceRefForTriggerV1Beta1 returns an option that adds a Subscriber Knative Service Ref for the given v1beta1 Trigger. func WithSubscriberServiceRefForTriggerV1Beta1(name string) TriggerOptionV1Beta1 { return func(t *eventingv1beta1.Trigger) { if name != "" { @@ -248,7 +319,18 @@ func WithSubscriberServiceRefForTriggerV1Beta1(name string) TriggerOptionV1Beta1 } } -// WithSubscriberURIForTriggerV1Beta1 returns an option that adds a Subscriber URI for the given Trigger. +// WithSubscriberServiceRefForTriggerV1 returns an option that adds a Subscriber Knative Service Ref for the given v1 Trigger. +func WithSubscriberServiceRefForTriggerV1(name string) TriggerOptionV1 { + return func(t *eventingv1.Trigger) { + if name != "" { + t.Spec.Subscriber = duckv1.Destination{ + Ref: KnativeRefForService(name, t.Namespace), + } + } + } +} + +// WithSubscriberURIForTriggerV1Beta1 returns an option that adds a Subscriber URI for the given v1beta1 Trigger. func WithSubscriberURIForTriggerV1Beta1(uri string) TriggerOptionV1Beta1 { apisURI, _ := apis.ParseURL(uri) return func(t *eventingv1beta1.Trigger) { @@ -258,6 +340,16 @@ func WithSubscriberURIForTriggerV1Beta1(uri string) TriggerOptionV1Beta1 { } } +// WithSubscriberURIForTriggerV1 returns an option that adds a Subscriber URI for the given v1 Trigger. +func WithSubscriberURIForTriggerV1(uri string) TriggerOptionV1 { + apisURI, _ := apis.ParseURL(uri) + return func(t *eventingv1.Trigger) { + t.Spec.Subscriber = duckv1.Destination{ + URI: apisURI, + } + } +} + // WithBrokerV1Beta1 returns an option that adds a broker for the given Trigger. func WithBrokerV1Beta1(name string) TriggerOptionV1Beta1 { return func(trigger *eventingv1beta1.Trigger) { @@ -278,6 +370,26 @@ func TriggerV1Beta1(name string, options ...TriggerOptionV1Beta1) *eventingv1bet return trigger } +// WithBrokerV1 returns an option that adds a broker for the given Trigger. +func WithBrokerV1(name string) TriggerOptionV1 { + return func(trigger *eventingv1.Trigger) { + trigger.Spec.Broker = name + } +} + +// TriggerV1 returns a v1 Trigger. +func TriggerV1(name string, options ...TriggerOptionV1) *eventingv1.Trigger { + trigger := &eventingv1.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + } + for _, option := range options { + option(trigger) + } + return trigger +} + // WithDeadLetterSinkForDelivery returns an options that adds a DeadLetterSink for the given DeliverySpec. func WithDeadLetterSinkForDelivery(name string) DeliveryOption { return func(delivery *eventingduckv1beta1.DeliverySpec) {