1- {{- if .Values.pvc_enabled }}
2- ---
3- # Persistent Volumes can be used for image caching
4- apiVersion : v1
5- kind : PersistentVolumeClaim
6- metadata :
7- name : {{ .Values.release_name }}
8- spec :
9- accessModes :
10- - ReadWriteMany
11- # StorageClassName comes from efs-controller and must be deployed first.
12- storageClassName : efs-sc
13- resources :
14- requests :
15- # EFS is not actually storage constrained, but this storage request is
16- # required. 100Gi is a ballpark for how much we initially request, but this
17- # may grow. We are responsible for docker pruning this periodically to
18- # save space.
19- storage : 100Gi
20- {{- end }}
21- {{- if .Values.docker_config_json_enabled }}
22- ---
23- apiVersion : v1
24- kind : Secret
25- metadata :
26- name : {{ .Values.release_name }}-regcred
27- type : kubernetes.io/dockerconfigjson
28- data :
29- .dockerconfigjson : {{ .Values.docker_config_json }}
30- {{- end }}
31- ---
321apiVersion : actions.summerwind.dev/v1alpha1
332kind : RunnerDeployment
343metadata :
387 # See https://github.com/actions-runner-controller/actions-runner-controller/issues/206#issuecomment-748601907
398 # replicas: 1
409 template :
41- {{- with index .Values " pod_annotations" }}
10+ {{- with .Values. pod_annotations }}
4211 metadata :
4312 annotations :
4413 {{- toYaml . | nindent 8 }}
4514 {{- end }}
4615 spec :
47- {{- if .Values.docker_config_json_enabled }}
16+ {{- if .Values.docker_config_json_enabled }}
4817 # secrets volumeMount are always mounted readOnly so config.json has to be copied to the correct directory
4918 # https://github.com/kubernetes/kubernetes/issues/62099
5019 # https://github.com/actions/actions-runner-controller/issues/2123#issuecomment-1527077517
@@ -82,14 +51,41 @@ spec:
8251 # - effect: NoSchedule
8352 # key: node-role.kubernetes.io/actions-runner
8453 # operator: Exists
54+ {{- with .Values.node_selector }}
55+ nodeSelector :
56+ {{- toYaml . | nindent 8 }}
57+ {{- end }}
58+ {{- with .Values.tolerations }}
59+ tolerations :
60+ {{- toYaml . | nindent 8 }}
61+ {{- end }}
62+ {{- with .Values.affinity }}
63+ affinity :
64+ {{- toYaml . | nindent 8 }}
65+ {{- end }}
66+
67+ {{- with .Values.running_pod_annotations }}
68+ # Run a pre-run hook to set pod annotations
69+ # See https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job#triggering-the-scripts
70+ containers :
71+ - name : runner
72+ # ARC (Summerwind) has its own pre-run hook, so we do not want to set
73+ # env:
74+ # - name: ACTIONS_RUNNER_HOOK_JOB_STARTED
75+ # value: /hooks/pre-run.sh # triggers when a job is started, and sets the pod to NOT safe-to-evict
76+ # Instead, its pre-run hook runs scripts in /etc/arc/hooks/job-started.d/
77+ volumeMounts :
78+ - name : hooks
79+ mountPath : /etc/arc/hooks/job-started.d/
80+ {{- end }}
8581
86- {{ if eq .Values.type "organization" }}
82+ {{- if eq .Values.type "organization" }}
8783 organization : {{ .Values.scope }}
8884 {{- end }}
89- {{ if eq .Values.type "repository" }}
85+ {{- if eq .Values.type "repository" }}
9086 repository : {{ .Values.scope }}
9187 {{- end }}
92- {{ if index .Values "group" }}
88+ {{- if index .Values "group" }}
9389 group : {{ .Values.group }}
9490 {{- end }}
9591 # You can use labels to create subsets of runners.
@@ -103,14 +99,6 @@ spec:
10399 {{- range .Values.labels }}
104100 - {{ . | quote }}
105101 {{- end }}
106- {{- if gt ( len (index .Values "node_selector") ) 0 }}
107- nodeSelector :
108- {{- toYaml .Values.node_selector | nindent 8 }}
109- {{- end }}
110- {{- if gt ( len (index .Values "tolerations") ) 0 }}
111- tolerations :
112- {{- toYaml .Values.tolerations | nindent 8 }}
113- {{- end }}
114102 # dockerdWithinRunnerContainer = false means access to a Docker daemon is provided by a sidecar container.
115103 dockerdWithinRunnerContainer : {{ .Values.dind_enabled }}
116104 image : {{ .Values.image | quote }}
@@ -133,7 +121,7 @@ spec:
133121 {{- if index .Values.resources.requests "ephemeral_storage" }}
134122 ephemeral-storage : {{ .Values.resources.requests.ephemeral_storage }}
135123 {{- end }}
136- {{- if and .Values.dind_enabled .Values.storage }}
124+ {{- if and .Values.dind_enabled .Values.docker_storage }}
137125 dockerVolumeMounts :
138126 - mountPath : /var/lib/docker
139127 name : docker-volume
@@ -150,24 +138,24 @@ spec:
150138 - mountPath : /home/runner/.docker
151139 name : docker-config-volume
152140 {{- end }}
153- {{- end }}
154- {{- if or (and .Values.dind_enabled .Values.storage ) (.Values.pvc_enabled) (.Values.docker_config_json_enabled) }}
141+ {{- end }}{{/* End of volumeMounts */}}
142+ {{- if or (and .Values.dind_enabled .Values.docker_storage ) (.Values.pvc_enabled) (.Values.docker_config_json_enabled) (not (empty .Values.running_pod_annotations) ) }}
155143 volumes :
156- {{- if and .Values.dind_enabled .Values.storage }}
144+ {{- if and .Values.dind_enabled .Values.docker_storage }}
157145 - name : docker-volume
158146 ephemeral :
159147 volumeClaimTemplate :
160148 spec :
161149 accessModes : [ "ReadWriteOnce" ] # Only 1 pod can connect at a time
162150 resources :
163151 requests :
164- storage : {{ .Values.storage }}
165- {{- end }}
166- {{- if .Values.pvc_enabled }}
152+ storage : {{ .Values.docker_storage }}
153+ {{- end }}
154+ {{- if .Values.pvc_enabled }}
167155 - name : shared-volume
168156 persistentVolumeClaim :
169157 claimName : {{ .Values.release_name }}
170- {{- end }}
158+ {{- end }}
171159 {{- if .Values.docker_config_json_enabled }}
172160 - name : docker-secret
173161 secret :
@@ -178,4 +166,88 @@ spec:
178166 - name : docker-config-volume
179167 emptyDir :
180168 {{- end }}
181- {{- end }}
169+ {{- with .Values.running_pod_annotations }}
170+ - name : hooks
171+ configMap :
172+ name : runner-hooks
173+ defaultMode : 0755 # Set execute permissions for all files
174+ {{- end }}
175+ {{- end }}{{/* End of volumes */}}
176+ {{- if .Values.pvc_enabled }}
177+ ---
178+ # Persistent Volumes can be used for image caching
179+ apiVersion : v1
180+ kind : PersistentVolumeClaim
181+ metadata :
182+ name : {{ .Values.release_name }}
183+ spec :
184+ accessModes :
185+ - ReadWriteMany
186+ # StorageClassName comes from efs-controller and must be deployed first.
187+ storageClassName : efs-sc
188+ resources :
189+ requests :
190+ # EFS is not actually storage constrained, but this storage request is
191+ # required. 100Gi is a ballpark for how much we initially request, but this
192+ # may grow. We are responsible for docker pruning this periodically to
193+ # save space.
194+ storage : 100Gi
195+ {{- end }}
196+ {{- if .Values.docker_config_json_enabled }}
197+ ---
198+ apiVersion : v1
199+ kind : Secret
200+ metadata :
201+ name : {{ .Values.release_name }}-regcred
202+ type : kubernetes.io/dockerconfigjson
203+ data :
204+ .dockerconfigjson : {{ .Values.docker_config_json }}
205+ {{- end }}
206+ {{- with .Values.running_pod_annotations }}
207+ ---
208+ apiVersion : v1
209+ kind : ConfigMap
210+ metadata :
211+ name : runner-hooks
212+ data :
213+ annotate.sh : |
214+ #!/bin/bash
215+
216+ # If we had kubectl and a KUBECONFIG, we could do this:
217+ # kubectl annotate pod $HOSTNAME 'karpenter.sh/do-not-evict="true"' --overwrite
218+ # kubectl annotate pod $HOSTNAME 'karpenter.sh/do-not-disrupt="true"' --overwrite
219+
220+ # This is the same thing, the hard way
221+
222+ # Metadata about the pod
223+ NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
224+ POD_NAME=$(hostname)
225+
226+ # Kubernetes API URL
227+ API_URL="https://kubernetes.default.svc"
228+
229+ # Read the service account token
230+ TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
231+
232+ # Content type
233+ CONTENT_TYPE="application/merge-patch+json"
234+
235+ PATCH_JSON=$(cat <<EOF
236+ {
237+ "metadata": {
238+ "annotations":
239+ {{- . | toJson | nindent 10 }}
240+ }
241+ }
242+ EOF
243+ )
244+
245+ # Use curl to patch the pod
246+ curl -sSk -X PATCH \
247+ -H "Authorization: Bearer $TOKEN" \
248+ -H "Content-Type: $CONTENT_TYPE" \
249+ -H "Accept: application/json" \
250+ -d "$PATCH_JSON" \
251+ "$API_URL/api/v1/namespaces/$NAMESPACE/pods/$POD_NAME" | jq .metadata.annotations
252+
253+ {{ end }}
0 commit comments