Skip to content

Commit

Permalink
fix(#951): add exception for self-hosted label in webhook search (#953)
Browse files Browse the repository at this point in the history
The webhook "workflowJob" pass the labels the job needs to the controller, who in turns search for them in its RunnerDeployment / RunnerSet. The current implementation ignore the search for `self-hosted` if this is the only label, however if multiple labels are found the `self-hosted` label must be declared explicitely or the RD / RS will not be selected for the autoscaling.

This PR fixes the behavior by ignoring this label, and add documentation on this webhook for the other labels that will still require an explicit declaration (OS and architecture). 

The exception should be temporary, ideally the labels implicitely created (self-hosted, OS, architecture) should be searchable alongside the explicitly declared labels.

code tested, work with `["self-hosted"]` and `["self-hosted","anotherLabel"]`

Fixes #951
  • Loading branch information
clement-loiselet-talend committed Dec 19, 2021
1 parent 83c8a98 commit 0c34196
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -615,6 +615,8 @@ spec:
duration: "30m"
```

This webhook requires you to explicitely set the labels in the RunnerDeployment / RunnerSet if you are using them in your workflow to match the agents (field `runs-on`). Only `self-hosted` will be considered as included by default.

You can configure your GitHub webhook settings to only include `Workflows Job` events, so that it sends us three kinds of `workflow_job` events per a job run.

Each kind has a `status` of `queued`, `in_progress` and `completed`. With the above configuration, `actions-runner-controller` adds one runner for a `workflow_job` event whose `status` is `queued`. Similarly, it removes one runner for a `workflow_job` event whose `status` is `completed`. The cavaet to this to remember is that this the scale down is within the bounds of your `scaleDownDelaySecondsAfterScaleOut` configuration, if this time hasn't past the scale down will be defered.
Expand Down
24 changes: 16 additions & 8 deletions controllers/horizontal_runner_autoscaler_webhook.go
Expand Up @@ -580,13 +580,17 @@ HRA:
return nil, err
}

if len(labels) == 1 && labels[0] == "self-hosted" {
return &ScaleTarget{HorizontalRunnerAutoscaler: hra, ScaleUpTrigger: v1alpha1.ScaleUpTrigger{Duration: duration}}, nil
}

// Ensure that the RunnerSet-managed runners have all the labels requested by the workflow_job.
for _, l := range labels {
var matched bool

// ignore "self-hosted" label as all instance here are self-hosted
if l == "self-hosted" {
continue
}

// TODO labels related to OS and architecture needs to be explicitely declared or the current implementation will not be able to find them.

for _, l2 := range rs.Spec.Labels {
if l == l2 {
matched = true
Expand All @@ -607,13 +611,17 @@ HRA:
return nil, err
}

if len(labels) == 1 && labels[0] == "self-hosted" {
return &ScaleTarget{HorizontalRunnerAutoscaler: hra, ScaleUpTrigger: v1alpha1.ScaleUpTrigger{Duration: duration}}, nil
}

// Ensure that the RunnerDeployment-managed runners have all the labels requested by the workflow_job.
for _, l := range labels {
var matched bool

// ignore "self-hosted" label as all instance here are self-hosted
if l == "self-hosted" {
continue
}

// TODO labels related to OS and architecture needs to be explicitely declared or the current implementation will not be able to find them.

for _, l2 := range rd.Spec.Template.Spec.Labels {
if l == l2 {
matched = true
Expand Down

0 comments on commit 0c34196

Please sign in to comment.