Skip to content

Commit 758c1bc

Browse files
zakiskchmouel
authored andcommitted
feat: Enable cluster wide setting for cancel-in-progress
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>
1 parent 9b5ec18 commit 758c1bc

File tree

11 files changed

+825
-161
lines changed

11 files changed

+825
-161
lines changed

config/302-pac-configmap.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ data:
9090
error-detection-simple-regexp: |-
9191
^(?P<filename>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+)?([ ]*)?(?P<error>.*)
9292
93+
# Global setting to control whether Pipelines-as-Code should automatically cancel
94+
# any in-progress PipelineRuns associated with a pull request when that pull request is updated.
95+
# This helps prevent multiple redundant runs from executing simultaneously.
96+
# Default value: false.
97+
enable-cancel-in-progress-on-pull-requests: "false"
98+
99+
# Global setting to determine whether Pipelines-as-Code should automatically cancel
100+
# in-progress PipelineRuns triggered by a push event, if a new push occurs on the same branch.
101+
# This prevents overlapping or redundant runs for the same branch.
102+
# Default value: false.
103+
enable-cancel-in-progress-on-push: "false"
104+
93105
# Since public bitbucket doesn't have the concept of Secret, we need to be
94106
# able to secure the request by querying https://ip-ranges.atlassian.com/,
95107
# this only happen for public bitbucket (ie: when provider.url is not set in

docs/content/docs/install/operator_installation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ spec:
3333
auto-configure-new-github-repo: 'false'
3434
error-log-snippet: 'true'
3535
error-detection-from-container-logs: 'false'
36+
enable-cancel-in-progress-on-pull-requests: 'false'
37+
enable-cancel-in-progress-on-push: 'false'
3638
hub-url: 'https://api.hub.tekton.dev/v1'
3739
hub-catalog-name: tekton
3840
error-detection-max-number-of-lines: '50'

docs/content/docs/install/settings.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,32 @@ There is a few things you can configure through the config map
139139
risk and should be aware of the potential security vulnerabilities.
140140
(only GitHub and Gitea is supported at the moment).
141141

142+
### Global Cancel In Progress Settings
143+
144+
* `enable-cancel-in-progress-on-pull-requests`
145+
146+
If the `enable-cancel-in-progress-on-pull-requests` setting is enabled (true), Pipelines-as-Code will automatically cancel
147+
any in-progress PipelineRuns associated with a pull request when a new update (such as a new commit) is pushed to that pull request.
148+
This ensures that only the latest commit is processed, helping conserve compute resources and avoid running outdated PipelineRuns
149+
tied to previous commits.
150+
151+
It's important to note that if this global setting is disabled (false), Pipelines-as-Code will still honor the cancel-in-progress annotation
152+
at the individual PipelineRun level. In such cases, if a PipelineRun includes this annotation, it will take precedence over the global setting,
153+
and Pipelines-as-Code will cancel any matching in-progress runs when the pull request is updated.
154+
155+
This is disabled by default.
156+
157+
* `enable-cancel-in-progress-on-push`
158+
159+
If the `enable-cancel-in-progress-on-push` setting is enabled (true), Pipelines-as-Code will automatically cancel any in-progress PipelineRuns
160+
triggered by a push event when a new push is made to the same branch. This helps ensure that only the most recent commit is processed, preventing unnecessary execution of outdated PipelineRuns and optimizing resource usage.
161+
162+
Additionally, if this global setting is disabled (false), Pipelines-as-Code will still respect the cancel-in-progress annotation
163+
on individual PipelineRuns. In such cases, the annotation will override the global configuration, and Pipelines-as-Code will
164+
cancel any in-progress runs for that specific PipelineRun when a new push occurs on the same branch.
165+
166+
This is disabled by default.
167+
142168
### Tekton Hub support
143169

144170
Pipelines-as-Code supports fetching task with its remote annotations feature, by default it will fetch it from the [public tekton hub](https://hub.tekton.dev/) but you can configure it to point to your own with these settings:

pkg/params/settings/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ type Settings struct {
6363
ErrorDetectionNumberOfLines int `default:"50" json:"error-detection-max-number-of-lines"`
6464
ErrorDetectionSimpleRegexp string `default:"^(?P<filename>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+)?([ ]*)?(?P<error>.*)" json:"error-detection-simple-regexp"`
6565

66+
EnableCancelInProgressOnPullRequests bool `json:"enable-cancel-in-progress-on-pull-requests"`
67+
EnableCancelInProgressOnPush bool `json:"enable-cancel-in-progress-on-push"`
68+
6669
CustomConsoleName string `json:"custom-console-name"`
6770
CustomConsoleURL string `json:"custom-console-url"`
6871
CustomConsolePRdetail string `json:"custom-console-url-pr-details"`

pkg/params/settings/config_test.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,31 @@ func TestSyncConfig(t *testing.T) {
2121
name: "With all default values",
2222
configMap: map[string]string{},
2323
expectedStruct: Settings{
24-
ApplicationName: "Pipelines as Code CI",
25-
HubCatalogs: nil,
26-
RemoteTasks: true,
27-
MaxKeepRunsUpperLimit: 0,
28-
DefaultMaxKeepRuns: 0,
29-
BitbucketCloudCheckSourceIP: true,
30-
BitbucketCloudAdditionalSourceIP: "",
31-
TektonDashboardURL: "",
32-
AutoConfigureNewGitHubRepo: false,
33-
AutoConfigureRepoNamespaceTemplate: "",
34-
SecretAutoCreation: true,
35-
SecretGHAppRepoScoped: true,
36-
SecretGhAppTokenScopedExtraRepos: "",
37-
ErrorLogSnippet: true,
38-
ErrorDetection: true,
39-
ErrorDetectionNumberOfLines: 50,
40-
ErrorDetectionSimpleRegexp: "^(?P<filename>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+)?([ ]*)?(?P<error>.*)",
41-
CustomConsoleName: "",
42-
CustomConsoleURL: "",
43-
CustomConsolePRdetail: "",
44-
CustomConsolePRTaskLog: "",
45-
CustomConsoleNamespaceURL: "",
46-
RememberOKToTest: false,
24+
ApplicationName: "Pipelines as Code CI",
25+
HubCatalogs: nil,
26+
RemoteTasks: true,
27+
MaxKeepRunsUpperLimit: 0,
28+
DefaultMaxKeepRuns: 0,
29+
BitbucketCloudCheckSourceIP: true,
30+
BitbucketCloudAdditionalSourceIP: "",
31+
TektonDashboardURL: "",
32+
AutoConfigureNewGitHubRepo: false,
33+
AutoConfigureRepoNamespaceTemplate: "",
34+
SecretAutoCreation: true,
35+
SecretGHAppRepoScoped: true,
36+
SecretGhAppTokenScopedExtraRepos: "",
37+
ErrorLogSnippet: true,
38+
ErrorDetection: true,
39+
ErrorDetectionNumberOfLines: 50,
40+
ErrorDetectionSimpleRegexp: "^(?P<filename>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+)?([ ]*)?(?P<error>.*)",
41+
EnableCancelInProgressOnPullRequests: false,
42+
EnableCancelInProgressOnPush: false,
43+
CustomConsoleName: "",
44+
CustomConsoleURL: "",
45+
CustomConsolePRdetail: "",
46+
CustomConsolePRTaskLog: "",
47+
CustomConsoleNamespaceURL: "",
48+
RememberOKToTest: false,
4749
},
4850
},
4951
{

0 commit comments

Comments
 (0)