Skip to content

Commit 289b427

Browse files
committed
feat: ability to create runner templates
Added new field: runnerTemplates Added ability to link pool to runner template using runnerInstallTemplate field
1 parent c27c307 commit 289b427

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

templates/configmap-init-pools.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ data:
6060
{{- if .extraSpec }}
6161
--extra-specs '{{ .extraSpec | toJson }}' \
6262
{{- end }}
63+
{{- if .runnerInstallTemplate }}
64+
--runner-install-template "{{ .runnerInstallTemplate }}" \
65+
{{- end }}
6366
--enabled
6467
{{- end }}
6568
{{- end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if .Values.runnerTemplates }}
2+
{{- range .Values.runnerTemplates }}
3+
{{- if not .path }}
4+
{{- fail (printf "runnerTemplate %q is missing a 'path' attribute." .name) }}
5+
{{- end }}
6+
---
7+
apiVersion: v1
8+
kind: ConfigMap
9+
metadata:
10+
name: "{{ include "garm.fullname" $ }}-template-content-{{ .name }}"
11+
labels:
12+
{{- include "garm.labels" $ | nindent 4 }}
13+
data:
14+
template: |-
15+
{{ $.Files.Get .path | indent 4 }}
16+
{{- end }}
17+
{{- end }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: "{{ include "garm.fullname" . }}-init-templates-script"
5+
labels:
6+
{{- include "garm.labels" . | nindent 4 }}
7+
data:
8+
init-templates.sh: |-
9+
#!/bin/sh
10+
set -e
11+
echo "Configuring GARM templates"
12+
13+
{{- if .Values.runnerTemplates }}
14+
{{- range .Values.runnerTemplates }}
15+
TEMPLATE_NAME="{{ .name }}"
16+
if ! garm-cli template list | grep -wq "${TEMPLATE_NAME}"; then
17+
echo "Creating template ${TEMPLATE_NAME}"
18+
garm-cli template create \
19+
--name "{{ .name }}" \
20+
--forge-type "{{ .forgeType }}" \
21+
--os-type "{{ .osType }}" \
22+
{{- if .description }}
23+
--description "{{ .description }}" \
24+
{{- end }}
25+
--path "/garm-templates/{{ .name }}/template"
26+
else
27+
echo "Template ${TEMPLATE_NAME} already exists."
28+
fi
29+
{{- end }}
30+
{{- end }}
31+

templates/job-operator.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ spec:
3737
configMap:
3838
name: "{{ include "garm.fullname" . }}-init-pools-script"
3939
defaultMode: 0755
40+
- name: init-templates-script
41+
configMap:
42+
name: "{{ include "garm.fullname" . }}-init-templates-script"
43+
defaultMode: 0755
4044
{{- if .Values.forges.gitea.credentials }}
4145
{{- range .Values.forges.gitea.credentials }}
4246
- name: gitea-secret-{{ .name }}
@@ -51,6 +55,13 @@ spec:
5155
secretName: {{ .secretName }}
5256
{{- end }}
5357
{{- end }}
58+
{{- if .Values.runnerTemplates }}
59+
{{- range .Values.runnerTemplates }}
60+
- name: template-content-{{ .name }}
61+
configMap:
62+
name: "{{ include "garm.fullname" $ }}-template-content-{{ .name }}"
63+
{{- end }}
64+
{{- end }}
5465
initContainers:
5566
- name: garm-profile-setup
5667
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
@@ -78,6 +89,28 @@ spec:
7889
mountPath: /init/init-profile.sh
7990
subPath: init-profile.sh
8091

92+
- name: garm-templates
93+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
94+
imagePullPolicy: {{ .Values.image.pullPolicy }}
95+
command: ["/init/init-templates.sh"]
96+
{{- with .Values.resources.configInit }}
97+
resources:
98+
{{- toYaml . | nindent 12 }}
99+
{{- end }}
100+
volumeMounts:
101+
- name: garm-cli-auth
102+
mountPath: /root/.local/share/garm-cli
103+
- name: init-templates-script
104+
mountPath: /init/init-templates.sh
105+
subPath: init-templates.sh
106+
{{- if .Values.runnerTemplates }}
107+
{{- range .Values.runnerTemplates }}
108+
- name: template-content-{{ .name }}
109+
mountPath: /garm-templates/{{ .name }}
110+
readOnly: true
111+
{{- end }}
112+
{{- end }}
113+
81114
- name: garm-credentials
82115
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
83116
imagePullPolicy: {{ .Values.image.pullPolicy }}

values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ persistence:
156156
## -- The size of the PVC.
157157
size: 1Gi
158158

159+
## -- A list of runner templates to create.
160+
## -- NOTE: If you deploy templates and then remove this field then templates will NOT be deleted from GARM server.
161+
## -- This is because templates might be in use by runner pools and tracking all dependencies is not feasible.
162+
runnerTemplates: []
163+
## -- NOTE: The name must be a valid RFC 1123 subdomain name (e.g., 'my-template').
164+
## -- It can only contain lowercase letters, numbers, and hyphens (-).
165+
## -- Underscores (_) are not allowed as the name is used for Kubernetes resources.
166+
# - name: "linux_cache_server"
167+
# description: "Configuring external cache server before runner is started"
168+
# forgeType: "gitea" # or github
169+
# osType: "linux"
170+
# ## -- Path to the file with the template content, relative to the chart root.
171+
# path: "resources/runner-template.sh.tpl"
172+
159173
## -- Configuration for different git forges.
160174
forges:
161175
## -- Gitea server configurations.
@@ -176,6 +190,8 @@ forges:
176190
# credName: "my-gitea"
177191

178192
## -- A list of Gitea runner pools to create.
193+
## -- Pools are re-created on every deployment (e.g helm upgrade) to always match the configuration.
194+
## -- NOTE: Before re-deploying make sure that this pool does not have any runners, otherwise you will get an error.
179195
pools: []
180196
## -- Reference to organization from the 'organizations' list above.
181197
# - orgName: "MyGiteaOrg"
@@ -194,6 +210,8 @@ forges:
194210
# custom_labels:
195211
# my-custom-label: "my-value"
196212
# disable_updates: true
213+
# ## -- The name or ID of the runner install template to use for this pool.
214+
# runnerInstallTemplate: ""
197215

198216
## -- GitHub server configurations.
199217
github:

0 commit comments

Comments
 (0)