Skip to content

feat: Enable cluster wide cancel-in-progress setting via PAC ConfigMap #2050

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

Conversation

zakisk
Copy link
Contributor

@zakisk zakisk commented Apr 15, 2025

Cancel-in-progress now can be enabled via PAC configMap using enable-cancel-in-progress-on-pull-requests and enable-cancel-in-progress-on-push fields for pull request and push events respectively. if a PipelineRun is having cancel-in-progress annotation specified explicitly then it will override setting from PAC configMap.

Changes

Submitter Checklist

  • 📝 Ensure your commit message is clear and informative. Refer to the How to write a git commit message guide. Include the commit message in the PR body rather than linking to an external site (e.g., Jira ticket).

  • ♽ Run make test lint before submitting a PR to avoid unnecessary CI processing. Consider installing pre-commit and running pre-commit install in the repository root for an efficient workflow.

  • ✨ We use linters to maintain clean and consistent code. Run make lint before submitting a PR. Some linters offer a --fix mode, executable with make fix-linters (ensure markdownlint and golangci-lint are installed).

  • 📖 Document any user-facing features or changes in behavior.

  • 🧪 While 100% coverage isn't required, we encourage unit tests for code changes where possible.

  • 🎁 If feasible, add an end-to-end test. See README for details.

  • 🔎 Address any CI test flakiness before merging, or provide a valid reason to bypass it (e.g., token rate limitations).

  • If adding a provider feature, fill in the following details:

    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

    (update the provider documentation accordingly)

@osp-pac osp-pac added the e2e label Apr 15, 2025
@zakisk zakisk requested review from chmouel and vdemeester April 15, 2025 14:48
@zakisk
Copy link
Contributor Author

zakisk commented Apr 15, 2025

linteres is failing on 😕

pkg/pipelineascode/cancel_pipelineruns.go:56: NotIn ==> noting, not in, notion
pkg/pipelineascode/cancel_pipelineruns_test.go:1525: NotIn ==> noting, not in, notion
pkg/pipelineascode/cancel_pipelineruns_test.go:1526: notin ==> noting, not in, notion

@chmouel
Copy link
Member

chmouel commented Apr 16, 2025

linteres is failing on 😕

pkg/pipelineascode/cancel_pipelineruns.go:56: NotIn ==> noting, not in, notion
pkg/pipelineascode/cancel_pipelineruns_test.go:1525: NotIn ==> noting, not in, notion
pkg/pipelineascode/cancel_pipelineruns_test.go:1526: notin ==> noting, not in, notion

can you send a pr ?

@zakisk
Copy link
Contributor Author

zakisk commented Apr 16, 2025

can you send a pr ?

yes

@zakisk
Copy link
Contributor Author

zakisk commented Apr 16, 2025

@chmouel codespell PR #2055

@zakisk zakisk force-pushed the SRVKP-6910-enable-cluster-wide-cancel-in-progress branch 5 times, most recently from 91ee790 to 4cb54cb Compare April 23, 2025 05:36
@chmouel chmouel self-assigned this Apr 23, 2025
@chmouel chmouel requested a review from Copilot April 23, 2025 07:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces functionality to enable cancel‐in‐progress for both pull request and push events via the PAC ConfigMap. Key changes include:

  • Adding new functions in test/pkg/github/setup.go to patch the PAC ConfigMap.
  • Implementing cancel‐in‐progress logic in pkg/pipelineascode and updating the corresponding tests.
  • Updating configuration, settings, and documentation to support the new cancel‐in‐progress flags.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/pkg/github/setup.go Added helper functions to patch PAC ConfigMap and reset settings.
test/github_pullrequest_test.go New tests for verifying cancel‐in‐progress behavior for PR and push.
pkg/pipelineascode/pipelineascode.go Renamed and updated cancellation function invocation.
pkg/pipelineascode/cancel_pipelineruns.go Updated label selector construction and cancellation condition logic.
pkg/params/settings/convert_test.go Added new config fields for cancel‐in‐progress.
pkg/params/settings/config_test.go Added tests for new cancel‐in‐progress settings.
pkg/params/settings/config.go Integrated new boolean fields into Settings.
docs/content/docs/install/settings.md Added documentation for cancel‐in‐progress settings.
docs/content/docs/install/operator_installation.md Updated installation docs with new cancel‐in‐progress options.
config/302-pac-configmap.yaml Added new config keys for global cancel‐in‐progress behavior.
Comments suppressed due to low confidence (2)

test/pkg/github/setup.go:124

  • Instead of calling log.Fatalf on marshalling errors in PatchPACConfigMap, consider returning the error so that it can be handled gracefully by the caller.
if err != nil { log.Fatalf("Failed to marshal patch data: %v", err) }

test/pkg/github/setup.go:155

  • In SetCancelInProgressToDefaults, returning the error instead of calling log.Fatalf would improve error propagation and allow the caller to handle the failure appropriately.
if err != nil { log.Fatalf("Failed to marshal patch data: %v", err) }

Copy link
Member

@chmouel chmouel left a comment

Choose a reason for hiding this comment

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

this looks good to me, just a comment about some duplication..

I'd like to enable this by default on our dogfooding cluster, please ping me to let you know how to do that

zakisk added 2 commits April 24, 2025 16:10
currently, cancel-in-progress can be configured only on
PipelineRun level via cancel-in-progress annotation.
This PR introduces new setting in Pipelines as Code
ConfigMap with enable-cancel-in-progress-on-pull-requests and
enable-cancel-in-progress-on-push to control cancel-in-progress
functionality on deployment level.

when enable-cancel-in-progress-on-pull-requests is set to true
all the PipelineRun will be cancelled on PR close and on PR
update when a commit is pushed on the head branch of PR and
same for push setting. a PipelineRun will override configmap
setting if it has cancel-in-progress annotation explicitly
and PAC will do accordingly.

https://issues.redhat.com/browse/SRVKP-6910

Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
before this, when source or head branch in cancel-in-progress
matching code having full path weren't being matched.
e.g. refs/heads/branch

Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
@zakisk zakisk force-pushed the SRVKP-6910-enable-cluster-wide-cancel-in-progress branch from 4cb54cb to b1a4c89 Compare April 24, 2025 10:41
@chmouel chmouel merged commit 6bd5498 into openshift-pipelines:main Apr 24, 2025
7 checks passed
@zakisk zakisk deleted the SRVKP-6910-enable-cluster-wide-cancel-in-progress branch April 25, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants