-
Notifications
You must be signed in to change notification settings - Fork 426
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
Add kubernetes based events for triggers #1222
Conversation
The following is the coverage report on the affected files.
|
/cc @vdemeester |
FWIW, I'd caution against sending events for successful reconciliation and even for things that are non-terminal failures. This particular example emits 15 events in 78sec. Creating events can be a problem in couple of scenarios:
In both cases there might be problems with the controller getting ratelimited due to large number of events and hilarity will ensue. We ran into this in Knative and just sharing our experience. In the end we ended up dialing back the number of events we emit because it ended up creating problems. |
@savitaashture Based on #649, we should emit events when we trigger a resource successfully. This code should go inside EventListener's sink, not reconciliation. |
a023c6e
to
af49882
Compare
The following is the coverage report on the affected files.
|
af49882
to
f7528ee
Compare
The following is the coverage report on the affected files.
|
config/200-clusterrole.yaml
Outdated
@@ -85,6 +85,9 @@ rules: | |||
resources: ["podsecuritypolicies"] | |||
resourceNames: ["tekton-triggers"] | |||
verbs: ["use"] | |||
- apiGroups: [""] | |||
resources: ["events"] | |||
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if here and below we need all these permissions? Seems like create would suffice because we only emit events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes only create is required
Thanks for the heads up 👍
f7528ee
to
66986be
Compare
The following is the coverage report on the affected files.
|
/test pull-tekton-triggers-integration-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @savitaashture
My main comment is around this PR and #1259 - I think we should be consistent in where and how we are emitting the event. As well as be consistent on the type of events that we are emitting (though the exact contents might be different).
@@ -261,6 +261,12 @@ func (els *EventListenerStatus) SetConditionsForDynamicObjects(conditions v1beta | |||
Message: cond.Message, | |||
}) | |||
} | |||
|
|||
els.SetCondition(&apis.Condition{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why do we need this in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added as part of this PR because EL for Knative when succeed was not displaying any messages so added this change as part of this PR itself
pkg/reconciler/events/event.go
Outdated
) | ||
|
||
const ( | ||
// EventReasonSucceded is the reason set for events about successful completion of EventListener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to make sure the event reasons/types here are the same as the one in #1259?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and used similar constant from #1259 PR
pkg/sink/sink.go
Outdated
func (r Sink) emitEvents(ctx context.Context, el *triggersv1.EventListener, err error) { | ||
var afterCondition *apis.Condition | ||
if el != nil { | ||
afterCondition = el.Status.GetCondition(apis.ConditionReady) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should send the apis.ConditionReady
as the message for the event. Maybe we can try to be consistent with the cloudevents PR here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with el.Status.GetCondition(apis.ConditionReady)
not sending message to event instead we are getting el Status
pkg/sink/sink.go
Outdated
@@ -111,6 +123,7 @@ func (r Sink) HandleEvent(response http.ResponseWriter, request *http.Request) { | |||
log.Errorf("Error reading event body: %s", err) | |||
r.recordCountMetrics(failTag) | |||
response.WriteHeader(http.StatusInternalServerError) | |||
r.emitEvents(r.ContextForEvents, el, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be co-ordinated with #1259 as well - can we have a single r.EmitEvents
that sends both K8sEvents and CloudEvents (if enabled).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup i agree but i think we can do that once PRs merge
66986be
to
829bce4
Compare
The following is the coverage report on the affected files.
|
829bce4
to
91572be
Compare
The following is the coverage report on the affected files.
|
91572be
to
8bfc4e1
Compare
The following is the coverage report on the affected files.
|
@@ -91,17 +95,40 @@ type Response struct { | |||
ErrorMessage string `json:"errorMessage,omitempty"` | |||
} | |||
|
|||
func (r Sink) emitEvents(recorder record.EventRecorder, el *triggersv1.EventListener, err error) { | |||
afterCondition := el.Status.GetCondition(apis.ConditionReady) | |||
if el.Annotations[events.EnableEventListenerEvents] == "true" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds good. This should be an option in the config-features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dibyom do you mean we no need to take from eventlistener annotation instead we should depend on config-features
cm ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad. I missed that this was an annotation. Just an annotation is fine for now as long as we document it.
@@ -91,17 +95,40 @@ type Response struct { | |||
ErrorMessage string `json:"errorMessage,omitempty"` | |||
} | |||
|
|||
func (r Sink) emitEvents(recorder record.EventRecorder, el *triggersv1.EventListener, err error) { | |||
afterCondition := el.Status.GetCondition(apis.ConditionReady) | |||
if el.Annotations[events.EnableEventListenerEvents] == "true" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds good. This should be an option in the config-features.
pkg/sink/sink.go
Outdated
events.EnableEventListenerEvents: "true", | ||
}}} | ||
|
||
r.emitEvents(r.EventRecorder, &elTemp, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean that we will always emit an event due to elTemp
always setting the annotation to true? i.e. the actual EL could have it set of false but due to elTemp
defaulting to true, we are still emitting one event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because from this operation
el, err := r.EventListenerLister.EventListeners(r.EventListenerNamespace).Get(r.EventListenerName)
there could be chances of error while doing Get
So added elTemp so that get operation failure captured
pkg/reconciler/events/event.go
Outdated
EnableEventListenerEvents = "enable-eventlistener-events" | ||
// TriggerProcessingStarted is sent for Sink triggers received which | ||
// are being processed | ||
TriggerProcessingStartedV1 = "triggers.tekton.eventlistener.triggerprocessing.started.v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad that this is consistent with cloudevents but I had a comment that those names should be similar to the ones for Pipelines - see #1259 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated 👍
pkg/reconciler/events/event.go
Outdated
sendKubernetesEvents(recorder, afterCondition, object, err) | ||
} | ||
|
||
func sendKubernetesEvents(c record.EventRecorder, afterCondition *apis.Condition, object runtime.Object, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure if we need to rely on the status of the EventListener for emitting events in Triggers - if the EL is not ready, we are probably not going to receive the event at all i.e. the server is not up or something.
IMO it will be clearer emitEvents just sends the eventType (Successful, Failed etc.) as a param instead of the afterCondition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had a scenario with custom-resource
example as part of 0.16.0
Triggers release we had an issue #1219 related to metadata.resourceVersion
as part of Knative and because of that EL status was not True but pods were up and running so that is the reason i considered this way of using EL status in order to cover such scenarios also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But agree with you that the current PR focuses on events for Trigger process so we no need to consider eventlistener status instead we can send the type as you suggested
I have updated PR PTAL
8bfc4e1
to
eb8e26e
Compare
The following is the coverage report on the affected files.
|
eb8e26e
to
7317448
Compare
The following is the coverage report on the affected files.
|
@@ -3,6 +3,8 @@ apiVersion: triggers.tekton.dev/v1alpha1 | |||
kind: EventListener | |||
metadata: | |||
name: github-listener | |||
annotations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to change this in our examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not needed but just as an example for emitting event added annotation
Reverted back for both v1alpha1
and v1beta1
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dibyom, vdemeester 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 |
Few small nits, but otherwise good to go! |
7317448
to
e57049a
Compare
The following is the coverage report on the affected files.
|
e57049a
to
89ecb1b
Compare
The following is the coverage report on the affected files.
|
/test pull-tekton-triggers-integration-tests |
2 similar comments
/test pull-tekton-triggers-integration-tests |
/test pull-tekton-triggers-integration-tests |
@dibyom I have addressed all review comments PTAL |
/lgtm |
Changes
This PR adds changes to display k8s events for EventListener Pod when http request reaches to EL
/cc @dibyom @khrm
Addresses #649
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Release Notes