Skip to content

Commit

Permalink
Only send cloud events when condition changes
Browse files Browse the repository at this point in the history
Change the logic for cloud events to be sent only if a change is
detected in the condition, specifically in state, message or reason.

Fixes #3336

Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
  • Loading branch information
afrittoli authored and tekton-robot committed Oct 7, 2020
1 parent 9611f3e commit 3d35b87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ retrieving those events using the `kubectl describe` command. Tekton can also em
When you [configure a sink](install.md#configuring-cloudevents-notifications), Tekton emits
events as described in the table below.

Tekton sends cloud events in a parallel routine to allow for retries without blocking the
reconciler. A routine is started every time the `Succeeded` condition changes - either state,
reason or message. Retries are sent using an exponential back-off strategy.
Because of retries, events are not guaranteed to be sent to the target sink in the order they happened.

Resource |Event |Event Type
:-------------|:-------:|:----------------------------------------------------------
`TaskRun` | `Started` | `dev.tekton.event.taskrun.started.v1`
Expand Down
9 changes: 6 additions & 3 deletions pkg/reconciler/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ func Emit(ctx context.Context, beforeCondition *apis.Condition, afterCondition *
sendKubernetesEvents(recorder, beforeCondition, afterCondition, object)

if sendCloudEvents {
err := cloudevent.SendCloudEventWithRetries(ctx, object)
if err != nil {
logger.Warnf("Failed to emit cloud events %v", err.Error())
// Only send events if the new condition represents a change
if !equality.Semantic.DeepEqual(beforeCondition, afterCondition) {
err := cloudevent.SendCloudEventWithRetries(ctx, object)
if err != nil {
logger.Warnf("Failed to emit cloud events %v", err.Error())
}
}
}
}
Expand Down

0 comments on commit 3d35b87

Please sign in to comment.