triggers: Proposal to move TriggerBinding-TriggerTemplate connection out of TriggerBinding definition

In the docs for TriggerBindings, we say:

Although similar, the separation of these two resources was deliberate to encourage TriggerTemplate definitions to be reusable

I don’t disagree with this idea and I don’t think TriggerTemplate reusability should change.

However, for many users, it may end up being even more important for TriggerBindings to be reusable! TriggerBinding reusability is severely limited in the current design because within the definition, a specific TriggerTemplate is referenced within the TemplateRef.

To give an idea of what I’m saying, imagine a user who is getting tons of GitHub events from various contexts/sources. Depending on the situation, the user has defined several TriggerTemplates, and each will execute different jobs like building code, performing test, moderating comments, etc. Now, for each of those TriggerTemplates, which are intended to be called upon separately in differently contexts, the user must completely redefine or copy-paste the payload->parameter logic, because that information is within TriggerBinding, which is tied to a specific TriggerTemplate via TemplateRef. This could become extremely tedious especially for users with complex payloads.

Bottom line, I think TriggerTemplates and TemplateRefs should each be reusable for their own reasons, and the way to do this is to move the TriggerBindingTriggerTemplate connection representation out of the TriggerBinding itself. This could be done by moving the connection information a layer up into EventListener, or to create a new resource, representing that connection and possible conditional logic and then listing those new connection resources within EventListener.

My proposal would be to move the connection information into EventListener. This would mean removing the templateRef field from TriggerBindings, and then an EventListener could look something like this:

apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
  name: simple-listener
spec:
  connections:
    - triggerBinding: simple-pipeline-binding
      triggerTemplate: simple-pipeline-template
    - triggerBinding: another-pipeline-binding
      triggerTemplate: another-pipeline-template

Conditional/filtering information would also go within the connections field. This way, the payload-variable logic is truly encapsulated and reusable within triggerBinding. I see EventListener analogous to a PipelineRun or TaskRun, in that it provides project-specific configuration details like connections, filtering, or perhaps default parameter/payload values, while triggerBinding and triggerTemplate can be reused as needed.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

yeah I like that proposal above from @ncskier better than the current project design. TriggerBindings are actually reusable to some degree because they aren’t tied to specific TriggerTemplates.

Very late to the party but in general I think these are some pretty cool improvements! My comments kinda go hand in hand with #62 - when I look at this proposed design:

apiVersion: tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
  name: my-triggerbinding
spec:
  inputParams:
  - name: secret
    description: The git webhook secret
  - name: branch
    description: The git branch
    default: master
  headerMatches:
  - X-GitHub-Event: push
  - X-GitHub-Secret: $(inputParams.secret)
  conditionals:
  - $(event.ref): refs/heads/$(inputParams.branch)
  outputParams:
  - name: gitrevision
    value: $(event.head_commit.id)
  - name: gitrepositoryurl
    value: $(event.repository.url)

I’m wondering a couple of things:

  1. Does it make sense to have these responsibilities all in the same CRD?
  2. What is the bare minimum set of functionality that we want to get working in our first iteration?

@ncskier was saying:

  1. The EventListener only knows about the addressable endpoint information (deployment + service configurations).
  2. The TriggerBinding only knows about the event information, and how it maps to parameters.
  3. The TriggerTemplate only knows about what resources to create, and how to inject its parameters into these resources.

I like this division of responsibility but for (2), TriggerBinding’s responsibilities, I wonder if we are ready to introduce conditions into the design and if this is the right place to do it - I think we can get a first working iteration of triggers without including conditionals? (Correct me if I’m wrong tho - I’m basically assuming we want to target a use case like GitHub PR triggering for our first iteration, and that we don’t need conditionals or filtering of any kind to make that happen)

(And plus if we want to add Conditionals I’d like to explore making use of Pipeline Conditions if we can! But I’m hoping we can punt on this until we need to 😄)

I agree with proceeding to implement @ncskier 's suggestion