Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 1829721

Browse files
feat: order label matchers for multi-runners (#3591)
# Description Add the option to label matcheer for multi-runner to order the matcher. First matchter applies first. fix #3590 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 51acab9 commit 1829721

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

Diff for: examples/multi-runner/templates/runner-configs/linux-x64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ matcherConfig:
22
exactMatch: false
33
labelMatchers:
44
- [ self-hosted, linux, x64, amazon ]
5+
priority: 1 # set ephemeral runner priority to 1
56
fifo: true
67
delay_webhook_event: 0
78
runner_config:

Diff for: modules/multi-runner/README.md

+2-1
Large diffs are not rendered by default.

Diff for: modules/multi-runner/variables.tf

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ variable "multi_runner_config" {
119119
matcherConfig = object({
120120
labelMatchers = list(list(string))
121121
exactMatch = optional(bool, false)
122+
priority = optional(number, 999)
122123
})
123124
fifo = optional(bool, false)
124125
redrive_build_queue = optional(object({
@@ -182,6 +183,7 @@ variable "multi_runner_config" {
182183
matcherConfig: {
183184
labelMatchers: "The list of list of labels supported by the runner configuration. `[[self-hosted, linux, x64, example]]`"
184185
exactMatch: "If set to true all labels in the workflow job must match the GitHub labels (os, architecture and `self-hosted`). When false if __any__ workflow label matches it will trigger the webhook."
186+
priority: "If set it defines the priority of the matcher, the matcher with the lowest priority will be evaluated first. Default is 999, allowed values 0-999."
185187
}
186188
fifo: "Enable a FIFO queue to remain the order of events received by the webhook. Suggest to set to true for repo level runners."
187189
redrive_build_queue: "Set options to attach (optional) a dead letter queue to the build queue, the queue between the webhook and the scale up lambda. You have the following options. 1. Disable by setting `enabled` to false. 2. Enable by setting `enabled` to `true`, `maxReceiveCount` to a number of max retries."

Diff for: modules/webhook/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ No modules.
9797
| <a name="input_repository_white_list"></a> [repository\_white\_list](#input\_repository\_white\_list) | List of github repository full names (owner/repo\_name) that will be allowed to use the github app. Leave empty for no filtering. | `list(string)` | `[]` | no |
9898
| <a name="input_role_path"></a> [role\_path](#input\_role\_path) | The path that will be added to the role; if not set, the environment name will be used. | `string` | `null` | no |
9999
| <a name="input_role_permissions_boundary"></a> [role\_permissions\_boundary](#input\_role\_permissions\_boundary) | Permissions boundary that will be added to the created role for the lambda. | `string` | `null` | no |
100-
| <a name="input_runner_config"></a> [runner\_config](#input\_runner\_config) | SQS queue to publish accepted build events based on the runner type. When exact match is disabled the webhook accecpts the event if one of the workflow job labels is part of the matcher. | <pre>map(object({<br> arn = string<br> id = string<br> fifo = bool<br> matcherConfig = object({<br> labelMatchers = list(list(string))<br> exactMatch = bool<br> })<br> }))</pre> | n/a | yes |
100+
| <a name="input_runner_config"></a> [runner\_config](#input\_runner\_config) | SQS queue to publish accepted build events based on the runner type. When exact match is disabled the webhook accecpts the event if one of the workflow job labels is part of the matcher. The priority defines the order the matchers are applied. | <pre>map(object({<br> arn = string<br> id = string<br> fifo = bool<br> matcherConfig = object({<br> labelMatchers = list(list(string))<br> exactMatch = bool<br> priority = optional(number, 999)<br> })<br> }))</pre> | n/a | yes |
101101
| <a name="input_sqs_workflow_job_queue"></a> [sqs\_workflow\_job\_queue](#input\_sqs\_workflow\_job\_queue) | SQS queue to monitor github events. | <pre>object({<br> id = string<br> arn = string<br> })</pre> | `null` | no |
102102
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags that will be added to created resources. By default resources will be tagged with name and environment. | `map(string)` | `{}` | no |
103103
| <a name="input_webhook_lambda_apigateway_access_log_settings"></a> [webhook\_lambda\_apigateway\_access\_log\_settings](#input\_webhook\_lambda\_apigateway\_access\_log\_settings) | Access log settings for webhook API gateway. | <pre>object({<br> destination_arn = string<br> format = string<br> })</pre> | `null` | no |

Diff for: modules/webhook/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@ variable "tags" {
3434
}
3535

3636
variable "runner_config" {
37-
description = "SQS queue to publish accepted build events based on the runner type. When exact match is disabled the webhook accecpts the event if one of the workflow job labels is part of the matcher."
37+
description = "SQS queue to publish accepted build events based on the runner type. When exact match is disabled the webhook accecpts the event if one of the workflow job labels is part of the matcher. The priority defines the order the matchers are applied."
3838
type = map(object({
3939
arn = string
4040
id = string
4141
fifo = bool
4242
matcherConfig = object({
4343
labelMatchers = list(list(string))
4444
exactMatch = bool
45+
priority = optional(number, 999)
4546
})
4647
}))
48+
validation {
49+
condition = try(var.runner_config.matcherConfig.priority, 999) >= 0 && try(var.runner_config.matcherConfig.priority, 999) < 1000
50+
error_message = "The priority of the matcher must be between 0 and 999."
51+
}
4752
}
53+
4854
variable "sqs_workflow_job_queue" {
4955
description = "SQS queue to monitor github events."
5056
type = object({

Diff for: modules/webhook/webhook.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
locals {
2+
# config with combined key and order
3+
runner_config = { for k, v in var.runner_config : format("%03d-%s", v.matcherConfig.priority, k) => merge(v, { key = k }) }
4+
5+
# sorted list
6+
runner_config_sorted = [for k in sort(keys(local.runner_config)) : local.runner_config[k]]
7+
}
8+
19
resource "aws_lambda_function" "webhook" {
210
s3_bucket = var.lambda_s3_bucket != null ? var.lambda_s3_bucket : null
311
s3_key = var.webhook_lambda_s3_key != null ? var.webhook_lambda_s3_key : null
@@ -18,7 +26,7 @@ resource "aws_lambda_function" "webhook" {
1826
POWERTOOLS_LOGGER_LOG_EVENT = var.log_level == "debug" ? "true" : "false"
1927
PARAMETER_GITHUB_APP_WEBHOOK_SECRET = var.github_app_parameters.webhook_secret.name
2028
REPOSITORY_WHITE_LIST = jsonencode(var.repository_white_list)
21-
RUNNER_CONFIG = jsonencode([for k, v in var.runner_config : v])
29+
RUNNER_CONFIG = jsonencode(local.runner_config_sorted)
2230
SQS_WORKFLOW_JOB_QUEUE = try(var.sqs_workflow_job_queue, null) != null ? var.sqs_workflow_job_queue.id : ""
2331
}
2432
}

0 commit comments

Comments
 (0)