Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support skipping single task only #3176

Closed
wants to merge 1 commit into from
Closed

Support skipping single task only #3176

wants to merge 1 commit into from

Conversation

jerop
Copy link
Member

@jerop jerop commented Sep 8, 2020

Changes

When WhenExpressions evaluate to False, the guarded Task and
its branch (dependent Tasks) are skipped

A Task is dependent on and in the branch of another Task as specified
by ordering using runAfter or by resources using Results, Workspaces
and Resources

In some use cases, when WhenExpressions evaluate to False,
users need to skip the guarded Task only and allow ordering-dependent
Tasks to execute

When WhenExpressions evaluate to False, it is possible to allow for
execution of ordering-dependent Tasks as specified by runAfter using
the whenSkipped field by setting it to runBranch.

However, setting whenSkipped in Tasks without WhenExpressions
or Tasks with resource dependencies is invalid, and will cause
Pipeline validation errors. This ensures consistency in executing or
skipping subsequent tasks.

Further details in TEP

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

When  `WhenExpressions` evaluate to `False`, it is possible to allow
execution of ordering-dependent `Tasks` as specified by `runAfter`
using the `whenSkipped` field by setting it to `runBranch`

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 8, 2020
@jerop jerop changed the title Implement Skipping Conditions Beta: Implement Skipping Sep 8, 2020
@jerop
Copy link
Member Author

jerop commented Sep 8, 2020

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 8, 2020
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 82.0% 81.1% -0.9
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 97.5% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 90.3% 90.3% -0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 82.0% 81.1% -0.9
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 97.5% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 90.3% 90.3% -0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 82.0% 82.2% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 97.5% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 90.3% 90.3% -0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 82.0% 82.2% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 97.5% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 90.3% 90.3% -0.0

@jerop
Copy link
Member Author

jerop commented Sep 9, 2020

runAfter is meant to be used to specify ordering when there are no resource dependencies - https://github.com/tektoncd/pipeline/blob/master/docs/pipelines.md#using-the-runafter-parameter

however, it seems that Workspaces don't have a way to specify resource dependencies so they use runAfter, further detail in #3109

need to look into what this means for skipping ordering-dependent tasks as specified by runAfter

a potential solution could be introducing a field - similar to runAfter - for specifying resource dependencies such as Workspaces that don't use the from or string substitution syntax

@bobcatfish @sbwsg

/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2020
docs/pipelines.md Outdated Show resolved Hide resolved
@bobcatfish
Copy link
Collaborator

@jerop i think for now it's fine to treat runAfter as the same for all circumstances - however if you wanted to tackle #3109 before this that'd be cool too. basically i dont think either needs to wait on the other

this would only be a problem for a fairly specific use case:

  1. Someone has a workspace coming "from" another Task, e.g. task B needs workspace X from task A, and this is expressed using runAfter
  2. That person uses a when expression on task A, and sets continueAfterSkip: true

imo (2) is actually an error - and i think if you did the same thing with a result, we'd fail it on validation, is that right? So not having #3109 before doing this would mean that there is an error case we aren't able to catch with validation. Definitely it would be better to be able to catch this, but I don't feel like that needs to block this, what do you think?

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 82.0% 82.2% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 97.5% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 90.3% 90.1% -0.2

@jerop
Copy link
Member Author

jerop commented Sep 9, 2020

@jerop i think for now it's fine to treat runAfter as the same for all circumstances - however if you wanted to tackle #3109 before this that'd be cool too. basically i dont think either needs to wait on the other

this would only be a problem for a fairly specific use case:

  1. Someone has a workspace coming "from" another Task, e.g. task B needs workspace X from task A, and this is expressed using runAfter
  2. That person uses a when expression on task A, and sets continueAfterSkip: true

imo (2) is actually an error - and i think if you did the same thing with a result, we'd fail it on validation, is that right? So not having #3109 before doing this would mean that there is an error case we aren't able to catch with validation. Definitely it would be better to be able to catch this, but I don't feel like that needs to block this, what do you think?

@bobcatfish thank you for clarifying the use case for workspace + runAfter described in that issue -- agreed that's something we can tackle separately (assigned myself)

@jerop
Copy link
Member Author

jerop commented Sep 9, 2020

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2020
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 82.0% 82.2% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 97.5% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 90.3% 90.1% -0.2

@pritidesai
Copy link
Member

so if there's a task with WhenExpressions that evaluate to false and continueAfterSkip is set to true, and it has both ordering-dependent tasks and resource-dependent tasks, the ordering-dependent tasks will be executed while resource-dependent tasks will be skipped -- shown in this test case: https://github.com/tektoncd/pipeline/pull/3176/files#diff-f7c8532cfe79319c0fff711a4979a6d6R2204-R2210

Will have to be little more careful here. It sounds like inconsistent behavior for resource dependent task vs ordering dependent task. Also a task could have both runAfter and task result and would be skipped (with these changes) due to resource dependency.

The way finally task with resource dependency is being handled is that final task is at least attempted but would fail at the param validation since the task result does not exist. But when we add param level defaults for task results, that final task would be executed with the default value.

Unfortunately I dont have any ideas how to fix this inconsistency other than allowing to specify default along with task result:

spec:
 tasks:
  - name: release-env
     taskRef:
       Name: boskos-release
     params:
       - name: proj-name
         value: $(tasks.get-env.results.project)
         default: best-default-ever

The long term solution is to support schema validation for params.

@jerop
Copy link
Member Author

jerop commented Sep 9, 2020

thank you for the review @pritidesai 😊

Will have to be little more careful here. It sounds like inconsistent behavior for resource dependent task vs ordering dependent task.

does this refer to inconsistency in to how we handle the dependencies here compared to finally tasks or inconsistency in how we handle the different kinds of dependencies here by itself?

Also a task could have both runAfter and task result and would be skipped (with these changes) due to resource dependency.

continueAfterSkipped is invalid in tasks with resource dependencies so i don't think these changes would affect the skipping of such tasks

The way finally task with resource dependency is being handled is that final task is at least attempted but would fail at the param validation since the task result does not exist. But when we add param level defaults for task results, that final task would be executed with the default value.

Unfortunately I dont have any ideas how to fix this inconsistency other than allowing to specify default along with task result:

spec:
 tasks:
  - name: release-env
     taskRef:
       Name: boskos-release
     params:
       - name: proj-name
         value: $(tasks.get-env.results.project)
         default: best-default-ever

when expressions use params from the pipeline level and use task results directly (not through params in the task level) -- does this mean we'd have to support default task results in when expressions as well (in addition to params)? (an alternative could be default results in the result-producing task)

we proposed that setting continueAfterSkip on a guarded Task with resource dependencies is invalid so it fails upfront at pipeline validation

@jerop jerop marked this pull request as draft September 9, 2020 20:09
@jerop jerop marked this pull request as ready for review September 9, 2020 22:00
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 5, 2020
@tekton-robot tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 4, 2021
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 1, 2021
@jerop jerop removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 1, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 85.6% 85.8% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.7% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.3% 0.1

@jerop
Copy link
Member Author

jerop commented Mar 1, 2021

/retest

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 85.6% 85.8% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.7% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.3% 0.1

When  `WhenExpressions` evaluate to `False`, the `Task` and its branch
(of dependent `Tasks`) will be skipped by default while the rest of the
`Pipeline` will execute.

A `Task` branch is made up of dependent `Tasks`, where there are two
types of dependencies:
- _Resource dependency_: based on resources needed from parent `Task`,
which includes [`Results`](#using-results) and [`Resources`](#specifying-resources).
- _Ordering dependency_: based on [`runAfter`](#using-the-runafter-parameter)
which provides sequencing of `Tasks` when there may not be resource
dependencies.

In some use cases, when `WhenExpressions` evaluate to `False`,
users need to skip the guarded `Task` only and allow ordering-dependent
`Tasks` to execute.

In `Tasks` guarded using `WhenExpressions` and that have ordering
dependencies only, use `whenSkipped` to specify what happens when the
guarded `Task` is skipped.

The `whenSkipped` takes either `SkipBranch` or `RunBranch` policies.
To allow execution of ordering-dependent `Tasks`, set `whenSkipped` to
`RunBranch` in the guarded parent task.

If neither `SkipBranch` nor `RunBranch` is specified, the default one
is `SkipBranch`.

However, setting `whenSkipped` in `Tasks` without `WhenExpressions` or
`Tasks` with resource dependencies is invalid and will cause `Pipeline`
validation errors.
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 85.6% 85.8% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.7% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.3% 0.1

@tektoncd tektoncd deleted a comment from tekton-robot Mar 1, 2021
@jerop
Copy link
Member Author

jerop commented Mar 1, 2021

/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 1, 2021
@jerop jerop marked this pull request as ready for review March 1, 2021 22:15
@jerop jerop changed the title Conditions Beta: Implement Skipping Implement whenSkipped:runBranch/skipBranch Mar 2, 2021
@jerop jerop changed the title Implement whenSkipped:runBranch/skipBranch Add whenSkipped:runBranch/skipBranch Mar 2, 2021
@jerop jerop changed the title Add whenSkipped:runBranch/skipBranch Support skipping single task only Mar 3, 2021
@michaelsauter
Copy link

michaelsauter commented Mar 8, 2021

What's the status on this? Is this supposed to land in the next release?

FWIW, I ran into this PR because from reading the current docs, I assumed that when expressions would not actually skip the following tasks ... I like how the documentation is worded in this PR, much clearer now.

Base automatically changed from master to main March 11, 2021 15:28
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
internal/builder/v1beta1/pipeline.go 85.6% 85.8% 0.2
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.7% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.3% 0.1

@tekton-robot
Copy link
Collaborator

@jerop: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-tekton-pipeline-integration-tests 433219a link /test pull-tekton-pipeline-integration-tests
pull-tekton-pipeline-build-tests 433219a link /test pull-tekton-pipeline-build-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@tekton-robot
Copy link
Collaborator

@jerop: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 30, 2021
@jerop
Copy link
Member Author

jerop commented Jun 1, 2021

new proposal accepted: https://github.com/tektoncd/community/blob/main/teps/0059-skipping-strategies.md

@jerop jerop closed this Jun 1, 2021
@jerop jerop deleted the cbs branch June 11, 2022 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants