Skip to content

Commit 802dc28

Browse files
authored
Add multi-label support to scalesets (#4408)
1 parent 9bc1c9e commit 802dc28

28 files changed

+388
-44
lines changed

apis/actions.github.com/v1alpha1/autoscalingrunnerset_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type AutoscalingRunnerSetSpec struct {
6666
// +optional
6767
RunnerScaleSetName string `json:"runnerScaleSetName,omitempty"`
6868

69+
// +optional
70+
RunnerScaleSetLabels []string `json:"runnerScaleSetLabels,omitempty"`
71+
6972
// +optional
7073
Proxy *ProxyConfig `json:"proxy,omitempty"`
7174

apis/actions.github.com/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gha-runner-scale-set-controller-experimental/crds/actions.github.com_autoscalingrunnersets.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8385,6 +8385,10 @@ spec:
83858385
type: object
83868386
runnerGroup:
83878387
type: string
8388+
runnerScaleSetLabels:
8389+
items:
8390+
type: string
8391+
type: array
83888392
runnerScaleSetName:
83898393
type: string
83908394
template:

charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalingrunnersets.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8385,6 +8385,10 @@ spec:
83858385
type: object
83868386
runnerGroup:
83878387
type: string
8388+
runnerScaleSetLabels:
8389+
items:
8390+
type: string
8391+
type: array
83888392
runnerScaleSetName:
83898393
type: string
83908394
template:

charts/gha-runner-scale-set-experimental/templates/autoscalingrunnserset.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ spec:
8383
githubConfigSecret: {{ include "github-secret.name" . | quote }}
8484
runnerGroup: {{ .Values.scaleset.runnerGroup | quote }}
8585
runnerScaleSetName: {{ .Values.scaleset.name | quote }}
86+
{{- if and .Values.scaleset.labels (kindIs "slice" .Values.scaleset.labels) }}
87+
{{- range .Values.scaleset.labels }}
88+
{{- if empty . }}
89+
{{- fail "scaleset.labels contains an empty string, each label must be a non-empty string of less than 256 characters" }}
90+
{{- end }}
91+
{{- if ge (len .) 256 }}
92+
{{- fail "scaleset.labels contains a label that is 256 characters or more, each label must be a non-empty string of less than 256 characters" }}
93+
{{- end }}
94+
{{- end }}
95+
runnerScaleSetLabels:
96+
{{- toYaml .Values.scaleset.labels | nindent 4 }}
97+
{{- end }}
8698

8799
{{- if .Values.githubServerTLS }}
88100
githubServerTLS:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
suite: "AutoscalingRunnerSet scale set labels"
2+
templates:
3+
- autoscalingrunnserset.yaml
4+
tests:
5+
- it: should apply scaleset labels slice as runnerScaleSetLabels
6+
set:
7+
scaleset.name: "test"
8+
scaleset.labels:
9+
- "linux"
10+
- "x64"
11+
auth.url: "https://github.com/org"
12+
auth.githubToken: "gh_token12345"
13+
controllerServiceAccount.name: "arc"
14+
controllerServiceAccount.namespace: "arc-system"
15+
release:
16+
name: "test-name"
17+
namespace: "test-namespace"
18+
asserts:
19+
- equal:
20+
path: spec.runnerScaleSetLabels[0]
21+
value: "linux"
22+
- equal:
23+
path: spec.runnerScaleSetLabels[1]
24+
value: "x64"
25+
26+
- it: should fail when a scaleset label is empty
27+
set:
28+
scaleset.name: "test"
29+
scaleset.labels:
30+
- "linux"
31+
- ""
32+
auth.url: "https://github.com/org"
33+
auth.githubToken: "gh_token12345"
34+
controllerServiceAccount.name: "arc"
35+
controllerServiceAccount.namespace: "arc-system"
36+
release:
37+
name: "test-name"
38+
namespace: "test-namespace"
39+
asserts:
40+
- failedTemplate:
41+
errorMessage: "scaleset.labels contains an empty string, each label must be a non-empty string of less than 256 characters"
42+
43+
- it: should fail when a scaleset label is 256 characters or more
44+
set:
45+
scaleset.name: "test"
46+
scaleset.labels:
47+
- "linux"
48+
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
49+
auth.url: "https://github.com/org"
50+
auth.githubToken: "gh_token12345"
51+
controllerServiceAccount.name: "arc"
52+
controllerServiceAccount.namespace: "arc-system"
53+
release:
54+
name: "test-name"
55+
namespace: "test-namespace"
56+
asserts:
57+
- failedTemplate:
58+
errorMessage: "scaleset.labels contains a label that is 256 characters or more, each label must be a non-empty string of less than 256 characters"

charts/gha-runner-scale-set-experimental/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ scaleset:
55
# Name of the scaleset
66
name: ""
77
runnerGroup: "default"
8+
# Labels are optional list of strings that will be applied to the scaleset
9+
# allowing scaleset to be selected by the listener based on the labels specified in the workflow.
10+
# https://docs.github.com/en/actions/how-tos/manage-runners/self-hosted-runners/apply-labels
11+
labels: []
812
## minRunners is the min number of idle runners. The target number of runners created will be
913
## calculated as a sum of minRunners and the number of jobs assigned to the scale set.
1014
# minRunners: 0

charts/gha-runner-scale-set/templates/autoscalingrunnerset.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ spec:
7575
{{- with .Values.runnerScaleSetName }}
7676
runnerScaleSetName: {{ . }}
7777
{{- end }}
78+
{{- if and .Values.scaleSetLabels (kindIs "slice" .Values.scaleSetLabels) }}
79+
{{- range .Values.scaleSetLabels }}
80+
{{- if empty . }}
81+
{{- fail "scaleSetLabels contains an empty string, each label must be a non-empty string of less than 256 characters" }}
82+
{{- end }}
83+
{{- if ge (len .) 256 }}
84+
{{- fail "scaleSetLabels contains a label that is 256 characters or more, each label must be a non-empty string of less than 256 characters" }}
85+
{{- end }}
86+
{{- end }}
87+
runnerScaleSetLabels:
88+
{{- toYaml .Values.scaleSetLabels | nindent 4 }}
89+
{{- end }}
7890

7991
{{- if .Values.githubServerTLS }}
8092
githubServerTLS:

charts/gha-runner-scale-set/tests/template_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,37 @@ func TestTemplateRenderedAutoScalingRunnerSet_RunnerScaleSetName(t *testing.T) {
474474
assert.Equal(t, "ghcr.io/actions/actions-runner:latest", ars.Spec.Template.Spec.Containers[0].Image)
475475
}
476476

477+
func TestTemplateRenderedAutoScalingRunnerSet_ScaleSetLabels(t *testing.T) {
478+
t.Parallel()
479+
480+
// Path to the helm chart we will test
481+
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set")
482+
require.NoError(t, err)
483+
484+
releaseName := "test-runners"
485+
namespaceName := "test-" + strings.ToLower(random.UniqueId())
486+
487+
options := &helm.Options{
488+
Logger: logger.Discard,
489+
SetValues: map[string]string{
490+
"githubConfigUrl": "https://github.com/actions",
491+
"githubConfigSecret.github_token": "gh_token12345",
492+
"scaleSetLabels[0]": "linux",
493+
"scaleSetLabels[1]": "x64",
494+
"controllerServiceAccount.name": "arc",
495+
"controllerServiceAccount.namespace": "arc-system",
496+
},
497+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
498+
}
499+
500+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnerset.yaml"})
501+
502+
var ars v1alpha1.AutoscalingRunnerSet
503+
helm.UnmarshalK8SYaml(t, output, &ars)
504+
505+
assert.Equal(t, []string{"linux", "x64"}, ars.Spec.RunnerScaleSetLabels)
506+
}
507+
477508
func TestTemplateRenderedAutoScalingRunnerSet_ProvideMetadata(t *testing.T) {
478509
t.Parallel()
479510

charts/gha-runner-scale-set/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
## ex: https://github.com/myorg/myrepo or https://github.com/myorg or https://github.com/enterprises/myenterprise
33
githubConfigUrl: ""
44

5+
scaleSetLabels: []
6+
57
## githubConfigSecret is the k8s secret information to use when authenticating via the GitHub API.
68
## You can choose to supply:
79
## A) a PAT token,

0 commit comments

Comments
 (0)