|
| 1 | +--- |
| 2 | +status: implementable |
| 3 | +title: Pipeline fail-fast |
| 4 | +creation-date: '2024-08-17' |
| 5 | +last-updated: '2024-08-17' |
| 6 | +authors: |
| 7 | +- '@chengjoey' |
| 8 | +--- |
| 9 | + |
| 10 | +# TEP-0158: Pipeline fail-fast |
| 11 | + |
| 12 | +<!-- toc --> |
| 13 | +- [Summary](#summary) |
| 14 | +- [Motivation](#motivation) |
| 15 | + * [Goals](#goals) |
| 16 | + * [use-cases](#use-cases) |
| 17 | +- [Proposal](#proposal) |
| 18 | + * [failFast](#failfast) |
| 19 | + * [config-defaults](#config-defaults) |
| 20 | + * [PipelineRun](#pipelinerun) |
| 21 | + * [Pipeline](#pipeline) |
| 22 | +- [Design Evaluation](#design-evaluation) |
| 23 | + * [Priority](#priority) |
| 24 | + * [Performance](#performance) |
| 25 | +- [References](#references) |
| 26 | +<!-- /toc --> |
| 27 | + |
| 28 | + |
| 29 | +## Summary |
| 30 | + |
| 31 | +This proposal is to support stopping the execution of the Pipeline immediately when a Task in the Pipeline failed. |
| 32 | +Because there may be multiple parallel tasks in the pipeline, when one task fails, |
| 33 | +The final status of the pipeline is Failed, but other tasks may still be executed, |
| 34 | +which will waste resources. Therefore, we need a mechanism to support the |
| 35 | +immediate stop of pipeline execution when a task failed. |
| 36 | + |
| 37 | +## Motivation |
| 38 | + |
| 39 | +When a Task in a Pipeline fails, the Pipeline status may eventually change to Failed, but other parallel Tasks continue to execute. |
| 40 | +When the final Pipeline status is Failed, There is a high probability that users will create a new Pipeline execution, |
| 41 | +because in many cases they hope that the final Pipeline status will be Success. Therefore, |
| 42 | +in this case, it is necessary to stop the Pipeline execution as soon as possible. The fail-fast mechanism can |
| 43 | +reduce the waste of resources on the one hand, and on the other hand, |
| 44 | +it can also let users know the execution results of the Pipeline as soon as possible. |
| 45 | + |
| 46 | +### Goals |
| 47 | + |
| 48 | +- Support canceling the execution of the Pipeline immediately when a Task in the Pipeline failed. |
| 49 | + |
| 50 | +### use-cases |
| 51 | + |
| 52 | +Take the following pipeline as an example. When `fail-task` fails to execute, |
| 53 | +the parallel `success1` and `success2`Tasks will exit execution. |
| 54 | +The status of PipelineRun is `Failed`, the status of `fail-task` is `Failed`, |
| 55 | +and the status of `success1` and `success2` are `RunCancelled`. |
| 56 | + |
| 57 | +```yaml |
| 58 | +apiVersion: tekton.dev/v1 |
| 59 | +kind: PipelineRun |
| 60 | +metadata: |
| 61 | + name: pipeline-run |
| 62 | +spec: |
| 63 | + failFast: "true" |
| 64 | + pipelineSpec: |
| 65 | + tasks: |
| 66 | + - name: fail-task |
| 67 | + taskSpec: |
| 68 | + steps: |
| 69 | + - name: fail-task |
| 70 | + image: busybox |
| 71 | + command: ["/bin/sh", "-c"] |
| 72 | + args: |
| 73 | + - exit 1 |
| 74 | + - name: success1 |
| 75 | + taskSpec: |
| 76 | + steps: |
| 77 | + - name: success1 |
| 78 | + image: busybox |
| 79 | + command: ["/bin/sh", "-c"] |
| 80 | + args: |
| 81 | + - sleep 360 |
| 82 | + - name: success2 |
| 83 | + taskSpec: |
| 84 | + steps: |
| 85 | + - name: success2 |
| 86 | + image: busybox |
| 87 | + command: ["/bin/sh", "-c"] |
| 88 | + args: |
| 89 | + - sleep 360 |
| 90 | +``` |
| 91 | +
|
| 92 | +## Proposal |
| 93 | +
|
| 94 | +### failFast |
| 95 | +
|
| 96 | +The `failFast` property is of string type and supports the following values: |
| 97 | +1. `true`: When a Task in the Pipeline fails, the Pipeline execution is stopped immediately. |
| 98 | +2. `false`: This is consistent with the current behavior. When a Task in a Pipeline fails, the Pipeline status changes to Failed, but other Tasks continue to execute. |
| 99 | + |
| 100 | +### config-defaults |
| 101 | + |
| 102 | +Add the `default-fail-fast` field in `config-defaults` to set the default fail-fast attribute for all Pipelines. |
| 103 | + |
| 104 | +```yaml |
| 105 | +apiVersion: v1 |
| 106 | +kind: ConfigMap |
| 107 | +metadata: |
| 108 | + name: config-defaults |
| 109 | + namespace: tekton-pipelines |
| 110 | +data: |
| 111 | + # Default fail-fast attribute for all Pipelines |
| 112 | + default-fail-fast: "true" |
| 113 | +``` |
| 114 | + |
| 115 | +### PipelineRun |
| 116 | + |
| 117 | +Add the `failFast` field in PipelineRun to set the fail-fast property of the PipelineRun at runtime. |
| 118 | + |
| 119 | +```yaml |
| 120 | +apiVersion: tekton.dev/v1 |
| 121 | +kind: PipelineRun |
| 122 | +metadata: |
| 123 | + name: pipeline-run |
| 124 | +spec: |
| 125 | + failFast: "true" |
| 126 | + pipelineSpec: |
| 127 | + ... |
| 128 | +``` |
| 129 | + |
| 130 | +### Pipeline |
| 131 | + |
| 132 | +Add the `failFast` field in Pipeline to set the fail-fast property of Pipeline. |
| 133 | + |
| 134 | +```yaml |
| 135 | +apiVersion: tekton.dev/v1 |
| 136 | +kind: Pipeline |
| 137 | +metadata: |
| 138 | + name: "demo.pipeline" |
| 139 | +spec: |
| 140 | + failFast: "true" |
| 141 | + tasks: |
| 142 | + ... |
| 143 | +``` |
| 144 | + |
| 145 | +## Design Evaluation |
| 146 | + |
| 147 | +### Priority |
| 148 | + |
| 149 | +The `failFast` priority is:PipelineRun > Pipeline > config-defaults |
| 150 | + |
| 151 | +### Performance |
| 152 | + |
| 153 | +PipelineRun status is `Failed`, failed Task status is `Failed`, and other parallel Task status is `RunCancelled`. |
| 154 | +When a Task fails, the Cancel event is triggered to cancel the execution of PipelineRun. |
| 155 | + |
| 156 | +## References |
| 157 | + |
| 158 | +* Implementation Pull Requests: |
| 159 | + * [Tekton Pipelines PR #7987 - support fail-fast for PipelineRun][pr-7987] |
| 160 | +* [Tekton Pipelines Issue #7880][issue-7880] |
0 commit comments