Skip to content

Commit

Permalink
TEP-0090: Matrix - Retries
Browse files Browse the repository at this point in the history
[TEP-0090: Matrix][tep-0090] proposed executing a `PipelineTask` in
parallel `TaskRuns` and `Runs` with substitutions from combinations
of `Parameters` in a `Matrix`.

Today, a matrixed `PipelineTask` that has retries will reattempt each
matrixed `TaskRun` when one of them fails. In this change, we fix this
issue such that each retry is completed for each matrixed `TaskRun`.
That is, each retry for each `TaskRun` is completed before it is
reattempted; failure in one matrixed `TaskRun` no longer affects retries
for other matrixed `TaskRuns` from the same `PipelineTask`.

[tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
  • Loading branch information
jerop committed Aug 11, 2022
1 parent 8e6265d commit a9b4665
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 1 deletion.
44 changes: 43 additions & 1 deletion docs/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ weight: 11
- [Fan Out](#fan-out)
- [`PipelineTasks` with `Tasks`](#pipelinetasks-with-tasks)
- [`PipelineTasks` with `Custom Tasks`](#pipelinetasks-with-custom-tasks)
- [Retries](#retries)

## Overview

Expand Down Expand Up @@ -521,6 +522,47 @@ status:
pipelineTaskName: platforms-and-browsers
```

## Retries

The `retries` field is used to specify the number of times a `PipelineTask` should be retried when its `TaskRun` or
`Run` fails, see the [documentation][retries] for further details. When a `PipelineTask` is fanned out using `Matrix`,
a given `TaskRun` or `Run` executed will be retried as much as the field in the `retries` field of the `PipelineTask`.

For example, the `PipelineTask` in this `PipelineRun` will be fanned out into three `TaskRuns` each of which will be
retried once:

```yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: matrixed-pr-with-retries-
spec:
pipelineSpec:
tasks:
- name: matrix-and-params
matrix:
- name: platform
value:
- linux
- mac
- windows
params:
- name: browser
value: chrome
retries: 1
taskSpec:
params:
- name: platform
- name: browser
steps:
- name: echo
image: alpine
script: |
echo "$(params.platform) and $(params.browser)"
exit 1
```

[cel]: https://github.com/tektoncd/experimental/tree/1609827ea81d05c8d00f8933c5c9d6150cd36989/cel
[pr-with-matrix]: ../examples/v1beta1/pipelineruns/alpha/pipelinerun-with-matrix.yaml
[pr-with-matrix-and-results]: ../examples/v1beta1/pipelineruns/alpha/pipelinerun-with-matrix-and-results.yaml
[pr-with-matrix-and-results]: ../examples/v1beta1/pipelineruns/alpha/pipelinerun-with-matrix-and-results.yaml
[retries]: pipelines.md#using-the-retries-field
3 changes: 3 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, para

tr, _ := c.taskRunLister.TaskRuns(pr.Namespace).Get(taskRunName)
if tr != nil {
if !tr.Status.GetCondition(apis.ConditionSucceeded).IsFalse() {
return tr, nil
}
// Don't modify the lister cache's copy.
tr = tr.DeepCopy()
// is a retry
Expand Down
Loading

0 comments on commit a9b4665

Please sign in to comment.