From ab272bff43785a09f1fb2b161d37fe20d8a09161 Mon Sep 17 00:00:00 2001 From: Soule BA Date: Thu, 28 Jan 2021 22:22:37 +0100 Subject: [PATCH] Proposal to enable finally tasks to execute when a pipelinerun has reached timeout. Enable finally task to run when a pipeline times out. This implies a behavioral change, as finally tasks will run no matter what. Enable pipeline authors to specify a timeout field for finally tasks. In all normal run, that timeout is not needed and finally tasks execute after non-finallytasks. But in case of timed out pipeline, the finally task execution is bounded by the declared timeout. --- ...0047-finallytask-execution-post-timeout.md | 265 ++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 teps/0047-finallytask-execution-post-timeout.md diff --git a/teps/0047-finallytask-execution-post-timeout.md b/teps/0047-finallytask-execution-post-timeout.md new file mode 100644 index 000000000..6a00ee4b8 --- /dev/null +++ b/teps/0047-finallytask-execution-post-timeout.md @@ -0,0 +1,265 @@ +--- +status: proposed +title: Finally tasks execution post pipelinerun timeout +creation-date: '2021-01-26' +last-updated: '2021-01-26' +authors: +- '@souleb' +--- + +# TEP-0047: Finally tasks execution post pipelinerun timeout +--- + + + + + + + + + +- [# TEP-0047: Finally tasks execution post pipelinerun timeout](#-tep-0047-finally-tasks-execution-post-pipelinerun-timeout) +- [Summary](#summary) +- [Motivation](#motivation) + - [Goals](#goals) + - [Non-Goals](#non-goals) +- [Proposal](#proposal) +- [Test Plan](#test-plan) +- [Alternatives](#alternatives) + + +## Summary + + + +This TEP adresses issue [`#2980`](https://github.com/tektoncd/pipeline/issues/2989). + +The proposal is to enable finally tasks to execute when a pipelinerun has reached timeout. + +## Motivation + + + +The finally task [`design document`](https://docs.google.com/document/d/1lxpYQHppiWOxsn4arqbwAFDo4T0-LCqpNa6p-TJdHrw/edit#heading=h.w51ed6k2inef) list the following use cases : + +- Cleanup cluster resources after finishing (with success/failure) integration tests (Dogfooding Scenario) +- Update Pull Request with what happened overall in the pipeline (pipeline level) +- Report Test Results at the end of the test pipeline (Notifications Scenario) + +Unfortunately if a pipeline's execution reaches the defined timeout value, the pipelinerun stop and reports a failed status. + +Here is an example pipeline run with a finally task: + +```yaml +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: hello-world-pipeline-run-with-timeout +spec: + timeout: "0h0m60s" + pipelineSpec: + tasks: + - name: task1 + timeout: "0h0m30s" + taskSpec: + steps: + - name: hello + image: ubuntu + script: | + echo "Hello World!" + sleep 10 + finally: + - name: task2 + params: + - name: echoStatus + value: "$(tasks.task1.status)" + taskSpec: + params: + - name: echoStatus + steps: + - name: verify-status + image: ubuntu + script: | + if [ $(params.echoStatus) == "Succeeded" ] + then + echo " Hello World echoed successfully" + fi +``` + +The finally task runs after the task completion and both execute normally. + + +| NAME | TASK NAME | STARTED | DURATION | STATUS | +|----------------------------------------------------------------|------------------|----------------|------------|------------------------| +| ∙ hello-world-pipeline-run-with-timeout-task1-tp9dq | task1 | 17 seconds ago | 4 seconds | Succeeded | +| ∙ hello-world-pipeline-run-with-timeout-task2-zpzfm | task2 | 47 seconds ago | 30 seconds | Succeeded | +| | | | | | + + +Now if we change the task script in order to have it exceed its timeout (30s), we get the following status report: + +| NAME | TASK NAME | STARTED | DURATION | STATUS | +|-----------------------------------------------------|-----------|----------------|------------|------------------------| +| ∙ hello-world-pipeline-run-with-timeout-task2-44tsb | task2 | 8 seconds ago | 5 seconds | Succeeded | +| ∙ hello-world-pipeline-run-with-timeout-task1-wgcq7 | task1 | 38 seconds ago | 30 seconds | Failed(TaskRunTimeout) | +| | | | | | + + +The finally task still executes after the task failure. + + +Finally if we reduce the pipelinerun timeout to 10s, our status report shows: + +`PipelineRun "hello-world-pipeline-run-with-timeout" failed to finish within "10s" (TaskRun "hello-world-pipeline-run-with-timeout-task1-q7fw4" failed to finish within "30s")` + +| NAME | TASK NAME | STARTED | DURATION | STATUS | +|-----------------------------------------------------|-----------|---------------|------------|------------------------| +| ∙ hello-world-pipeline-run-with-timeout-task1-q7fw4 | task1 | 2 minutes ago | 30 seconds | Failed(TaskRunTimeout) | +| | | | | | +| | | | | | + + +The pipelinerun timeout take precedence over the task timeout. After 10s the task fails... And the finally task does not get the chance to execute. + + +For this reason, it is currently not possible to rely on Finally tasks for any of the aforementioned use cases. + +### Goals + + + +Enable the uses cases : + +- Cleanup cluster resources after finishing (with success/failure) integration tests (Dogfooding Scenario) +- Update Pull Request with what happened overall in the pipeline (pipeline level) +- Report Test Results at the end of the test pipeline (Notifications Scenario) + +When a pipelinerun times out. + +### Non-Goals + + + +## Proposal + + + +Enable finally task to run when a pipeline times out. This implies a behavioral change, as finally tasks will run no matter what. + +Enable pipeline authors to specify a timeout field for finally tasks. In all normal run, that timeout is not needed and finally tasks execute after non-finally tasks. But in case of timed out pipeline, the finally task execution is bounded by the declared timeout. + +```yaml +spec: + tasks: + - name: tests + taskRef: + Name: integration-test + finally: + timeout: "0h0m10s" + - name: cleanup-test + taskRef: + Name: cleanup +``` + +In order to keep older declaration working, we set the timeout field optional with a `default 20 minutes timeout`. + + +## Test Plan + + + +- Unit tests +- End-to-end tests +- Examples + + +## Alternatives + + + +We could add a new field to decide whether to permits finally tasks to run in case of timeout. \ No newline at end of file