Skip to content

Conversation

@rafalbigaj
Copy link
Contributor

@rafalbigaj rafalbigaj commented May 5, 2021

The implementation of TEP-0058: Graceful Pipeline Run Termination.

The new spec.Status values:

  • StoppedRunFinally - To "stop" (i.e. let the tasks complete, then execute finally tasks) a Pipeline
  • CancelledRunFinally - To "cancel" (i.e. interrupt any executing non finally tasks, then execute finally tasks)
  • Cancelled - Same as today's PipelineRunCancelled - i.e. interrupt any executing tasks without running finally tasks

PipelineRunCancelled is deprecated (replaced by Cancelled)

Changes

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in or deleted (only if no user facing changes)

Release Notes

# The new PipelineRun spec statuses have been added to control the way who a PipelineRun is being canceled or stopped.

- "StoppedRunFinally" - To stop (i.e. let the tasks complete, then execute finally tasks) a PipelineRun
- "CancelledRunFinally" - To cancel (i.e. interrupt any executing non finally tasks, then execute finally tasks)
- "Cancelled" - replaces today's "PipelineRunCancelled" - i.e. interrupt any executing tasks without running finally tasks

Support for existing statuses has been left unchanged.

The status "PipelineRunCancelled" is deprecated and replaced by "Cancelled" (it would be removed in v1).

The new states are released as alpha API features.

[1] https://github.com/tektoncd/community/blob/main/teps/0058-graceful-pipeline-run-termination.md

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 5, 2021
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 5, 2021
@tekton-robot
Copy link
Collaborator

Hi @rafalbigaj. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@vdemeester
Copy link
Member

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 5, 2021
@vdemeester
Copy link
Member

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label May 5, 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% 84.7% -1.0
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 75.8% 73.5% -2.2
pkg/apis/pipeline/v1beta1/pipelinerun_validation.go 100.0% 97.1% -2.9
pkg/reconciler/pipelinerun/cancel.go 84.0% 81.0% -3.0
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.8% -0.1
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 69.8% 68.8% -1.1

return errs
}

func validateSpecStatus(status PipelineRunSpecStatus) *apis.FieldError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to update the test function

func TestPipelineRun_Invalid(t *testing.T) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also guard validating the new fields with the feature gate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

pipelineRun: &v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{Name: "test-pipeline-run-cancelled"},
Spec: v1beta1.PipelineRunSpec{
Status: v1beta1.PipelineRunSpecStatusCancelledDeprecated,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a test with the non deprecated stopping and cancelling fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was added to cover deprecated status name (PipelineRunCancelled). The already existing ones cover the new status name (Cancelled).

@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 6, 2021
@rafalbigaj
Copy link
Contributor Author

/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% 84.7% -1.0
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 75.8% 73.5% -2.2
pkg/reconciler/pipelinerun/cancel.go 84.0% 88.1% 4.1
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 84.0% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 69.8% 68.4% -1.4

@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% 84.2% -1.5
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 75.8% 73.5% -2.2
pkg/reconciler/pipelinerun/cancel.go 84.0% 88.1% 4.1
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 84.0% 0.2
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 71.7% 70.3% -1.4

@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% 84.2% -1.5
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 75.8% 73.5% -2.2
pkg/reconciler/pipelinerun/cancel.go 84.0% 88.1% 4.1
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 84.0% 0.2
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 71.7% 70.3% -1.4

@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% 84.2% -1.5
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 75.8% 73.5% -2.2
pkg/reconciler/pipelinerun/cancel.go 84.0% 88.1% 4.1
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 84.0% 0.2
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 71.7% 70.3% -1.4

@rafalbigaj
Copy link
Contributor Author

/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% 84.2% -1.5
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 75.8% 73.5% -2.2
pkg/reconciler/pipelinerun/cancel.go 84.0% 88.1% 4.1
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 84.0% 0.2
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 71.7% 70.3% -1.4

@rafalbigaj
Copy link
Contributor Author

/test pull-tekton-pipeline-build-tests

1 similar comment
@rafalbigaj
Copy link
Contributor Author

/test pull-tekton-pipeline-build-tests

return nil
}
}
if alphaAPIFieldsEnabled {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to come back to this again. Here when the alphaFields is not enabled, we might have an error without any information given to the user. Would be nice to have a specific error in that case stating that it fails because the alphaFields are not enabled.

There is a helper function you may use:

func ValidateEnabledAPIFields(ctx context.Context, featureName, wantVersion string) *apis.FieldError {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing! Fixed

@pritidesai
Copy link
Member

We are almost there, thanks a bunch once again for all the effort @rafalbigaj

The changes look great and the pipeline state transitioning is much more meaningful now:

01-terminate-pipelinerun   Unknown     Running     4s
01-terminate-pipelinerun   False       PipelineRunCancelled   49s         43s

01-terminate-pipelinerun   Unknown     Running                   4s
01-terminate-pipelinerun   Unknown     StoppedRunningFinally     37s
01-terminate-pipelinerun   False       Cancelled                 39s

01-terminate-pipelinerun   Unknown     Running                8s
01-terminate-pipelinerun   Unknown     CancelledRunningFinally   18s
01-terminate-pipelinerun   False       Cancelled                 19s         21s

01-terminate-pipelinerun   Unknown     Running   4s
01-terminate-pipelinerun   False       Cancelled   31s         21s

I would like to hear your thoughts on isRunning before approving 🎉

The implementation of TEP-0058: Graceful Pipeline Run Termination.

The new `spec.Status` values:

- `StoppedRunFinally` - To "stop" (i.e. let the tasks complete, then execute finally tasks) a Pipeline
- `CancelledRunFinally` - To "cancel" (i.e. interrupt any executing non finally tasks, then execute finally tasks)
- `Cancelled` - Same as today's `PipelineRunCancelled` - i.e. interrupt any executing tasks without running finally tasks

The new `PipelineRun` condition reasons:

- `CancelledRunningFinally` - indicates that pipeline has been gracefully cancelled, but final tasks are now running
- `StoppedRunningFinally` - indicates that pipeline has been gracefully stopped, but final tasks are now running

Status `PipelineRunCancelled` is deprecated (replaced by `Cancelled`). The same applies to the condition reason.

New features hidden by alpha API fields flag.
@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 86.5% 86.7% 0.2
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 73.5% 74.3% 0.8
pkg/apis/pipeline/v1beta1/pipelinerun_validation.go 98.3% 98.5% 0.2
pkg/reconciler/pipelinerun/cancel.go 84.0% 88.9% 4.9
pkg/reconciler/pipelinerun/pipelinerun.go 82.9% 83.1% 0.2
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.2% 0.2
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 71.7% 73.4% 1.8

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for yet another update and for your patience!
I went through all the various tests and coverage again, and everything looks good to me.
I would be nice to have another quick docs PR on top to document that a pending pipeline cannot be cancelled via graceful cancel 🙏
/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afrittoli

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 11, 2021
@pritidesai
Copy link
Member

thank you once again @rafalbigaj for all the work and your patience, the changes look great. Very exciting for this 🎉

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 11, 2021
@tekton-robot tekton-robot merged commit c8dc797 into tektoncd:main Jun 11, 2021
vdemeester added a commit to vdemeester/tektoncd-cli that referenced this pull request Jul 9, 2021
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

When we updated the dependencies, we didn't change the constant we are
using from tektoncd/pipeline and thus, we were using the new value
that is only supported when alpha api are enabled — hence the CI is
broken.

This make the cli use the deprecated field for now, but we need to
follow up to support graceful cancellation.

Signed-off-by: Vincent Demeester <[email protected]>
vdemeester added a commit to vdemeester/tektoncd-cli that referenced this pull request Jul 9, 2021
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

When we updated the dependencies, we didn't change the constant we are
using from tektoncd/pipeline and thus, we were using the new value
that is only supported when alpha api are enabled — hence the CI is
broken.

This make the cli use the deprecated field for now, but we need to
follow up to support graceful cancellation.

Signed-off-by: Vincent Demeester <[email protected]>
vdemeester added a commit to vdemeester/tektoncd-cli that referenced this pull request Jul 9, 2021
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

When we updated the dependencies, we didn't change the constant we are
using from tektoncd/pipeline and thus, we were using the new value
that is only supported when alpha api are enabled — hence the CI is
broken.

This make the cli use the deprecated field for now, but we need to
follow up to support graceful cancellation.

Signed-off-by: Vincent Demeester <[email protected]>
tekton-robot pushed a commit to tektoncd/cli that referenced this pull request Jul 9, 2021
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

When we updated the dependencies, we didn't change the constant we are
using from tektoncd/pipeline and thus, we were using the new value
that is only supported when alpha api are enabled — hence the CI is
broken.

This make the cli use the deprecated field for now, but we need to
follow up to support graceful cancellation.

Signed-off-by: Vincent Demeester <[email protected]>
vinamra28 added a commit to vinamra28/cli that referenced this pull request Jan 10, 2022
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

In this patch, a new flag is introduced `--grace` which handles all the
scenarios as follows

--grace int   Gracefully cancel a PipelineRun
              To use this, you need to change the feature-flags configmap enable-api-fields to alpha instead of stable.
              Ignored if set to a negative value.
              Set to 1 if you want to cancel the current running task and directly run the finally tasks.
              Set to 2 if you want to cancel the remaining non-final task and directly run the finally tasks.

Signed-off-by: vinamra28 <[email protected]>
vinamra28 added a commit to vinamra28/cli that referenced this pull request Jan 12, 2022
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

In this patch, a new flag is introduced `--grace` which handles all the
scenarios as follows

--grace int   Gracefully cancel a PipelineRun
              To use this, you need to change the feature-flags configmap enable-api-fields to alpha instead of stable.
              Ignored if set to a negative value.
              Set to 1 if you want to cancel the current running task and directly run the finally tasks.
              Set to 2 if you want to cancel the remaining non-final task and directly run the finally tasks.

Signed-off-by: vinamra28 <[email protected]>
vinamra28 added a commit to vinamra28/cli that referenced this pull request Jan 14, 2022
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

In this patch, a new flag is introduced `--grace` which handles all the
scenarios as follows

--grace int   Gracefully cancel a PipelineRun
              To use this, you need to change the feature-flags configmap enable-api-fields to alpha instead of stable.
              Ignored if set to a negative value.
              Set to 1 if you want to cancel the current running task and directly run the finally tasks.
              Set to 2 if you want to cancel the remaining non-final task and directly run the finally tasks.

Signed-off-by: vinamra28 <[email protected]>
vinamra28 added a commit to vinamra28/cli that referenced this pull request Jan 21, 2022
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

In this patch, a new flag is introduced `--grace` which handles all the
scenarios as follows

--grace int   Gracefully cancel a PipelineRun
              To use this, you need to change the feature-flags configmap enable-api-fields to alpha instead of stable.
              Ignored if set to a negative value.
              Set to 1 if you want to cancel the current running task and directly run the finally tasks.
              Set to 2 if you want to cancel the remaining non-final task and directly run the finally tasks.

Signed-off-by: vinamra28 <[email protected]>
tekton-robot pushed a commit to tektoncd/cli that referenced this pull request Jan 21, 2022
With tektoncd/pipeline#3915, there is now a
possibility to graceful cancel. As of today, the cli only supports
force cancelling.

In this patch, a new flag is introduced `--grace` which handles all the
scenarios as follows

--grace int   Gracefully cancel a PipelineRun
              To use this, you need to change the feature-flags configmap enable-api-fields to alpha instead of stable.
              Ignored if set to a negative value.
              Set to 1 if you want to cancel the current running task and directly run the finally tasks.
              Set to 2 if you want to cancel the remaining non-final task and directly run the finally tasks.

Signed-off-by: vinamra28 <[email protected]>
abayer added a commit to abayer/tektoncd-pipeline that referenced this pull request Jun 22, 2022
Fixes tektoncd#4611.

We deprecated the original cancelled status (with the value `PipelineRunCancelled`) in tektoncd#3915, and we're now at the time for it to be removed in favor of the value `Cancelled`.

Signed-off-by: Andrew Bayer <[email protected]>
abayer added a commit to abayer/tektoncd-pipeline that referenced this pull request Jun 30, 2022
Fixes tektoncd#4611.

We deprecated the original cancelled status (with the value `PipelineRunCancelled`) in tektoncd#3915, and we're now at the time for it to be removed in favor of the value `Cancelled`.

Signed-off-by: Andrew Bayer <[email protected]>
tekton-robot pushed a commit that referenced this pull request Jul 1, 2022
Fixes #4611.

We deprecated the original cancelled status (with the value `PipelineRunCancelled`) in #3915, and we're now at the time for it to be removed in favor of the value `Cancelled`.

Signed-off-by: Andrew Bayer <[email protected]>
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants