Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: TriggerGroups #1232

Merged

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Oct 1, 2021

Changes

This is a port of #1052 - mostly just fixes so that it can merge cleanly with main

This feature allows an operator to specify a set of interceptors that will be executed
before a group of triggers are selected and executed. This allows common data
to be passed from interceptor execution down to multiple triggers to solve
a set of common use cases across multiple Triggers.

This feature is enabled for now inline in the EventListener spec, but in the future
may be enabled only in alpha once the feature gates proposal is implemented within
this project.

So far I've done the following

  • Rebased Initial implementation for trigger groups #1052 with latest main branch
  • Removed some old code that returned that waited for triggers to finish processing before returning
  • Move the types to v1beta1 (still need to delete it from v1alpha1)
  • Fix the correct body/header to triggers within a trigger group
  • Ensure we wait for triggers in triggerGroups to process to fix sink tests
  • Ported webhook validation to v1beta1
  • Added an extra validation check + tests to enable the field only when enable-api-fields is set to alpha
  • Moved the examples to v1beta1

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Release Notes

Adds a new TriggerGroups field to EventListener spec that allows users to specify a set of interceptors that will be executed
before a group of triggers are selected and executed. To enable this feature set `enable-api-fields` to `alpha` in the `feature-flags-triggers` config map.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Oct 1, 2021
@tekton-robot tekton-robot requested review from khrm and wlynch October 1, 2021 21:01
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 1, 2021
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_validation.go 97.7% 97.9% 0.1
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.8% 2.2

@dibyom dibyom force-pushed the feature/trigger-groups-implementation branch 3 times, most recently from aee6879 to 7f9eacd Compare October 5, 2021 18:55
@dibyom dibyom added this to the Triggers v0.17 milestone Oct 6, 2021
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1beta1/event_listener_validation.go 97.7% 97.9% 0.2
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.8% 2.2

@tektoncd tektoncd deleted a comment from tekton-robot Oct 6, 2021
@tektoncd tektoncd deleted a comment from tekton-robot Oct 6, 2021
@tektoncd tektoncd deleted a comment from tekton-robot Oct 6, 2021
@tektoncd tektoncd deleted a comment from tekton-robot Oct 6, 2021
@tektoncd tektoncd deleted a comment from tekton-robot Oct 6, 2021
@dibyom
Copy link
Member Author

dibyom commented Oct 6, 2021

Move behind an alpha feature gate

Added validation in the webhook. Should probably add another check in the reconciler too

Move examples to behind v1beta1 - would have to figure out how to enable feature gate for the example tests

Due to the allowlist in https://github.com/tektoncd/triggers/blob/main/test/e2e-tests-examples.sh#L138, the triggerGroup example would not be run. I'll work on something like https://github.com/tektoncd/pipeline/tree/main/docs/developers#example-yamls in a separate PR to enable the YAML test for this example.

@dibyom dibyom force-pushed the feature/trigger-groups-implementation branch from 6227ffe to 0eee40a Compare October 6, 2021 18:14
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1beta1/event_listener_validation.go 97.7% 97.9% 0.2
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.6% 2.1

@dibyom
Copy link
Member Author

dibyom commented Oct 6, 2021

I'll add some extra validation in the reconciler so that the alpha fields cannot be used and rebase the commits but in the meantime, this should be ready for a review
/assign @wlynch
/assign @savitaashture

@dibyom dibyom marked this pull request as ready for review October 6, 2021 20:18
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 6, 2021
@dibyom dibyom force-pushed the feature/trigger-groups-implementation branch from 0eee40a to bce959a Compare October 11, 2021 15:47
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1beta1/event_listener_validation.go 97.7% 97.9% 0.2
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.6% 2.1

@dibyom dibyom force-pushed the feature/trigger-groups-implementation branch from bce959a to f86b654 Compare October 11, 2021 16:35
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1beta1/event_listener_validation.go 97.7% 97.9% 0.2
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.6% 2.1

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM! Just minor nits.

Comment on lines 107 to 117
type EventListenerTriggerGroup struct {
Name string `json:"name"`
Interceptors []*TriggerInterceptor `json:"interceptors"`
TriggerSelector EventListenerTriggerSelector `json:"triggerSelector"`
}

type EventListenerTriggerSelector struct {
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing godoc comments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I thought I removed the types from v1alpha1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the types from v1alpha1. They are only available in v1beta1

pkg/apis/triggers/v1beta1/event_listener_types.go Outdated Show resolved Hide resolved
pkg/interceptors/server/server.go Show resolved Hide resolved
}

func (r Sink) selectTriggers(namespaceSelector triggersv1.NamespaceSelector, labelSelector *metav1.LabelSelector) ([]*triggersv1.Trigger, error) {
var trItems []*triggersv1.Trigger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this definition futher down to where its used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack. Keeping it here since it is also called by the HandleEvent function above.


func (r Sink) selectTriggers(namespaceSelector triggersv1.NamespaceSelector, labelSelector *metav1.LabelSelector) ([]*triggersv1.Trigger, error) {
var trItems []*triggersv1.Trigger
var err error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed? AFAICT in this func all error handling in this func is immediately followed with

if err != nil {
  return err
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its because targetLabels := labels.Everything() and then assigned to in inside the if, we have to pre-declare the err variable.

pkg/sink/sink.go Outdated Show resolved Hide resolved
pkg/sink/sink.go Outdated Show resolved Hide resolved
pkg/sink/sink.go Outdated Show resolved Hide resolved
@@ -264,10 +328,14 @@ func (r Sink) processTrigger(t triggersv1.Trigger, request *http.Request, event
go r.recordResourceCreation(resources)
}

func (r Sink) ExecuteTriggerInterceptors(t triggersv1.Trigger, in *http.Request, event []byte, log *zap.SugaredLogger, eventID string, extensions map[string]interface{}) ([]byte, http.Header, *triggersv1.InterceptorResponse, error) {
return r.ExecuteInterceptors(t.Spec.Interceptors, in, event, log, eventID, fmt.Sprintf("namespaces/%s/triggers/%s", t.Namespace, t.Name), t.Namespace, extensions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack. will do in a new PR

@@ -1,27 +0,0 @@
Copyright (c) 2009 The Go Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we now why these licenses are being deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, its just what the hack/update-deps.sh script is doing. (I've seen the x/crypto/LICENSE being added/deleted a few times before).

This feature allows an operator to specify a set of interceptors that will be executed
before a group of triggers are selected and executed. This allows common data
to be passed from interceptor execution down to multiple triggers to solve
a set of common use cases across multiple Triggers.

This feature is enabled for now inline in the EventListener spec, but in the future
may be enabled only in alpha once the feature gates proposal is implemented within
this project.

Addresses tektoncd#945
@dibyom dibyom force-pushed the feature/trigger-groups-implementation branch from f86b654 to 691b204 Compare October 11, 2021 20:27
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1beta1/event_listener_validation.go 97.7% 97.9% 0.2
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.8% 2.2

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last formatting fix, otherwise LGTM

docs/eventlisteners.md Outdated Show resolved Hide resolved
This commit adds validation to ensure that triggerGroups can only be used
in the v1beta1 apiVersion when `enable-api-fields` is set to `alpha`.
@dibyom dibyom force-pushed the feature/trigger-groups-implementation branch from 691b204 to 7da5283 Compare October 12, 2021 01:04
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1beta1/event_listener_validation.go 97.7% 97.9% 0.2
pkg/interceptors/server/server.go 82.1% 82.5% 0.4
pkg/sink/sink.go 73.6% 75.8% 2.2

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 12, 2021
@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wlynch

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 12, 2021
@tekton-robot tekton-robot merged commit c24f7e2 into tektoncd:main Oct 12, 2021
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
Resources Resources `json:"resources,omitempty"`
// Trigger groups allow for centralized processing of an interceptor chain
TriggerGroups []EventListenerTriggerGroup `json:"triggerGroups"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to update the JSON schema bundled with the IntelliJ and VSCode tooling but realized both Triggers and TriggerGroups fields are required. Shouldn't we add the omitempty annotation ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup we should - they aren't both required in the sense that the validation will both are not provided.

@dibyom dibyom deleted the feature/trigger-groups-implementation branch October 21, 2021 20:02
dibyom added a commit to dibyom/triggers that referenced this pull request Oct 22, 2021
Addresses comment: tektoncd#1232 (comment)

Signed-off-by: Dibyo Mukherjee <[email protected]>
dibyom added a commit to dibyom/triggers that referenced this pull request Oct 22, 2021
Addresses comment: tektoncd#1232 (comment)

Signed-off-by: Dibyo Mukherjee <[email protected]>
tekton-robot pushed a commit that referenced this pull request Oct 25, 2021
Addresses comment: #1232 (comment)

Signed-off-by: Dibyo Mukherjee <[email protected]>
dibyom added a commit to dibyom/triggers that referenced this pull request Nov 3, 2021
Addresses comment: tektoncd#1232 (comment)

Signed-off-by: Dibyo Mukherjee <[email protected]>
(cherry picked from commit 4a9db17)
tekton-robot pushed a commit that referenced this pull request Nov 3, 2021
Addresses comment: #1232 (comment)

Signed-off-by: Dibyo Mukherjee <[email protected]>
(cherry picked from commit 4a9db17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants