Skip to content

Commit 665a03b

Browse files
waveywavestekton-robot
authored andcommitted
feat: override task timeout in pipelineruns
Signed-off-by: Vibhav Bobade <[email protected]>
1 parent 490861a commit 665a03b

26 files changed

+859
-35
lines changed

config/300-crds/300-pipeline.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ spec:
349349
x-kubernetes-preserve-unknown-fields: true
350350
timeout:
351351
description: |-
352-
Time after which the TaskRun times out. Defaults to 1 hour.
352+
Duration after which the TaskRun times out. Defaults to 1 hour.
353353
Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
354354
type: string
355355
when:
@@ -794,7 +794,7 @@ spec:
794794
x-kubernetes-preserve-unknown-fields: true
795795
timeout:
796796
description: |-
797-
Time after which the TaskRun times out. Defaults to 1 hour.
797+
Duration after which the TaskRun times out. Defaults to 1 hour.
798798
Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
799799
type: string
800800
when:
@@ -1126,7 +1126,7 @@ spec:
11261126
x-kubernetes-preserve-unknown-fields: true
11271127
timeout:
11281128
description: |-
1129-
Time after which the TaskRun times out. Defaults to 1 hour.
1129+
Duration after which the TaskRun times out. Defaults to 1 hour.
11301130
Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
11311131
type: string
11321132
when:
@@ -1465,7 +1465,7 @@ spec:
14651465
x-kubernetes-preserve-unknown-fields: true
14661466
timeout:
14671467
description: |-
1468-
Time after which the TaskRun times out. Defaults to 1 hour.
1468+
Duration after which the TaskRun times out. Defaults to 1 hour.
14691469
Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
14701470
type: string
14711471
when:

config/300-crds/300-pipelinerun.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,11 @@ spec:
14191419
x-kubernetes-preserve-unknown-fields: true
14201420
taskServiceAccountName:
14211421
type: string
1422+
timeout:
1423+
description: |-
1424+
Duration after which the TaskRun times out.
1425+
Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
1426+
type: string
14221427
x-kubernetes-list-type: atomic
14231428
timeout:
14241429
description: |-
@@ -3901,6 +3906,13 @@ spec:
39013906
description: The name of the Step to override.
39023907
type: string
39033908
x-kubernetes-list-type: atomic
3909+
timeout:
3910+
description: |-
3911+
Duration after which the TaskRun times out. Overrides the timeout specified
3912+
on the Task's spec if specified. Takes lower precedence to PipelineRun's
3913+
`spec.timeouts.tasks`
3914+
Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
3915+
type: string
39043916
x-kubernetes-list-type: atomic
39053917
taskRunTemplate:
39063918
description: TaskRunTemplate represent template of taskrun

docs/pipeline-api.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,6 +3322,21 @@ Kubernetes core/v1.ResourceRequirements
33223322
<p>Compute resources to use for this TaskRun</p>
33233323
</td>
33243324
</tr>
3325+
<tr>
3326+
<td>
3327+
<code>timeout</code><br/>
3328+
<em>
3329+
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
3330+
Kubernetes meta/v1.Duration
3331+
</a>
3332+
</em>
3333+
</td>
3334+
<td>
3335+
<em>(Optional)</em>
3336+
<p>Time after which the TaskRun times out.
3337+
Refer Go&rsquo;s ParseDuration documentation for expected format: <a href="https://golang.org/pkg/time/#ParseDuration">https://golang.org/pkg/time/#ParseDuration</a></p>
3338+
</td>
3339+
</tr>
33253340
</tbody>
33263341
</table>
33273342
<h3 id="tekton.dev/v1.PipelineTaskRunTemplate">PipelineTaskRunTemplate

docs/pipelineruns.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ spec:
951951
podTemplate:
952952
nodeSelector:
953953
disktype: ssd
954+
timeout: "1h30m"
954955
```
955956
{{% /tab %}}
956957

@@ -968,12 +969,16 @@ spec:
968969
taskPodTemplate:
969970
nodeSelector:
970971
disktype: ssd
972+
timeout: "1h30m"
971973
```
972974
{{% /tab %}}
973975
{{< /tabs >}}
974976

975977
If used with this `Pipeline`, `build-task` will use the task specific `PodTemplate` (where `nodeSelector` has `disktype` equal to `ssd`)
976-
along with `securityContext` from the `pipelineRun.spec.podTemplate`.
978+
along with `securityContext` from the `pipelineRun.spec.podTemplate`. The task will also have a specific timeout of 1 hour and 30 minutes. This overrides any existing timeout already defined by the pipelineTask as well, though the specified `pipelineRun.spec.timeouts.tasks` will still take precedence.
979+
980+
For more details on timeout overrides, precedence rules, validation, and practical examples, see [Overriding Individual Task Timeouts](#overriding-individual-task-timeouts) in the failure timeout section.
981+
977982
`PipelineTaskRunSpec` may also contain `StepSpecs` and `SidecarSpecs`; see
978983
[Overriding `Task` `Steps` and `Sidecars`](./taskruns.md#overriding-task-steps-and-sidecars) for more information.
979984

@@ -1414,6 +1419,36 @@ The global default timeout is set to 60 minutes when you first install Tekton. Y
14141419
a different global default timeout value using the `default-timeout-minutes` field in
14151420
[`config/config-defaults.yaml`](./../config/config-defaults.yaml).
14161421

1422+
#### Overriding Individual Task Timeouts
1423+
1424+
You can use `taskRunSpecs` to override individual task timeouts at runtime without modifying the Pipeline definition.
1425+
1426+
**Timeout Precedence (highest to lowest):**
1427+
1. `taskRunSpecs[].timeout` - runtime override per task
1428+
2. `pipeline.spec.tasks[].timeout` - Pipeline spec timeout
1429+
3. `timeouts.tasks` or `timeouts.pipeline` - PipelineRun constraints
1430+
4. Global default timeout
1431+
1432+
```yaml
1433+
apiVersion: tekton.dev/v1
1434+
kind: PipelineRun
1435+
spec:
1436+
timeouts:
1437+
pipeline: "10m" # 3. PipelineRun constraint
1438+
pipelineSpec:
1439+
tasks:
1440+
- name: task-a
1441+
timeout: "8m" # 2. Pipeline spec timeout
1442+
taskSpec: { ... }
1443+
- name: task-b
1444+
taskSpec: { ... } # 4. Uses global default (60m)
1445+
taskRunSpecs:
1446+
- pipelineTaskName: task-a
1447+
timeout: "5m" # 1. Highest priority - overrides 8m Pipeline timeout
1448+
```
1449+
1450+
**Note:** `taskRunSpecs` timeouts cannot exceed pipeline-level constraints and will fail validation if they do.
1451+
14171452
Example timeouts usages are as follows:
14181453

14191454
Combination 1: Set the timeout for the entire `pipeline` and reserve a portion of it for `tasks`.

docs/pipelines.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,8 @@ format. For example, valid values are `1h30m`, `1h`, `1m`, and `60s`.
12061206
For example, if the `PipelineRun` sets `timeouts.pipeline = 1h` and the `Pipeline` sets `tasks[0].timeout = 3h`, the task will still timeout after `1h`.
12071207
See [`PipelineRun - Configuring a failure timeout`](pipelineruns.md#configuring-a-failure-timeout) for details.
12081208

1209+
**Note:** Task timeouts specified in the Pipeline can be overridden at runtime using the [`taskRunSpecs`](pipelineruns.md#overriding-individual-task-timeouts) field in the PipelineRun. This provides flexibility to adjust timeouts for specific execution contexts without modifying the Pipeline definition.
1210+
12091211
In the example below, the `build-the-image` `Task` is configured to time out after 90 seconds:
12101212

12111213
```yaml
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: tekton.dev/v1
2+
kind: Task
3+
metadata:
4+
name: sleep-task
5+
spec:
6+
steps:
7+
- name: sleep-long
8+
image: alpine:latest
9+
script: |
10+
#!/bin/sh
11+
sleep 10
12+
---
13+
apiVersion: tekton.dev/v1
14+
kind: Task
15+
metadata:
16+
name: verify-task
17+
spec:
18+
steps:
19+
- name: verify-completion
20+
image: alpine:latest
21+
script: |
22+
#!/bin/sh
23+
echo "- Pipeline task timeout: 60s (defined in pipeline spec)"
24+
echo "- TaskRunSpecs override: 20s (defined in pipelinerun spec)"
25+
echo "- Actual task duration: 10s (within 20s override timeout)"
26+
---
27+
apiVersion: tekton.dev/v1
28+
kind: Pipeline
29+
metadata:
30+
name: taskrun-timeout-override
31+
spec:
32+
tasks:
33+
- name: long-running-task
34+
taskRef:
35+
name: sleep-task
36+
kind: Task
37+
timeout: "60s" # pipeline task timeout (will be overridden to 20s)
38+
- name: verify-timeout
39+
taskRef:
40+
name: verify-task
41+
kind: Task
42+
runAfter: ["long-running-task"]
43+
---
44+
apiVersion: tekton.dev/v1
45+
kind: PipelineRun
46+
metadata:
47+
name: taskrun-timeout-override
48+
spec:
49+
pipelineRef:
50+
name: taskrun-timeout-override
51+
taskRunSpecs:
52+
- pipelineTaskName: long-running-task
53+
timeout: "20s" # 20s timeout (can't actually test with a timeout lesser than 10s else the task fails)

pkg/apis/pipeline/v1/openapi_generated.go

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/pipeline/v1/pipeline_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ type PipelineTask struct {
237237
// +listType=atomic
238238
Workspaces []WorkspacePipelineTaskBinding `json:"workspaces,omitempty"`
239239

240-
// Time after which the TaskRun times out. Defaults to 1 hour.
240+
// Duration after which the TaskRun times out. Defaults to 1 hour.
241241
// Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
242242
// +optional
243243
Timeout *metav1.Duration `json:"timeout,omitempty"`

pkg/apis/pipeline/v1/pipeline_validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) {
14151415
if err == nil {
14161416
t.Errorf("PipelineSpec.Validate() did not return error for invalid pipelineSpec")
14171417
}
1418-
if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" {
1418+
if d := cmp.Diff(tt.expectedError.Error(), err.Error()); d != "" {
14191419
t.Errorf("PipelineSpec.Validate() errors diff %s", diff.PrintWantGot(d))
14201420
}
14211421
})

pkg/apis/pipeline/v1/pipelinerun_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,13 @@ type PipelineTaskRunSpec struct {
656656

657657
// Compute resources to use for this TaskRun
658658
ComputeResources *corev1.ResourceRequirements `json:"computeResources,omitempty"`
659+
660+
// Duration after which the TaskRun times out. Overrides the timeout specified
661+
// on the Task's spec if specified. Takes lower precedence to PipelineRun's
662+
// `spec.timeouts.tasks`
663+
// Refer Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration
664+
// +optional
665+
Timeout *metav1.Duration `json:"timeout,omitempty"`
659666
}
660667

661668
// GetTaskRunSpec returns the task specific spec for a given
@@ -678,6 +685,7 @@ func (pr *PipelineRun) GetTaskRunSpec(pipelineTaskName string) PipelineTaskRunSp
678685
s.SidecarSpecs = task.SidecarSpecs
679686
s.Metadata = task.Metadata
680687
s.ComputeResources = task.ComputeResources
688+
s.Timeout = task.Timeout
681689
}
682690
}
683691
return s

0 commit comments

Comments
 (0)