From e0a42328f30f09a877ac81cc58ecb928a7243444 Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Thu, 30 Apr 2020 11:32:44 +0530 Subject: [PATCH] Add Support for Embedding TriggerBindingSpec in EL TriggerBindingSpec can be added to EventListener Trigger --- docs/clustertriggerbindings.md | 2 + docs/eventlisteners.md | 16 +++- ...eventlistener-interceptor-with-secret.yaml | 1 + .../cel-eventlistener-interceptor.yaml | 1 + .../cel-eventlistener-multiple-overlays.yaml | 1 + .../cel-eventlistener-no-filter.yaml | 1 + .../eventlistener-clustertriggerbinding.yaml | 2 + .../eventlistener-embedded-bindings.yaml | 19 +++++ .../eventlistener-interceptor.yaml | 1 + .../eventlistener-multiinterceptor.yaml | 1 + examples/eventlisteners/eventlistener.yaml | 2 + .../github-eventlistener-interceptor.yaml | 1 + .../v1alpha1/event_listener_defaults.go | 13 +++ .../v1alpha1/event_listener_defaults_test.go | 6 ++ .../triggers/v1alpha1/event_listener_types.go | 9 +- .../v1alpha1/event_listener_validation.go | 12 ++- .../event_listener_validation_test.go | 83 ++++++++++++------- .../v1alpha1/zz_generated.deepcopy.go | 7 +- pkg/sink/sink_test.go | 2 +- pkg/template/resource.go | 14 +++- pkg/template/resource_test.go | 37 +++++++-- test/builder/eventlistener.go | 9 +- test/builder/eventlistener_test.go | 73 +++++++++++++--- test/eventlistener_scale_test.go | 2 +- test/eventlistener_test.go | 4 +- 25 files changed, 255 insertions(+), 64 deletions(-) create mode 100644 examples/eventlisteners/eventlistener-embedded-bindings.yaml diff --git a/docs/clustertriggerbindings.md b/docs/clustertriggerbindings.md index 25abec3faf..ff7eee20dc 100644 --- a/docs/clustertriggerbindings.md +++ b/docs/clustertriggerbindings.md @@ -48,8 +48,10 @@ spec: bindings: - name: pipeline-clusterbinding kind: ClusterTriggerBinding + ref: pipeline-clusterbinding - name: message-clusterbinding kind: ClusterTriggerBinding + ref: message-clusterbinding template: name: pipeline-template ``` diff --git a/docs/eventlisteners.md b/docs/eventlisteners.md index 4dfd591150..07d64884e0 100644 --- a/docs/eventlisteners.md +++ b/docs/eventlisteners.md @@ -149,7 +149,7 @@ The `triggers` field is required. Each EventListener can consist of one or more - `name` - (Optional) a valid [Kubernetes name](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set) - [`interceptors`](#interceptors) - (Optional) list of interceptors to use -- `bindings` - A list of names of `TriggerBindings` to use +- `bindings` - A list of names of `TriggerBindings` to use or embedded TriggerBindingsSpecs to use. - `template` - The name of `TriggerTemplate` to use ```yaml @@ -160,7 +160,12 @@ triggers: eventTypes: ["pull_request"] bindings: - name: pipeline-binding + ref: pipeline-binding - name: message-binding + spec: + params: + - name: message + value: Hello from the Triggers EventListener! template: name: pipeline-template ``` @@ -180,7 +185,9 @@ triggers: eventTypes: ["pull_request"] bindings: - name: pipeline-binding + ref: pipeline-binding - name: message-binding + ref: message-binding template: name: pipeline-template ``` @@ -316,6 +323,7 @@ spec: namespace: default bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` @@ -361,6 +369,7 @@ spec: - pull_request bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` @@ -405,6 +414,7 @@ spec: - Push Hook bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` @@ -450,6 +460,7 @@ spec: filter: "header.canonical('X-GitHub-Event') == 'push'" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` @@ -488,6 +499,7 @@ spec: filter: "header.canonical('X-GitHub-Event') == 'push'" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` @@ -515,6 +527,7 @@ spec: expression: "truncate(body.pull_request.head.sha, 7)" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` @@ -544,6 +557,7 @@ spec: expression: "split(body.ref, '/')[2]" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template ``` diff --git a/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml b/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml index f5c38fa9b2..1fb403ae7f 100644 --- a/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml +++ b/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml @@ -19,5 +19,6 @@ spec: filter: "'test-secret'.compareSecret('token', 'mysecret')" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/examples/eventlisteners/cel-eventlistener-interceptor.yaml b/examples/eventlisteners/cel-eventlistener-interceptor.yaml index c89e04f473..2b97b585b7 100644 --- a/examples/eventlisteners/cel-eventlistener-interceptor.yaml +++ b/examples/eventlisteners/cel-eventlistener-interceptor.yaml @@ -22,5 +22,6 @@ spec: filter: "header.canonical('X-GitHub-Event') == 'push'" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml b/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml index 7d39ad56da..7259fbdcd4 100644 --- a/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml +++ b/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml @@ -15,5 +15,6 @@ spec: expression: "split(body.ref, '/')[2]" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/examples/eventlisteners/cel-eventlistener-no-filter.yaml b/examples/eventlisteners/cel-eventlistener-no-filter.yaml index 225c5c15ae..b4a41c7b07 100644 --- a/examples/eventlisteners/cel-eventlistener-no-filter.yaml +++ b/examples/eventlisteners/cel-eventlistener-no-filter.yaml @@ -13,5 +13,6 @@ spec: expression: "truncate(body.pull_request.head.sha, 7)" bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/examples/eventlisteners/eventlistener-clustertriggerbinding.yaml b/examples/eventlisteners/eventlistener-clustertriggerbinding.yaml index 8d29a13540..ddc7f6a6c2 100644 --- a/examples/eventlisteners/eventlistener-clustertriggerbinding.yaml +++ b/examples/eventlisteners/eventlistener-clustertriggerbinding.yaml @@ -10,7 +10,9 @@ spec: bindings: - name: pipeline-clusterbinding kind: ClusterTriggerBinding + ref: pipeline-clusterbinding - name: message-clusterbinding kind: ClusterTriggerBinding + ref: message-clusterbinding template: name: pipeline-template diff --git a/examples/eventlisteners/eventlistener-embedded-bindings.yaml b/examples/eventlisteners/eventlistener-embedded-bindings.yaml new file mode 100644 index 0000000000..ac0019c616 --- /dev/null +++ b/examples/eventlisteners/eventlistener-embedded-bindings.yaml @@ -0,0 +1,19 @@ +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: EventListener +metadata: + name: listener-embed-binding +spec: + serviceAccountName: tekton-triggers-example-sa + triggers: + - name: foo-trig + bindings: + - name: pipeline-binding + ref: pipeline-binding + - name: message-binding + spec: + params: + - name: message + value: Hello from the Triggers EventListener(listener-embed-binding)! + template: + name: pipeline-template diff --git a/examples/eventlisteners/eventlistener-interceptor.yaml b/examples/eventlisteners/eventlistener-interceptor.yaml index 491ced4563..dee715bdc9 100644 --- a/examples/eventlisteners/eventlistener-interceptor.yaml +++ b/examples/eventlisteners/eventlistener-interceptor.yaml @@ -23,5 +23,6 @@ spec: namespace: default bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/examples/eventlisteners/eventlistener-multiinterceptor.yaml b/examples/eventlisteners/eventlistener-multiinterceptor.yaml index 2e64721026..0f1ee86ace 100644 --- a/examples/eventlisteners/eventlistener-multiinterceptor.yaml +++ b/examples/eventlisteners/eventlistener-multiinterceptor.yaml @@ -29,5 +29,6 @@ spec: namespace: default bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/examples/eventlisteners/eventlistener.yaml b/examples/eventlisteners/eventlistener.yaml index cad0a9f249..430e9955c4 100644 --- a/examples/eventlisteners/eventlistener.yaml +++ b/examples/eventlisteners/eventlistener.yaml @@ -9,6 +9,8 @@ spec: - name: foo-trig bindings: - name: pipeline-binding + ref: pipeline-binding - name: message-binding + ref: message-binding template: name: pipeline-template diff --git a/examples/eventlisteners/github-eventlistener-interceptor.yaml b/examples/eventlisteners/github-eventlistener-interceptor.yaml index d417f7f902..96f18b9fc0 100644 --- a/examples/eventlisteners/github-eventlistener-interceptor.yaml +++ b/examples/eventlisteners/github-eventlistener-interceptor.yaml @@ -16,5 +16,6 @@ spec: - pull_request bindings: - name: pipeline-binding + ref: pipeline-binding template: name: pipeline-template diff --git a/pkg/apis/triggers/v1alpha1/event_listener_defaults.go b/pkg/apis/triggers/v1alpha1/event_listener_defaults.go index 470395a9ae..57215df707 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_defaults.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_defaults.go @@ -26,6 +26,8 @@ func (el *EventListener) SetDefaults(ctx context.Context) { // set defaults for i := range el.Spec.Triggers { defaultBindings(&el.Spec.Triggers[i]) + // TODO: Remove this in future release #564. + defaultMandatoryRef((&el.Spec.Triggers[i])) } } } @@ -40,3 +42,14 @@ func defaultBindings(t *EventListenerTrigger) { } } } + +// set default TriggerBinding kind for Bindings +func defaultMandatoryRef(t *EventListenerTrigger) { + if len(t.Bindings) > 0 { + for _, b := range t.Bindings { + if b.Ref == "" && b.Spec == nil { + b.Ref = b.Name + } + } + } +} diff --git a/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go b/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go index e68138cb1e..c062170d2b 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go @@ -38,14 +38,17 @@ func TestEventListenerSetDefaults(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{ { Name: "binding", + Ref: "binding", }, { Name: "namespace-binding", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "namespace-binding", }, { Name: "cluster-binding", Kind: v1alpha1.ClusterTriggerBindingKind, + Ref: "cluster-binding", }, }, }}, @@ -59,14 +62,17 @@ func TestEventListenerSetDefaults(t *testing.T) { { Name: "binding", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "binding", }, { Name: "namespace-binding", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "namespace-binding", }, { Name: "cluster-binding", Kind: v1alpha1.ClusterTriggerBindingKind, + Ref: "cluster-binding", }, }, }}, diff --git a/pkg/apis/triggers/v1alpha1/event_listener_types.go b/pkg/apis/triggers/v1alpha1/event_listener_types.go index d809e18378..33a136ede2 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_types.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_types.go @@ -134,9 +134,12 @@ type SecretRef struct { // EventListenerBinding refers to a particular TriggerBinding or ClusterTriggerBindingresource. type EventListenerBinding struct { - Name string `json:"name"` - Kind TriggerBindingKind `json:"kind"` - APIVersion string `json:"apiversion,omitempty"` + Name string `json:"name"` + Kind TriggerBindingKind `json:"kind"` + // +optional + Ref string `json:"ref,omitempty"` + Spec *TriggerBindingSpec `json:"spec,omitempty"` + APIVersion string `json:"apiversion,omitempty"` } // EventListenerTemplate refers to a particular TriggerTemplate resource. diff --git a/pkg/apis/triggers/v1alpha1/event_listener_validation.go b/pkg/apis/triggers/v1alpha1/event_listener_validation.go index 220c587fa6..c4f18cf711 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_validation.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_validation.go @@ -50,7 +50,17 @@ func (t *EventListenerTrigger) validate(ctx context.Context) *apis.FieldError { return apis.ErrMissingField(fmt.Sprintf("bindings[%d].name", i)) } - if b.Kind != NamespacedTriggerBindingKind && b.Kind != ClusterTriggerBindingKind { + // Either Ref or Spec should be present + if b.Ref == "" && b.Spec == nil { + return apis.ErrMissingOneOf(fmt.Sprintf("bindings[%d].Ref", i), fmt.Sprintf("bindings[%d].Spec", i)) + } + + // Both Ref and Spec can't be present at the same time + if b.Ref != "" && b.Spec != nil { + return apis.ErrMultipleOneOf(fmt.Sprintf("bindings[%d].Ref", i), fmt.Sprintf("bindings[%d].Spec", i)) + } + + if b.Ref != "" && b.Kind != NamespacedTriggerBindingKind && b.Kind != ClusterTriggerBindingKind { return apis.ErrInvalidValue(fmt.Errorf("invalid kind"), fmt.Sprintf("bindings[%d].kind", i)) } } diff --git a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go index b0cdb75ea5..dbbca09e49 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go @@ -35,51 +35,51 @@ func Test_EventListenerValidate(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("dne", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), ))), }, { name: "Valid EventListener No TriggerBinding", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("", "", "", "v1alpha1"), ))), }, { name: "Valid EventListener with TriggerBinding", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "TriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "TriggerBinding", "tb", "v1alpha1"), ))), }, { name: "Valid EventListener with ClusterTriggerBinding", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "ClusterTriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "ClusterTriggerBinding", "tb", "v1alpha1"), ))), }, { name: "Valid EventListener with multiple TriggerBindings", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb1", "ClusterTriggerBinding", "v1alpha1"), - bldr.EventListenerTriggerBinding("tb2", "TriggerBinding", "v1alpha1"), - bldr.EventListenerTriggerBinding("tb3", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb1", "ClusterTriggerBinding", "tb1", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb2", "TriggerBinding", "tb2", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb3", "", "tb3", "v1alpha1"), ))), }, { name: "Valid EventListener No Interceptor", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), ))), }, { name: "Valid EventListener Interceptor", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("svc", "v1", "Service", "namespace"), ))), }, { @@ -87,7 +87,7 @@ func Test_EventListenerValidate(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("svc", "v1", "Service", "namespace", bldr.EventInterceptorParam("Valid-Header-Key", "valid value"), ), @@ -97,7 +97,7 @@ func Test_EventListenerValidate(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("svc", "v1", "Service", "namespace", bldr.EventInterceptorParam("Valid-Header-Key1", "valid value1"), bldr.EventInterceptorParam("Valid-Header-Key1", "valid value2"), @@ -109,18 +109,18 @@ func Test_EventListenerValidate(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("svc", "v1", "Service", "namespace"), ), bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), ))), }, { name: "Valid EventListener with CEL interceptor", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerCELInterceptor("body.value == 'test'"), ))), }, { @@ -128,14 +128,21 @@ func Test_EventListenerValidate(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), + ))), + }, { + name: "Valid EventListener with embedded bindings", + el: bldr.EventListener("name", "namespace", + bldr.EventListenerSpec( + bldr.EventListenerTrigger("tt", "v1alpha1", + bldr.EventListenerTriggerBinding("tb", "", "", "v1alpha1", bldr.TriggerBindingParam("key", "value")), ))), }, { name: "Valid EventListener with CEL overlays", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerCELInterceptor("", bldr.EventListenerCELOverlay("body.value", "'testing'")), ))), }} @@ -165,6 +172,20 @@ func TestEventListenerValidate_error(t *testing.T) { Triggers: nil, }, }, + }, { + name: "TriggerBinding with no ref or spec", + el: bldr.EventListener("name", "namespace", + bldr.EventListenerSpec( + bldr.EventListenerTrigger("tt", "v1alpha1", + bldr.EventListenerTriggerBinding("tb", "", "", "v1alpha1"), + ))), + }, { + name: "TriggerBinding with both ref and spec", + el: bldr.EventListener("name", "namespace", + bldr.EventListenerSpec( + bldr.EventListenerTrigger("tt", "v1alpha1", + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1", bldr.TriggerBindingParam("key", "value")), + ))), }, { name: "Bindings missing name", el: &v1alpha1.EventListener{ @@ -202,7 +223,7 @@ func TestEventListenerValidate_error(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind}}, + Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.EventListenerTemplate{Name: "tt", APIVersion: "invalid"}, }}, }, @@ -216,7 +237,7 @@ func TestEventListenerValidate_error(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind}}, + Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.EventListenerTemplate{Name: "", APIVersion: "v1alpha1"}, }}, }, @@ -226,7 +247,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("svc", "", "", ""), ))), }, { @@ -238,7 +259,7 @@ func TestEventListenerValidate_error(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind}}, + Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.EventListenerTemplate{Name: "tt"}, Interceptors: []*v1alpha1.EventInterceptor{{}}, }}, @@ -253,7 +274,7 @@ func TestEventListenerValidate_error(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind}}, + Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.EventListenerTemplate{Name: "tt"}, Interceptors: []*v1alpha1.EventInterceptor{{ Webhook: &v1alpha1.WebhookInterceptor{ @@ -270,14 +291,14 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "NamespaceTriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "NamespaceTriggerBinding", "tb", "v1alpha1"), ))), }, { name: "Interceptor Wrong APIVersion", el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("foo", "v3", "Service", ""), ))), }, { @@ -285,7 +306,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("foo", "v1", "Deployment", ""), ))), }, { @@ -293,7 +314,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("foo", "v1", "Deployment", "", bldr.EventInterceptorParam("non-canonical-header-key", "valid value"), ), @@ -303,7 +324,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("foo", "v1", "Deployment", "", bldr.EventInterceptorParam("", "valid value"), ), @@ -313,7 +334,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerInterceptor("foo", "v1", "Deployment", "", bldr.EventInterceptorParam("Valid-Header-Key", ""), ), @@ -327,7 +348,7 @@ func TestEventListenerValidate_error(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind}}, + Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.EventListenerTemplate{Name: "tt"}, Interceptors: []*v1alpha1.EventInterceptor{{ GitHub: &v1alpha1.GitHubInterceptor{}, @@ -345,7 +366,7 @@ func TestEventListenerValidate_error(t *testing.T) { }, Spec: v1alpha1.EventListenerSpec{ Triggers: []v1alpha1.EventListenerTrigger{{ - Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind}}, + Bindings: []*v1alpha1.EventListenerBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.EventListenerTemplate{Name: "tt"}, Interceptors: []*v1alpha1.EventInterceptor{{ CEL: &v1alpha1.CELInterceptor{}, @@ -358,7 +379,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerName("github.com/tektoncd/triggers"), ))), }, { @@ -366,7 +387,7 @@ func TestEventListenerValidate_error(t *testing.T) { el: bldr.EventListener("name", "namespace", bldr.EventListenerSpec( bldr.EventListenerTrigger("tt", "v1alpha1", - bldr.EventListenerTriggerBinding("tb", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"), bldr.EventListenerTriggerName("1234567890123456789012345678901234567890123456789012345678901234"), ))), }} diff --git a/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go index e15fa7c0cf..662938d405 100644 --- a/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go @@ -191,6 +191,11 @@ func (in *EventListener) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EventListenerBinding) DeepCopyInto(out *EventListenerBinding) { *out = *in + if in.Spec != nil { + in, out := &in.Spec, &out.Spec + *out = new(TriggerBindingSpec) + (*in).DeepCopyInto(*out) + } return } @@ -321,7 +326,7 @@ func (in *EventListenerTrigger) DeepCopyInto(out *EventListenerTrigger) { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] *out = new(EventListenerBinding) - **out = **in + (*in).DeepCopyInto(*out) } } } diff --git a/pkg/sink/sink_test.go b/pkg/sink/sink_test.go index b1e55df587..30cbf7baa4 100644 --- a/pkg/sink/sink_test.go +++ b/pkg/sink/sink_test.go @@ -197,7 +197,7 @@ func TestHandleEvent(t *testing.T) { tbs = append(tbs, tb) // Add TriggerBinding to trigger in EventListener trigger := bldr.EventListenerTrigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding(tbName, "", "v1alpha1"), + bldr.EventListenerTriggerBinding(tbName, "", tbName, "v1alpha1"), ) triggers = append(triggers, trigger) } diff --git a/pkg/template/resource.go b/pkg/template/resource.go index 9577e74b2c..2f27dea271 100644 --- a/pkg/template/resource.go +++ b/pkg/template/resource.go @@ -49,14 +49,24 @@ func ResolveTrigger(trigger triggersv1.EventListenerTrigger, getTB getTriggerBin tb := make([]*triggersv1.TriggerBinding, 0, len(trigger.Bindings)) ctb := make([]*triggersv1.ClusterTriggerBinding, 0, len(trigger.Bindings)) for _, b := range trigger.Bindings { + if b.Spec != nil { + tb = append(tb, &triggersv1.TriggerBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: b.Name, + }, + Spec: *b.Spec, + }) + continue + } + if b.Kind == triggersv1.ClusterTriggerBindingKind { - ctb2, err := getCTB(b.Name, metav1.GetOptions{}) + ctb2, err := getCTB(b.Ref, metav1.GetOptions{}) if err != nil { return ResolvedTrigger{}, fmt.Errorf("error getting ClusterTriggerBinding %s: %w", b.Name, err) } ctb = append(ctb, ctb2) } else { - tb2, err := getTB(b.Name, metav1.GetOptions{}) + tb2, err := getTB(b.Ref, metav1.GetOptions{}) if err != nil { return ResolvedTrigger{}, fmt.Errorf("error getting TriggerBinding %s: %w", b.Name, err) } diff --git a/pkg/template/resource_test.go b/pkg/template/resource_test.go index 6d0020434c..33ce906177 100644 --- a/pkg/template/resource_test.go +++ b/pkg/template/resource_test.go @@ -310,7 +310,7 @@ func Test_ResolveTrigger(t *testing.T) { { name: "1 binding", trigger: bldr.Trigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding("my-triggerbinding", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("my-triggerbinding", "", "my-triggerbinding", "v1alpha1"), ), want: ResolvedTrigger{ TriggerBindings: []*triggersv1.TriggerBinding{tb}, @@ -321,7 +321,7 @@ func Test_ResolveTrigger(t *testing.T) { { name: "1 clustertype binding", trigger: bldr.Trigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding("my-clustertriggerbinding", "ClusterTriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("my-clustertriggerbinding", "ClusterTriggerBinding", "my-clustertriggerbinding", "v1alpha1"), ), want: ResolvedTrigger{ TriggerBindings: []*triggersv1.TriggerBinding{}, @@ -329,6 +329,27 @@ func Test_ResolveTrigger(t *testing.T) { TriggerTemplate: &tt, }, }, + { + name: "1 embed binding", + trigger: bldr.Trigger("my-triggertemplate", "v1alpha1", + bldr.EventListenerTriggerBinding("my-embed-binding", "", "", "v1alpha1", bldr.TriggerBindingParam("key", "value")), + ), + want: ResolvedTrigger{ + TriggerBindings: []*triggersv1.TriggerBinding{ + { + ObjectMeta: metav1.ObjectMeta{Name: "my-embed-binding"}, + Spec: triggersv1.TriggerBindingSpec{ + Params: []triggersv1.Param{{ + Name: "key", + Value: "value", + }}, + }, + }, + }, + ClusterTriggerBindings: []*triggersv1.ClusterTriggerBinding{}, + TriggerTemplate: &tt, + }, + }, { name: "no binding", trigger: triggersv1.EventListenerTrigger{ @@ -342,8 +363,8 @@ func Test_ResolveTrigger(t *testing.T) { { name: "multiple bindings with builder", trigger: bldr.Trigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding("my-triggerbinding", "", "v1alpha1"), - bldr.EventListenerTriggerBinding("my-clustertriggerbinding", "ClusterTriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("my-triggerbinding", "", "my-triggerbinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("my-clustertriggerbinding", "ClusterTriggerBinding", "my-clustertriggerbinding", "v1alpha1"), ), want: ResolvedTrigger{ TriggerBindings: []*triggersv1.TriggerBinding{tb}, @@ -436,7 +457,7 @@ func Test_ResolveTrigger_error(t *testing.T) { { name: "error triggerbinding", trigger: bldr.Trigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding("invalid-tb-name", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("invalid-tb-name", "", "invalid-tb-name", "v1alpha1"), ), getTB: getTB, getCTB: getCTB, @@ -445,7 +466,7 @@ func Test_ResolveTrigger_error(t *testing.T) { { name: "error clustertriggerbinding", trigger: bldr.Trigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding("invalid-ctb-name", "ClusterTriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding("invalid-ctb-name", "ClusterTriggerBinding", "invalid-ctb-name", "v1alpha1"), ), getTB: getTB, getCTB: getCTB, @@ -454,7 +475,7 @@ func Test_ResolveTrigger_error(t *testing.T) { { name: "error triggertemplate", trigger: bldr.Trigger("invalid-tt-name", "v1alpha1", - bldr.EventListenerTriggerBinding("my-triggerbinding", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("my-triggerbinding", "", "my-triggerbinding", "v1alpha1"), ), getTB: getTB, getCTB: getCTB, @@ -463,7 +484,7 @@ func Test_ResolveTrigger_error(t *testing.T) { { name: "error triggerbinding and triggertemplate", trigger: bldr.Trigger("invalid-tt-name", "v1alpha1", - bldr.EventListenerTriggerBinding("invalid-tb-name", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("invalid-tb-name", "", "invalid-tb-name", "v1alpha1"), ), getTB: getTB, getCTB: getCTB, diff --git a/test/builder/eventlistener.go b/test/builder/eventlistener.go index 177dbe63c7..04c9f595ad 100644 --- a/test/builder/eventlistener.go +++ b/test/builder/eventlistener.go @@ -178,12 +178,13 @@ func EventListenerTriggerServiceAccount(saName, namespace string) EventListenerT } // EventListenerTriggerBinding adds a Binding to the Trigger in EventListenerSpec Triggers. -func EventListenerTriggerBinding(name, kind, apiVersion string) EventListenerTriggerOp { +func EventListenerTriggerBinding(name, kind, ref, apiVersion string, ops ...TriggerBindingSpecOp) EventListenerTriggerOp { return func(trigger *v1alpha1.EventListenerTrigger) { if len(name) != 0 { binding := &v1alpha1.EventListenerBinding{ Name: name, APIVersion: apiVersion, + Ref: ref, } if kind == "ClusterTriggerBinding" { @@ -193,6 +194,12 @@ func EventListenerTriggerBinding(name, kind, apiVersion string) EventListenerTri if kind == "TriggerBinding" || kind == "" { binding.Kind = v1alpha1.NamespacedTriggerBindingKind } + if len(ops) != 0 { + binding.Spec = &v1alpha1.TriggerBindingSpec{} + for _, op := range ops { + op(binding.Spec) + } + } trigger.Bindings = append(trigger.Bindings, binding) } } diff --git a/test/builder/eventlistener_test.go b/test/builder/eventlistener_test.go index 63d96b4f48..eb283f5c89 100644 --- a/test/builder/eventlistener_test.go +++ b/test/builder/eventlistener_test.go @@ -147,6 +147,44 @@ func TestEventListenerBuilder(t *testing.T) { ), ), ), + }, { + name: "One Trigger with one embedded Binding", + normal: &v1alpha1.EventListener{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "namespace", + }, + Spec: v1alpha1.EventListenerSpec{ + ServiceAccountName: "serviceAccount", + Triggers: []v1alpha1.EventListenerTrigger{{ + Bindings: []*v1alpha1.EventListenerBinding{{ + Name: "tb1", + Kind: v1alpha1.NamespacedTriggerBindingKind, + Spec: &v1alpha1.TriggerBindingSpec{ + Params: []v1alpha1.Param{ + { + Name: "key", + Value: "value", + }, + }, + }, + APIVersion: "v1alpha1", + }}, + Template: v1alpha1.EventListenerTemplate{ + Name: "tt1", + APIVersion: "v1alpha1", + }, + }}, + }, + }, + builder: EventListener("name", "namespace", + EventListenerSpec( + EventListenerServiceAccount("serviceAccount"), + EventListenerTrigger("tt1", "v1alpha1", + EventListenerTriggerBinding("tb1", "", "", "v1alpha1", TriggerBindingParam("key", "value")), + ), + ), + ), }, { name: "One Trigger with one Binding", normal: &v1alpha1.EventListener{ @@ -160,6 +198,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -173,7 +212,7 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "", "v1alpha1"), + EventListenerTriggerBinding("tb1", "", "tb1", "v1alpha1"), ), ), ), @@ -190,6 +229,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -203,7 +243,7 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "TriggerBinding", "v1alpha1"), + EventListenerTriggerBinding("tb1", "TriggerBinding", "tb1", "v1alpha1"), ), ), ), @@ -220,6 +260,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.ClusterTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -233,7 +274,7 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "ClusterTriggerBinding", "v1alpha1"), + EventListenerTriggerBinding("tb1", "ClusterTriggerBinding", "tb1", "v1alpha1"), ), ), ), @@ -249,13 +290,16 @@ func TestEventListenerBuilder(t *testing.T) { Triggers: []v1alpha1.EventListenerTrigger{{ Bindings: []*v1alpha1.EventListenerBinding{ { - Name: "tb1", - Kind: v1alpha1.NamespacedTriggerBindingKind, + Name: "tb1", + Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", + APIVersion: "v1alpha1", }, { Name: "ctb1", Kind: v1alpha1.ClusterTriggerBindingKind, + Ref: "ctb1", APIVersion: "v1alpha1", }, }, @@ -270,8 +314,8 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "", "v1alpha1"), - EventListenerTriggerBinding("ctb1", "ClusterTriggerBinding", "v1alpha1"), + EventListenerTriggerBinding("tb1", "", "tb1", "v1alpha1"), + EventListenerTriggerBinding("ctb1", "ClusterTriggerBinding", "ctb1", "v1alpha1"), ), ), ), @@ -295,6 +339,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -305,6 +350,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb2", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb2", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -323,10 +369,10 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "", "v1alpha1"), + EventListenerTriggerBinding("tb1", "", "tb1", "v1alpha1"), ), EventListenerTrigger("tt2", "v1alpha1", - EventListenerTriggerBinding("tb2", "", "v1alpha1"), + EventListenerTriggerBinding("tb2", "", "tb2", "v1alpha1"), ), ), ), @@ -354,6 +400,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -367,7 +414,7 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "", "v1alpha1"), + EventListenerTriggerBinding("tb1", "", "tb1", "v1alpha1"), EventListenerTriggerName("foo-trig"), EventListenerTriggerInterceptor("foo", "v1", "Service", "namespace"), ), @@ -406,6 +453,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -418,7 +466,7 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "", "v1alpha1"), + EventListenerTriggerBinding("tb1", "", "tb1", "v1alpha1"), EventListenerTriggerName("foo-trig"), EventListenerTriggerInterceptor("foo", "v1", "Service", "namespace", EventInterceptorParam("header1", "value1"), @@ -448,6 +496,7 @@ func TestEventListenerBuilder(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{ Name: "tb1", Kind: v1alpha1.NamespacedTriggerBindingKind, + Ref: "tb1", APIVersion: "v1alpha1", }}, Template: v1alpha1.EventListenerTemplate{ @@ -461,7 +510,7 @@ func TestEventListenerBuilder(t *testing.T) { EventListenerSpec( EventListenerServiceAccount("serviceAccount"), EventListenerTrigger("tt1", "v1alpha1", - EventListenerTriggerBinding("tb1", "", "v1alpha1"), + EventListenerTriggerBinding("tb1", "", "tb1", "v1alpha1"), EventListenerTriggerName("foo-trig"), EventListenerCELInterceptor("body.value == 'test'", EventListenerCELOverlay("value", "'testing'")), ), diff --git a/test/eventlistener_scale_test.go b/test/eventlistener_scale_test.go index e3f0663de7..30dfc7fd3a 100644 --- a/test/eventlistener_scale_test.go +++ b/test/eventlistener_scale_test.go @@ -52,7 +52,7 @@ func TestEventListenerScale(t *testing.T) { for i := 0; i < 1000; i++ { trigger := bldr.Trigger("my-triggertemplate", "v1alpha1", - bldr.EventListenerTriggerBinding("my-triggerbinding", "", "v1alpha1"), + bldr.EventListenerTriggerBinding("my-triggerbinding", "", "my-triggerbinding", "v1alpha1"), ) trigger.Name = fmt.Sprintf("%d", i) el.Spec.Triggers = append(el.Spec.Triggers, trigger) diff --git a/test/eventlistener_test.go b/test/eventlistener_test.go index efc7b3ce0b..8158e5379a 100644 --- a/test/eventlistener_test.go +++ b/test/eventlistener_test.go @@ -228,8 +228,8 @@ func TestEventListenerCreate(t *testing.T) { bldr.EventListenerSpec( bldr.EventListenerServiceAccount(sa.Name), bldr.EventListenerTrigger(tt.Name, "", - bldr.EventListenerTriggerBinding(tb.Name, "", "v1alpha1"), - bldr.EventListenerTriggerBinding(ctb.Name, "ClusterTriggerBinding", "v1alpha1"), + bldr.EventListenerTriggerBinding(tb.Name, "", tb.Name, "v1alpha1"), + bldr.EventListenerTriggerBinding(ctb.Name, "ClusterTriggerBinding", ctb.Name, "v1alpha1"), ), ), ))