Skip to content

Commit c9e04e2

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 c9e04e2

File tree

2 files changed

+179
-42
lines changed

2 files changed

+179
-42
lines changed

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

Lines changed: 178 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,77 @@ 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+
default: squash
471+
- name: taskB
472+
runAfter:
473+
- "taskA"
474+
taskRef:
475+
name: demo-task
476+
params:
477+
- name: param1
478+
value: $(tasks.taskA.results.merge_status || "foobar")
479+
- name: param2
480+
value: $(tasks.taskA.results.branches || [foo, bar, baz])
481+
- name: param3
482+
value: $(tasks.taskA.results.images || {node="foo", gcloud="bar"})
483+
- name: taskC
484+
runAfter:
485+
- "taskA"
486+
taskRef:
487+
name: demo-task
488+
params:
489+
- name: param1
490+
value: $(tasks.taskA.results.merge_status)
491+
- name: param2
492+
value: $(tasks.taskA.results.branches || [foo, bar, baz])
493+
- name: param3
494+
value: $(tasks.taskA.results.images || {node="foo", gcloud="bar"})
495+
...
461496
```
462497

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.
498+
If the `Task` doesn't produces any result then it should fail. In order to
499+
continue with the execution of `Pipeline`, `onError: continue` should be added
500+
in the `PipelineTask` which we anticipate to fail and subsequent `Tasks`
501+
which are consuming the results produced by the previous `Task` should have a
502+
default value specified.
470503

471504
The proposed solution can be used to solve the above use cases as follows:
472505

@@ -491,7 +524,7 @@ spec:
491524
- name: build-image
492525
runAfter: [ "check-pr-content" ]
493526
when:
494-
- input: "$(tasks.check-pr-content.results.image-change)"
527+
- input: "$(tasks.check-pr-content.results.image-change || no)"
495528
operator: in
496529
values: ["yes"]
497530
taskRef:
@@ -554,9 +587,9 @@ spec:
554587
runAfter: [ "build-image" ]
555588
params:
556589
- name: trusted-image-name
557-
value: "$(tasks.build-trusted.results.image)"
590+
value: "$(tasks.build-trusted.results.image || "trusted")"
558591
- name: untrusted-image-name
559-
value: "$(tasks.build-untrusted.results.image)"
592+
value: "$(tasks.build-untrusted.results.image || "untrusted")"
560593
taskRef:
561594
name: propagate-image-name
562595
# pipeline result
@@ -586,7 +619,6 @@ spec:
586619
results:
587620
- name: check
588621
description: The result of the check, "passed" or "failed"
589-
default: "passed"
590622
steps:
591623
- name: check-name
592624
image: alpine
@@ -631,6 +663,7 @@ spec:
631663
description: The pullRequestNumber
632664
tasks:
633665
- name: check-name-match
666+
onError: continue
634667
taskRef:
635668
name: check-name-matches
636669
params:
@@ -640,7 +673,7 @@ spec:
640673
value: $(params.checkName)
641674
- name: clone-repo
642675
when:
643-
- input: $(tasks.check-name-match.results.check)
676+
- input: $(tasks.check-name-match.results.check || "failed")
644677
operator: in
645678
values: ["passed"]
646679
taskRef:
@@ -655,8 +688,12 @@ spec:
655688
...
656689
```
657690

691+
In the above example, if the value of parameter `checkName` is not passed,
692+
the `Task` is failed but in order to continue the execution of the `Pipeline`,
693+
we use the `onError: continue` flag and
694+
658695
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
696+
default value of `Result` will be produced `f` and Pipeline's execution will
660697
be continued. The only case when the execution of `Pipeline` is stopped when
661698
the wrong value of parameter `checkName` is passed.
662699

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

671708
## Alternatives
672709

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

675809
Allow `Results` to declare an optional field as `optional`. When a `Task` fails to
@@ -704,7 +838,7 @@ spec:
704838
```
705839

706840
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).
841+
produce `Results` as discussed in [tektoncd/pipeline#3497][tektoncd/pipeline#3497].
708842
It does not address the use cases for providing default `Results` that can be consumed in subsequent `Tasks`.
709843

710844

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

723857
* [Accessing Execution status of any DAG task from finally](https://github.com/tektoncd/community/blob/master/teps/0028-task-execution-status-at-runtime.md)
858+
859+
860+
[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)