Skip to content

Commit a07b496

Browse files
committed
[TEP-0048] Task Results without Results
This TEP is updated with the new proposed solution where we now specify the default value for results at the time where they are consumed. Signed-off-by: vinamra28 <jvinamra776@gmail.com>
1 parent 8bd4cb3 commit a07b496

2 files changed

Lines changed: 178 additions & 42 deletions

File tree

teps/0048-task-results-without-results.md

Lines changed: 177 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ authors:
44
- "@pritidesai"
55
- "@jerop"
66
- "@vinamra28"
7+
- "@bobcatfish"
78
creation-date: 2020-10-20
8-
last-updated: 2022-08-09
9-
status: implementable
9+
last-updated: 2023-02-13
10+
status: proposed
1011
---
1112

1213
# TEP-0048: Task Results without Results
@@ -27,6 +28,8 @@ status: implementable
2728
- [<code>Task</code> claiming to produce <code>Result</code> fails if it doesn't produces](#-claiming-to-produce--fails-if-it-doesnt-produces)
2829
- [Test Plan](#test-plan)
2930
- [Alternatives](#alternatives)
31+
- [Specifying Default Value during Runtime](#specifying-default-value-during-runtime)
32+
- [Specifying Default Value at the time of Authoring the Task](#specifying-default-value-at-the-time-of-authoring-the-task)
3033
- [Declaring Results as Optional](#declaring-results-as-optional)
3134
- [Future Work](#future-work)
3235
- [References](#references)
@@ -81,9 +84,9 @@ a missing task result. There are many reasons for a missing task result:
8184
* a `task` producing task result failed, no result available
8285
* a `task` producing result was skipped/disabled and no result generated
8386
* a `task` producing result did not generate that result even without any failure. We have a
84-
[bug report](https://github.com/tektoncd/pipeline/issues/3497) open to declare
87+
[bug report][tektoncd/pipeline#3497] open to declare
8588
such a task as failure. This reason might not hold true after issue
86-
[#3497]((https://github.com/tektoncd/pipeline/issues/3497)) is fixed.
89+
[#3497][tektoncd/pipeline#3497] is fixed.
8790

8891
Here are the major motivations for `pipeline` authors to design their pipelines with the missing task results:
8992

@@ -426,47 +429,76 @@ will fix the `Pipeline`.
426429

427430
## Proposal
428431

429-
We propose adding an optional field - `default` - to the `Result` specification in `Task`.
432+
We propose adding default value at the place where variable replacement
433+
happens and let consumer decide which value it wants to pick up. For example:
430434

431435
```yaml
432436
apiVersion: tekton.dev/v1beta1
433437
kind: Task
434438
metadata:
435439
name: task
436440
spec:
437-
results:
438-
- name: merge_status
439-
description: whether to rebase or squash
440-
type: string
441-
default: rebase
442-
- name: branches
443-
description: branches in the repository
444-
type: array
445-
default:
446-
- main
447-
- v1alpha1
448-
- v1beta1
449-
- v1
450-
- name: images
451-
type: object
452-
properties:
453-
node:
454-
type: string
455-
default: "node:latest"
456-
gcloud:
457-
type: string
458-
default: "gcloud:latest"
459441
steps:
460442
...
443+
results:
444+
- name: merge_status
445+
description: whether to rebase or squash
446+
type: string
447+
- name: branches
448+
description: branches in the repository
449+
type: array
450+
- name: images
451+
type: object
452+
properties:
453+
node:
454+
type: string
455+
gcloud:
456+
type: string
457+
---
458+
apiVersion: tekton.dev/v1beta1
459+
kind: Pipeline
460+
metadata:
461+
name: pipeline-with-defaults
462+
spec:
463+
tasks:
464+
- name: taskA
465+
onError: continue
466+
taskRef:
467+
name: task
468+
results:
469+
- name: merge_status
470+
- name: taskB
471+
runAfter:
472+
- "taskA"
473+
taskRef:
474+
name: demo-task
475+
params:
476+
- name: param1
477+
value: $(tasks.taskA.results.merge_status || "foobar")
478+
- name: param2
479+
value: $(tasks.taskA.results.branches || [foo, bar, baz])
480+
- name: param3
481+
value: $(tasks.taskA.results.images || {node="foo", gcloud="bar"})
482+
- name: taskC
483+
runAfter:
484+
- "taskA"
485+
taskRef:
486+
name: demo-task
487+
params:
488+
- name: param1
489+
value: $(tasks.taskA.results.merge_status)
490+
- name: param2
491+
value: $(tasks.taskA.results.branches || [foo, bar, baz])
492+
- name: param3
493+
value: $(tasks.taskA.results.images || {node="foo", gcloud="bar"})
494+
...
461495
```
462496

463-
464-
Adding a default value to `Results` is optional; validation of a `Task` doesn't
465-
fail if the default value isn't provided.
466-
467-
Adding a default value to a `Result` will guarantee that it will hold a value even
468-
if the `Task` fails to produce it. If a `Task` does not produce a `Result` that does not
469-
have a default value, then the `Task` should fail - see [tektoncd/pipeline#3497](https://github.com/tektoncd/pipeline/issues/3497) for further details.
497+
If the `Task` doesn't produce any result then it should fail. In order to
498+
continue with the execution of `Pipeline`, `onError: continue` should be added
499+
in the `PipelineTask` which we anticipate to fail and subsequent `Tasks`
500+
which are consuming the results produced by the previous `Task` should have a
501+
default value specified.
470502

471503
The proposed solution can be used to solve the above use cases as follows:
472504

@@ -491,7 +523,7 @@ spec:
491523
- name: build-image
492524
runAfter: [ "check-pr-content" ]
493525
when:
494-
- input: "$(tasks.check-pr-content.results.image-change)"
526+
- input: "$(tasks.check-pr-content.results.image-change || no)"
495527
operator: in
496528
values: ["yes"]
497529
taskRef:
@@ -554,9 +586,9 @@ spec:
554586
runAfter: [ "build-image" ]
555587
params:
556588
- name: trusted-image-name
557-
value: "$(tasks.build-trusted.results.image)"
589+
value: "$(tasks.build-trusted.results.image || "trusted")"
558590
- name: untrusted-image-name
559-
value: "$(tasks.build-untrusted.results.image)"
591+
value: "$(tasks.build-untrusted.results.image || "untrusted")"
560592
taskRef:
561593
name: propagate-image-name
562594
# pipeline result
@@ -586,7 +618,6 @@ spec:
586618
results:
587619
- name: check
588620
description: The result of the check, "passed" or "failed"
589-
default: "passed"
590621
steps:
591622
- name: check-name
592623
image: alpine
@@ -631,6 +662,7 @@ spec:
631662
description: The pullRequestNumber
632663
tasks:
633664
- name: check-name-match
665+
onError: continue
634666
taskRef:
635667
name: check-name-matches
636668
params:
@@ -640,7 +672,7 @@ spec:
640672
value: $(params.checkName)
641673
- name: clone-repo
642674
when:
643-
- input: $(tasks.check-name-match.results.check)
675+
- input: $(tasks.check-name-match.results.check || "failed")
644676
operator: in
645677
values: ["passed"]
646678
taskRef:
@@ -655,8 +687,12 @@ spec:
655687
...
656688
```
657689

690+
In the above example, if the value of parameter `checkName` is not passed,
691+
the `Task` is failed but in order to continue the execution of the `Pipeline`,
692+
we use the `onError: continue` flag and
693+
658694
In the above example, even if the value of parameter `checkName` is not passed,
659-
default value of `Result` will be produced `passed` and Pipeline's execution will
695+
default value of `Result` will be produced `failed` and Pipeline's execution will
660696
be continued. The only case when the execution of `Pipeline` is stopped when
661697
the wrong value of parameter `checkName` is passed.
662698

@@ -670,6 +706,103 @@ Having default results defined in check-name-matches Task will fix the Pipeline.
670706

671707
## Alternatives
672708

709+
### Specifying Default Value during Runtime
710+
711+
Adding an optional field - `default` for a `Result` which can be specified
712+
during runtime, i.e., in `TaskRun` or `Pipeline` for a `Task` or in `PipelineRun` for a `Pipeline`.
713+
714+
```yaml
715+
apiVersion: tekton.dev/v1beta1
716+
kind: Task
717+
metadata:
718+
name: task
719+
spec:
720+
results:
721+
- name: merge_status
722+
description: whether to rebase or squash
723+
type: string
724+
- name: branches
725+
description: branches in the repository
726+
type: array
727+
- name: images
728+
type: object
729+
properties:
730+
node:
731+
type: string
732+
gcloud:
733+
type: string
734+
steps:
735+
...
736+
---
737+
apiVersion: tekton.dev/v1beta1
738+
kind: TaskRun
739+
metadata:
740+
name: task
741+
spec:
742+
taskRef:
743+
name: task
744+
results:
745+
- name: merge_status
746+
default: rebase
747+
...
748+
```
749+
750+
Passing the default value for the `Result` at runtime is optional; validation
751+
of `TaskRun` or `Pipeline` or `PipelineRun` doesn't fail if the value isn't provided.
752+
753+
Adding a default value to `Results` is optional; validation of a `Task` doesn't
754+
fail if the default value isn't provided.
755+
756+
Adding a default value to a `Result` will guarantee that it will hold a value even
757+
if the `Task` fails to produce it. If a `Task` does not produce a `Result` that does not
758+
have a default value, then the `Task` should fail - see [tektoncd/pipeline#3497][tektoncd/pipeline#3497] for further details.
759+
760+
Values specified in `TaskRun` or `Pipeline` should be overwritten by declaring
761+
`Task` itself, if `Task` declares a `Result` then it should be considered as
762+
the final value for that result.
763+
764+
### Specifying Default Value at the time of Authoring the Task
765+
766+
Allow `Results` to declare an optional field as `default`. When a `Task` fails to
767+
produce a `Result` but has a default value specified, then the `Task` does not fail. When a `Task` fails
768+
to produce a `Result` that doesn't have any default value specified, then then the `Task` will fail.
769+
770+
```yaml
771+
apiVersion: tekton.dev/v1beta1
772+
kind: Task
773+
metadata:
774+
name: task
775+
spec:
776+
results:
777+
- name: merge_status
778+
description: whether to rebase or squash
779+
type: string
780+
default: "rebase"
781+
- name: branches
782+
description: branches in the repository
783+
type: array
784+
default:
785+
- "foo"
786+
- "bar"
787+
- name: images
788+
type: object
789+
properties:
790+
node:
791+
type: string
792+
gcloud:
793+
type: string
794+
default:
795+
node: "16"
796+
gcloud: "true"
797+
steps:
798+
...
799+
```
800+
801+
This solution only solves the issue of `Tasks` not failing when they
802+
don't produce `Results` as discussed in [tektoncd/pipeline#3497][tektoncd/pipeline#3497].
803+
However, it does not addressed the use case where an user can
804+
have different default values at runtime based on their `Pipeline`.
805+
673806
### Declaring Results as Optional
674807

675808
Allow `Results` to declare an optional field as `optional`. When a `Task` fails to
@@ -704,7 +837,7 @@ spec:
704837
```
705838

706839
However, this solution only solves the issue of `Tasks` not failing when they don't
707-
produce `Results` as discussed in [tektoncd/pipeline#3497](https://github.com/tektoncd/pipeline/issues/3497).
840+
produce `Results` as discussed in [tektoncd/pipeline#3497][tektoncd/pipeline#3497].
708841
It does not address the use cases for providing default `Results` that can be consumed in subsequent `Tasks`.
709842

710843

@@ -721,3 +854,6 @@ Determine if we need default `Results` declared at runtime in the future, and ho
721854
* [Issue reported - "when" expressions do not match user expectations](https://github.com/tektoncd/pipeline/issues/3345)
722855

723856
* [Accessing Execution status of any DAG task from finally](https://github.com/tektoncd/community/blob/master/teps/0028-task-execution-status-at-runtime.md)
857+
858+
859+
[tektoncd/pipeline#3497]: https://github.com/tektoncd/pipeline/issues/3497

teps/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This is the complete list of Tekton TEPs:
4848
|[TEP-0045](0045-whenexpressions-in-finally-tasks.md) | WhenExpressions in Finally Tasks | implemented | 2021-06-03 |
4949
|[TEP-0046](0046-finallytask-execution-post-timeout.md) | Finally tasks execution post pipelinerun timeout | implemented | 2021-12-14 |
5050
|[TEP-0047](0047-pipeline-task-display-name.md) | Pipeline Task Display Name | implementable | 2022-01-04 |
51-
|[TEP-0048](0048-task-results-without-results.md) | Task Results without Results | implementable | 2022-08-09 |
51+
|[TEP-0048](0048-task-results-without-results.md) | Task Results without Results | proposed | 2022-02-13 |
5252
|[TEP-0049](0049-aggregate-status-of-dag-tasks.md) | Aggregate Status of DAG Tasks | implemented | 2021-06-03 |
5353
|[TEP-0050](0050-ignore-task-failures.md) | Ignore Task Failures | implementable | 2022-09-16 |
5454
|[TEP-0051](0051-ppc64le-architecture-support.md) | ppc64le Support | proposed | 2021-01-28 |

0 commit comments

Comments
 (0)