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

POC: Canceling concurrent PipelineRuns #5501

Closed
wants to merge 1 commit into from

Conversation

lbernick
Copy link
Member

@lbernick lbernick commented Sep 15, 2022

Changes

Alternative to tektoncd/triggers#1446.

This commit adds a proof of concept for "concurrency primitives" in Pipelines that will allow higher-level controllers to implement concurrency controls. It adds a new CRD, "ConcurrencyControl". PipelineRuns that should have their concurrency controlled should be created with a label referencing the ConcurrencyControl. The PipelineRun controller will create another label on the PipelineRun specifying its "concurrency key". Any PipelineRuns with the same concurrency key belong to the same concurrency group and use the same concurrency strategy.

This solution doesn't require PipelineRuns to be created as Pending. The reason for this is that knative does not allow a reconciler to edit the spec of an object being reconciled. In other words, the PipelineRun controller cannot "start" Pending PipelineRuns after canceling other PipelineRuns in the same concurrency group. Instead, concurrency controls are just handled before execution starts.

Submitter Checklist

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

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

This commit adds a proof of concept for "concurrency primitives" in Pipelines
that will allow higher-level controllers to implement concurrency controls.
It adds a new CRD, "ConcurrencyControl". PipelineRuns that should have their
concurrency controlled should be created with a label referencing the ConcurrencyControl.
The PipelineRun controller will create another label on the PipelineRun specifying
its "concurrency key". Any PipelineRuns with the same concurrency key belong to the same
concurrency group and use the same concurrency strategy.

This solution doesn't require PipelineRuns to be created as Pending. The reason for this
is that knative does not allow a reconciler to edit the spec of an object being reconciled.
In other words, the PipelineRun controller cannot "start" Pending PipelineRuns after
canceling other PipelineRuns in the same concurrency group. Instead, concurrency controls
are just handled before execution starts.

One drawback of this solution is that users can get around concurrency controls by editing
the labels of the PipelineRun.
@tekton-robot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@tekton-robot
Copy link
Collaborator

@lbernick: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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 do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Sep 15, 2022
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from lbernick after the PR has been reviewed.

The full list of commands accepted by this bot can be found 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 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 15, 2022
@dibyom
Copy link
Member

dibyom commented Sep 15, 2022

This solution doesn't require PipelineRuns to be created as Pending. The reason for this is that knative does not allow a reconciler to edit the spec of an object being reconciled. In other words, the PipelineRun controller cannot "start" Pending PipelineRuns after canceling other PipelineRuns in the same concurrency group. Instead, concurrency controls are just handled before execution starts.

The ReconcileKind interface does not update changes to the spec, but one can always make a call to update the status from within the ReconcileKind function.

@lbernick
Copy link
Member Author

This solution doesn't require PipelineRuns to be created as Pending. The reason for this is that knative does not allow a reconciler to edit the spec of an object being reconciled. In other words, the PipelineRun controller cannot "start" Pending PipelineRuns after canceling other PipelineRuns in the same concurrency group. Instead, concurrency controls are just handled before execution starts.

The ReconcileKind interface does not update changes to the spec, but one can always make a call to update the status from within the ReconcileKind function.

for sure! I mention this because I didn't want to "run" a pending pipelinerun by editing its status, because I thought it would be confusing/introduce bugs to have spec status = Pending but then have the PR actually executing. so I made this not dependent on creating pipelineruns as pending.

}
key := resources.ApplyParametersToConcurrency(ctx, cc, pr)
pr.Labels["tekton.dev/concurrency-key"] = key
if cc.Spec.Strategy != "Cancel" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming we'd create constants for supported strategies?

Copy link
Member Author

Choose a reason for hiding this comment

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

definitely!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just making sure. =)

@abayer
Copy link
Contributor

abayer commented Sep 19, 2022

This feels like it's on the right track!

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 19, 2022
@tekton-robot
Copy link
Collaborator

@lbernick: 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.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

I do like that the ConcurrencyControl CRD holds the strategy and "how" the key is computed.
What is "slightly" weird though, is the implicitness of how it is computed. With default value, we can probably get away with it, but it might lead to weird behavior from time to time, if, for example, a parameter is renamed and thus, doesn't map to the ConcurrencyControl anymore.

Comment on lines +12 to +14
params:
- name: param-1
- name: param-2
Copy link
Member

Choose a reason for hiding this comment

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

Those would be "populated" by the PipelineRun params ?
What happens if there is a mismatch between PipelineRun's params and that ConcurrencyControl params?

Copy link
Member Author

Choose a reason for hiding this comment

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

Those would be "populated" by the PipelineRun params ?

yup!

What happens if there is a mismatch between PipelineRun's params and that ConcurrencyControl params?

We would probably fail the PipelineRun (not sure how a separate controller outside of pipelines would do that though) or cancel it.

@lbernick
Copy link
Member Author

I do like that the ConcurrencyControl CRD holds the strategy and "how" the key is computed. What is "slightly" weird though, is the implicitness of how it is computed. With default value, we can probably get away with it, but it might lead to weird behavior from time to time, if, for example, a parameter is renamed and thus, doesn't map to the ConcurrencyControl anymore.

I agree! Do you have any suggestions for what might work better? We could remove "key" and "params" entirely, but I think this will be challenging if we want to sort things into concurrency groups based on parameters from a trigger or workflow (which I think we'll want to do).

@lbernick
Copy link
Member Author

Closing in favor of tektoncd/experimental#895

@lbernick lbernick closed this Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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