Skip to content

Commit

Permalink
Finish setting up events for pipeline runs
Browse files Browse the repository at this point in the history
Add the start events for pipelineruns. Cleanup a bit of dead code
where an event was generated but it's not used anymore.
  • Loading branch information
afrittoli authored and tekton-robot committed Jun 30, 2020
1 parent 1a90647 commit c7a60b8
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 26 deletions.
12 changes: 10 additions & 2 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ No events are emitted for `Conditions` today (https://github.com/tektoncd/pipeli
successfully, including post-steps injected by Tekton.
- `Failed`: this is triggered if the `TaskRun` is completed, but not successfully.
Causes of failure may be: one the steps failed, the `TaskRun` was cancelled or
the `TaskRun` timed out.
the `TaskRun` timed out. `Failed` events are also triggered in case the `TaskRun`
cannot be executed at all because of validation issues.

## PipelineRuns

`PipelineRun` events are generated for the following `Reasons`:

- `Started`: this is triggered the first time the `PipelineRun` is picked by the
reconciler from its work queue, so it only happens if web-hook validation was
successful. Note that this event does not imply that a step started executing,
as pipeline, task and bound resource validation must be successful first.
- `Running`: this is triggered when the `PipelineRun` passes validation and
actually starts running.
- `Succeeded`: this is triggered once all `Tasks` reachable via the DAG are
executed successfully.
- `Failed`: this is triggered if the `PipelineRun` is completed, but not
successfully. Causes of failure may be: one the `Tasks` failed or the
`PipelineRun` was cancelled.
`PipelineRun` was cancelled or timed out. `Failed` events are also triggered
in case the `PipelineRun` cannot be executed at all because of validation issues.
17 changes: 10 additions & 7 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, pr *v1beta1.PipelineRun)
}
// start goroutine to track pipelinerun timeout only startTime is not set
go c.timeoutHandler.WaitPipelineRun(pr, pr.Status.StartTime)
// Emit events. During the first reconcile the status of the PipelineRun may change twice
// from not Started to Started and then to Running, so we need to sent the event here
// and at the end of 'Reconcile' again.
// We also want to send the "Started" event as soon as possible for anyone who may be waiting
// on the event to perform user facing initialisations, such has reset a CI check status
afterCondition := pr.Status.GetCondition(apis.ConditionSucceeded)
events.Emit(controller.GetEventRecorder(ctx), nil, afterCondition, pr)

// We already sent an event for start, so update `before` with the current status
before = pr.Status.GetCondition(apis.ConditionSucceeded)
}

if pr.IsDone() {
Expand Down Expand Up @@ -243,7 +253,6 @@ func (c *Reconciler) updatePipelineResults(ctx context.Context, pr *v1beta1.Pipe

func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) error {
logger := logging.FromContext(ctx)
recorder := controller.GetEventRecorder(ctx)
// We may be reading a version of the object that was stored at an older version
// and may not have had all of the assumed default specified.
pr.SetDefaults(contexts.WithUpgradeViaDefaulting(ctx))
Expand Down Expand Up @@ -407,12 +416,6 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err
return controller.NewPermanentError(err)
}

if pipelineState.IsDone() && pr.IsDone() {
c.timeoutHandler.Release(pr)
recorder.Event(pr, corev1.EventTypeNormal, v1beta1.PipelineRunReasonSuccessful.String(), "PipelineRun completed successfully.")
return nil
}

for _, rprt := range pipelineState {
err := taskrun.ValidateResolvedTaskResources(rprt.PipelineTask.Params, rprt.ResolvedTaskResources)
if err != nil {
Expand Down
Loading

0 comments on commit c7a60b8

Please sign in to comment.