Skip to content

Commit aae281f

Browse files
committed
build(helm): handle auto-scaling volume claim access mode
1 parent ad724a3 commit aae281f

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

install/kubernetes/github-actions-cache-server/templates/_helpers.tpl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,40 @@ Otherwise, auto-enable when storage driver is "filesystem" or db driver is "sqli
8181
{{- end -}}
8282
{{- end }}
8383

84+
{{/*
85+
Check if multiple replicas are possible (autoscaling enabled or replicaCount > 1).
86+
*/}}
87+
{{- define "github-actions-cache-server.multipleReplicas" -}}
88+
{{- if or (and .Values.autoscaling.enabled (gt (.Values.autoscaling.maxReplicas | int) 1)) (gt (.Values.replicaCount | int) 1) -}}
89+
true
90+
{{- else -}}
91+
false
92+
{{- end -}}
93+
{{- end }}
94+
95+
{{/*
96+
Effective PVC access modes.
97+
Automatically switches to ReadWriteMany when multiple replicas are possible
98+
and the filesystem storage driver is used, to prevent errors when multiple
99+
pods attach to the same volume.
100+
*/}}
101+
{{- define "github-actions-cache-server.pvcAccessModes" -}}
102+
{{- if and (eq (include "github-actions-cache-server.multipleReplicas" .) "true") (eq .Values.config.storage.driver "filesystem") -}}
103+
- ReadWriteMany
104+
{{- else -}}
105+
{{ toYaml .Values.persistentVolumeClaim.accessModes }}
106+
{{- end -}}
107+
{{- end }}
108+
109+
{{/*
110+
Validate configuration. Fails if incompatible settings are detected.
111+
*/}}
112+
{{- define "github-actions-cache-server.validate" -}}
113+
{{- if and (eq .Values.config.db.driver "sqlite") (eq (include "github-actions-cache-server.multipleReplicas" .) "true") -}}
114+
{{- fail "SQLite database driver cannot be used with multiple replicas (autoscaling enabled or replicaCount > 1). SQLite does not support concurrent access from multiple pods. Please switch to 'postgres' or 'mysql' database driver." -}}
115+
{{- end -}}
116+
{{- end }}
117+
84118
{{/*
85119
Generate environment variables from config values.
86120
*/}}

install/kubernetes/github-actions-cache-server/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{ $name := include "github-actions-cache-server.fullname" . }}
22
{{ $pvcEnabled := include "github-actions-cache-server.pvcEnabled" . }}
3+
{{- include "github-actions-cache-server.validate" . -}}
34
---
45
apiVersion: apps/v1
56
kind: Deployment

install/kubernetes/github-actions-cache-server/templates/persistentvolumeclaim.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ metadata:
1616
{{- end }}
1717
spec:
1818
accessModes:
19-
{{- toYaml .Values.persistentVolumeClaim.accessModes | nindent 4 }}
19+
{{- include "github-actions-cache-server.pvcAccessModes" . | nindent 4 }}
2020
resources:
2121
requests:
2222
storage: {{ .Values.persistentVolumeClaim.storage }}

install/kubernetes/github-actions-cache-server/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,19 @@ autoscaling:
203203
# -- Persistent volume claim for data storage.
204204
# Automatically enabled when using filesystem storage or sqlite database driver.
205205
# Can be manually overridden with persistentVolumeClaim.enabled = true/false.
206+
#
207+
# NOTE: When using autoscaling (or replicaCount > 1) with the filesystem storage
208+
# driver, accessModes is automatically switched to ReadWriteMany so that multiple
209+
# pods can attach to the same volume. If you need a different access mode, set it
210+
# explicitly below.
211+
#
212+
# SQLite cannot be used with multiple replicas and will produce an install error.
206213
persistentVolumeClaim:
207214
# -- Set to true/false to explicitly enable/disable. If not set, automatically
208215
# enabled when storage.driver is "filesystem" or db.driver is "sqlite".
209216
enabled: null
217+
# -- Access modes for the PVC. Automatically changed to ReadWriteMany when
218+
# the filesystem storage driver is used with multiple replicas.
210219
accessModes:
211220
- ReadWriteOnce
212221
storage: 20Gi

0 commit comments

Comments
 (0)