diff --git a/pkg/apis/triggers/v1alpha1/event_listener_validation.go b/pkg/apis/triggers/v1alpha1/event_listener_validation.go index e3444ab0f..b41d90a18 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_validation.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_validation.go @@ -272,6 +272,10 @@ func (t *EventListenerTrigger) validate(ctx context.Context) (errs *apis.FieldEr errs = errs.Also(apis.ErrMissingOneOf("template", "triggerRef")) } + if t.TriggerRef != "" && (t.Template != nil || t.Bindings != nil || t.Interceptors != nil) { + errs = errs.Also(apis.ErrMultipleOneOf("triggerRef", "template or bindings or interceptors")) + } + // Validate optional Bindings errs = errs.Also(triggerSpecBindingArray(t.Bindings).validate(ctx)) if t.Template != nil { diff --git a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go index bd3b4a7cc..ca484d9b4 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go @@ -261,11 +261,6 @@ func Test_EventListenerValidate(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{ - Ref: "tb", - Kind: "TriggerBinding", - APIVersion: "v1alpha1", - }}, TriggerRef: "triggerref", }}, Resources: v1alpha1.Resources{ @@ -737,6 +732,27 @@ func TestEventListenerValidate_error(t *testing.T) { }, }, }, + }, { + name: "Specify TriggerTemplate along with TriggerRef", + el: &v1alpha1.EventListener{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "namespace", + }, + Spec: v1alpha1.EventListenerSpec{ + Triggers: []v1alpha1.EventListenerTrigger{{ + Template: &v1alpha1.EventListenerTemplate{ + Ref: ptr.String("tt"), + }, + TriggerRef: "triggerref", + }}, + Resources: v1alpha1.Resources{ + CustomResource: &v1alpha1.CustomResource{ + RawExtension: getValidRawData(t), + }, + }, + }, + }, }} for _, test := range tests {