Skip to content

Commit 161d2f3

Browse files
committed
feat: refactor helm chart
To avoid having to completely define template.spec, in case the user wanted to make significant changes to the runner pod, new values extra{Args,Env,VolumeMounts...} are introduced. This also makes the helm chart follow a more canonical layout than before
1 parent a152741 commit 161d2f3

16 files changed

+315
-354
lines changed

charts/gha-runner-scale-set/templates/_helpers.tpl

Lines changed: 200 additions & 175 deletions
Large diffs are not rendered by default.

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ metadata:
2020
{{- end }}
2121
actions.github.com/cleanup-manager-role-binding: {{ include "gha-runner-scale-set.managerRoleBindingName" . }}
2222
actions.github.com/cleanup-manager-role-name: {{ include "gha-runner-scale-set.managerRoleName" . }}
23-
{{- if and $containerMode (eq $containerMode.type "kubernetes") (not .Values.template.spec.serviceAccountName) }}
23+
{{- if and $containerMode (eq $containerMode.type "kubernetes") (not .Values.runner.serviceAccountName) }}
2424
actions.github.com/cleanup-kubernetes-mode-role-binding-name: {{ include "gha-runner-scale-set.kubeModeRoleBindingName" . }}
2525
actions.github.com/cleanup-kubernetes-mode-role-name: {{ include "gha-runner-scale-set.kubeModeRoleName" . }}
2626
actions.github.com/cleanup-kubernetes-mode-service-account-name: {{ include "gha-runner-scale-set.kubeModeServiceAccountName" . }}
2727
{{- end }}
28-
{{- if and (ne $containerMode.type "kubernetes") (not .Values.template.spec.serviceAccountName) }}
28+
{{- if and (ne $containerMode.type "kubernetes") (not .Values.runner.serviceAccountName) }}
2929
actions.github.com/cleanup-no-permission-service-account-name: {{ include "gha-runner-scale-set.noPermissionServiceAccountName" . }}
3030
{{- end }}
3131
spec:
@@ -95,7 +95,7 @@ spec:
9595
{{- end }}
9696

9797
template:
98-
{{- with .Values.template.metadata }}
98+
{{- with .Values.runner.extraMetadata }}
9999
metadata:
100100
{{- with .labels }}
101101
labels:
@@ -107,60 +107,56 @@ spec:
107107
{{- end }}
108108
{{- end }}
109109
spec:
110-
{{- range $key, $val := .Values.template.spec }}
111-
{{- if and (ne $key "containers") (ne $key "volumes") (ne $key "initContainers") (ne $key "serviceAccountName") }}
112-
{{ $key }}: {{ $val | toYaml | nindent 8 }}
113-
{{- end }}
114-
{{- end }}
115-
{{- if not .Values.template.spec.restartPolicy }}
116-
restartPolicy: Never
117-
{{- end }}
110+
restartPolicy: {{ .Values.runner.restartPolicy }}
118111
{{- $containerMode := .Values.containerMode }}
119112
{{- if eq $containerMode.type "kubernetes" }}
120-
serviceAccountName: {{ default (include "gha-runner-scale-set.kubeModeServiceAccountName" .) .Values.template.spec.serviceAccountName }}
113+
serviceAccountName: {{ default (include "gha-runner-scale-set.kubeModeServiceAccountName" .) .Values.runner.serviceAccountName }}
121114
{{- else }}
122-
serviceAccountName: {{ default (include "gha-runner-scale-set.noPermissionServiceAccountName" .) .Values.template.spec.serviceAccountName }}
115+
serviceAccountName: {{ default (include "gha-runner-scale-set.noPermissionServiceAccountName" .) .Values.runner.serviceAccountName }}
123116
{{- end }}
124-
{{- if or .Values.template.spec.initContainers (eq $containerMode.type "dind") }}
117+
{{- if or (not (empty .Values.runner.extraInitContainers)) (eq $containerMode.type "dind") }}
125118
initContainers:
126119
{{- if eq $containerMode.type "dind" }}
127120
- name: init-dind-externals
128121
{{- include "gha-runner-scale-set.dind-init-container" . | nindent 8 }}
129122
{{- end }}
130-
{{- with .Values.template.spec.initContainers }}
131-
{{- toYaml . | nindent 6 }}
132-
{{- end }}
123+
{{- include "gha-runner-scale-set.extra-init-containers" . | nindent 4 }}
133124
{{- end }}
134125
containers:
135126
{{- if eq $containerMode.type "dind" }}
136127
- name: runner
137128
{{- include "gha-runner-scale-set.dind-runner-container" . | nindent 8 }}
138129
- name: dind
139130
{{- include "gha-runner-scale-set.dind-container" . | nindent 8 }}
140-
{{- include "gha-runner-scale-set.non-runner-non-dind-containers" . | nindent 6 }}
131+
{{- include "gha-runner-scale-set.extra-containers" . | nindent 4 }}
141132
{{- else if eq $containerMode.type "kubernetes" }}
142133
- name: runner
143134
{{- include "gha-runner-scale-set.kubernetes-mode-runner-container" . | nindent 8 }}
144-
{{- include "gha-runner-scale-set.non-runner-containers" . | nindent 6 }}
135+
{{- include "gha-runner-scale-set.extra-containers" . | nindent 4 }}
145136
{{- else }}
146-
{{- include "gha-runner-scale-set.default-mode-runner-containers" . | nindent 6 }}
137+
- name: runner
138+
{{- include "gha-runner-scale-set.default-mode-runner-containers" . | nindent 8 }}
139+
{{- include "gha-runner-scale-set.extra-containers" . | nindent 4 }}
147140
{{- end }}
148141
{{- $tlsConfig := (default (dict) .Values.githubServerTLS) }}
149-
{{- if or .Values.template.spec.volumes (eq $containerMode.type "dind") (eq $containerMode.type "kubernetes") $tlsConfig.runnerMountPath }}
142+
{{- if or .Values.runner.extraVolumes (eq $containerMode.type "dind") (eq $containerMode.type "kubernetes") $tlsConfig.runnerMountPath }}
150143
volumes:
151144
{{- if $tlsConfig.runnerMountPath }}
152145
{{- include "gha-runner-scale-set.tls-volume" $tlsConfig | nindent 6 }}
153146
{{- end }}
154147
{{- if eq $containerMode.type "dind" }}
155148
{{- include "gha-runner-scale-set.dind-volume" . | nindent 6 }}
156149
{{- include "gha-runner-scale-set.dind-work-volume" . | nindent 6 }}
157-
{{- include "gha-runner-scale-set.non-work-volumes" . | nindent 6 }}
150+
{{- include "gha-runner-scale-set.extra-volumes" . | nindent 6 }}
158151
{{- else if eq $containerMode.type "kubernetes" }}
159152
{{- include "gha-runner-scale-set.kubernetes-mode-work-volume" . | nindent 6 }}
160-
{{- include "gha-runner-scale-set.non-work-volumes" . | nindent 6 }}
153+
{{- include "gha-runner-scale-set.extra-volumes" . | nindent 6 }}
161154
{{- else }}
162-
{{- with .Values.template.spec.volumes }}
163-
{{- toYaml . | nindent 6 }}
155+
{{- with .Values.runner.extraVolumes }}
156+
{{- toYaml . | nindent 6 }}
157+
{{- end }}
164158
{{- end }}
165159
{{- end }}
160+
{{- with .Values.runner.extraPodSpec }}
161+
{{- toYaml . | nindent 6 }}
166162
{{- end }}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- $containerMode := .Values.containerMode }}
2-
{{- if and (eq $containerMode.type "kubernetes") (not .Values.template.spec.serviceAccountName) }}
2+
{{- if and (eq $containerMode.type "kubernetes") (not .Values.runner.serviceAccountName) }}
33
# default permission for runner pod service account in kubernetes mode (container hook)
44
apiVersion: rbac.authorization.k8s.io/v1
55
kind: Role

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- $containerMode := .Values.containerMode }}
2-
{{- if and (eq $containerMode.type "kubernetes") (not .Values.template.spec.serviceAccountName) }}
2+
{{- if and (eq $containerMode.type "kubernetes") (not .Values.runner.serviceAccountName) }}
33
apiVersion: rbac.authorization.k8s.io/v1
44
kind: RoleBinding
55
metadata:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- $containerMode := .Values.containerMode }}
2-
{{- if and (eq $containerMode.type "kubernetes") (not .Values.template.spec.serviceAccountName) }}
2+
{{- if and (eq $containerMode.type "kubernetes") (not .Values.runner.serviceAccountName) }}
33
apiVersion: v1
44
kind: ServiceAccount
55
metadata:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- $containerMode := .Values.containerMode }}
2-
{{- if and (ne $containerMode.type "kubernetes") (not .Values.template.spec.serviceAccountName) }}
2+
{{- if and (ne $containerMode.type "kubernetes") (not .Values.runner.serviceAccountName) }}
33
apiVersion: v1
44
kind: ServiceAccount
55
metadata:

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func TestTemplateRenderedUserProvideSetServiceAccount(t *testing.T) {
283283
SetValues: map[string]string{
284284
"githubConfigUrl": "https://github.com/actions",
285285
"githubConfigSecret.github_token": "gh_token12345",
286-
"template.spec.serviceAccountName": "test-service-account",
286+
"runner.serviceAccountName": "test-service-account",
287287
"controllerServiceAccount.name": "arc",
288288
"controllerServiceAccount.namespace": "arc-system",
289289
},
@@ -420,14 +420,14 @@ func TestTemplateRenderedAutoScalingRunnerSet_ProvideMetadata(t *testing.T) {
420420
options := &helm.Options{
421421
Logger: logger.Discard,
422422
SetValues: map[string]string{
423-
"githubConfigUrl": "https://github.com/actions",
424-
"githubConfigSecret.github_token": "gh_token12345",
425-
"template.metadata.labels.test1": "test1",
426-
"template.metadata.labels.test2": "test2",
427-
"template.metadata.annotations.test3": "test3",
428-
"template.metadata.annotations.test4": "test4",
429-
"controllerServiceAccount.name": "arc",
430-
"controllerServiceAccount.namespace": "arc-system",
423+
"githubConfigUrl": "https://github.com/actions",
424+
"githubConfigSecret.github_token": "gh_token12345",
425+
"runner.extraMetadata.labels.test1": "test1",
426+
"runner.extraMetadata.labels.test2": "test2",
427+
"runner.extraMetadata.annotations.test3": "test3",
428+
"runner.extraMetadata.annotations.test4": "test4",
429+
"controllerServiceAccount.name": "arc",
430+
"controllerServiceAccount.namespace": "arc-system",
431431
},
432432
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
433433
}
@@ -1781,7 +1781,7 @@ func TestTemplateRenderedAutoScalingRunnerSet_RestartPolicy(t *testing.T) {
17811781
"githubConfigSecret.github_token": "gh_token12345",
17821782
"controllerServiceAccount.name": "arc",
17831783
"controllerServiceAccount.namespace": "arc-system",
1784-
"template.spec.restartPolicy": "Always",
1784+
"runner.restartPolicy": "Always",
17851785
},
17861786
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
17871787
}

charts/gha-runner-scale-set/tests/values_dind_extra_init_containers.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
githubConfigUrl: https://github.com/actions/actions-runner-controller
22
githubConfigSecret:
33
github_token: test
4-
template:
5-
spec:
6-
initContainers:
4+
runner:
5+
extraInitContainers:
76
- name: kube-init
87
image: runner-image:latest
98
command: ["sudo", "chown", "-R", "1001:123", "/home/runner/_work"]
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
githubConfigUrl: https://github.com/actions/actions-runner-controller
22
githubConfigSecret:
33
github_token: test
4-
template:
5-
spec:
6-
containers:
7-
- name: other
8-
image: other-image:latest
9-
volumes:
10-
- name: foo
11-
emptyDir: {}
12-
- name: bar
13-
emptyDir: {}
14-
- name: work
15-
hostPath:
16-
path: /data
17-
type: Directory
4+
runner:
5+
extraVolumes:
6+
- name: foo
7+
emptyDir: {}
8+
- name: bar
9+
emptyDir: {}
10+
- name: work
11+
hostPath:
12+
path: /data
13+
type: Directory
1814
containerMode:
19-
type: dind
15+
type: dind

charts/gha-runner-scale-set/tests/values_dind_merge_spec.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ githubConfigSecret:
44
template:
55
spec:
66
containers:
7-
- name: runner
7+
runner:
8+
runnerContainer:
89
image: runner-image:latest
9-
env:
10+
extraEnv:
1011
- name: DOCKER_HOST
1112
value: tcp://localhost:9999
1213
- name: MY_NODE_NAME
1314
valueFrom:
1415
fieldRef:
1516
fieldPath: spec.nodeName
16-
volumeMounts:
17+
extraVolumeMounts:
1718
- name: work
1819
mountPath: /work
1920
- name: others
@@ -22,10 +23,10 @@ template:
2223
limits:
2324
memory: "64Mi"
2425
cpu: "250m"
25-
volumes:
26+
extraVolumes:
2627
- name: work
2728
hostPath:
2829
path: /data
2930
type: Directory
3031
containerMode:
31-
type: dind
32+
type: dind

0 commit comments

Comments
 (0)