Skip to content

Commit 234e352

Browse files
authored
Helm chart: Add option to create PVC for local configuration path (#3761)
* Add option to create PVC for local configuration path This enables persistence for deployment with local sqlite database. * ignore persistence option when DB url is set
1 parent 27169d1 commit 234e352

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{- if and .Values.zenml.database.persistence.enabled (not .Values.zenml.database.url) }}
2+
{{- $pvc_name := printf "%s-config" (include "zenml.fullname" .) -}}
3+
{{- $pvc := (lookup "v1" "PersistentVolumeClaim" .Release.Namespace $pvc_name) }}
4+
{{- if not $pvc }}
5+
apiVersion: v1
6+
kind: PersistentVolumeClaim
7+
metadata:
8+
name: {{ $pvc_name }}
9+
labels:
10+
{{- include "zenml.labels" . | nindent 4 }}
11+
annotations:
12+
"helm.sh/hook": "pre-install,pre-upgrade"
13+
"helm.sh/hook-weight": "-1"
14+
"helm.sh/hook-delete-policy": before-hook-creation
15+
spec:
16+
{{- with .Values.zenml.database.persistence.storageClassName }}
17+
storageClassName: {{.}}
18+
{{- end }}
19+
accessModes:
20+
- ReadWriteOnce
21+
resources:
22+
requests:
23+
storage: {{.Values.zenml.database.persistence.size}}
24+
{{- end }}
25+
{{- end }}

helm/templates/server-db-job.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ spec:
5959
{{- toYaml .Values.podSecurityContext | nindent 8 }}
6060
volumes:
6161
- name: zenml-config
62+
{{- if and .Values.zenml.database.persistence.enabled (not .Values.zenml.database.url) }}
63+
persistentVolumeClaim:
64+
claimName: {{ include "zenml.fullname" . }}-config
65+
{{- else }}
6266
emptyDir: {}
67+
{{- end }}
6368
{{- if eq .Values.zenml.database.backupStrategy "dump-file" }}
6469
# define a volume that will hold a backup of the database
6570
- name: db-backup
@@ -227,4 +232,4 @@ spec:
227232
nodeSelector:
228233
{{- toYaml . | nindent 8 }}
229234
{{- end }}
230-
{{- end }}
235+
{{- end }}

helm/templates/server-db-pvc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ spec:
2222
storageClassName: {{ . }}
2323
{{- end }}
2424
{{- end }}
25-
{{- end }}
25+
{{- end }}

helm/templates/server-deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ spec:
5959
{{- toYaml .Values.podSecurityContext | nindent 8 }}
6060
volumes:
6161
- name: zenml-config
62+
{{- if and .Values.zenml.database.persistence.enabled (not .Values.zenml.database.url) }}
63+
persistentVolumeClaim:
64+
claimName: {{ include "zenml.fullname" . }}-config
65+
{{- else }}
6266
emptyDir: {}
67+
{{- end }}
6368
{{- if or .Values.zenml.certificates.customCAs .Values.zenml.certificates.secretRefs }}
6469
- name: custom-certs
6570
projected:

helm/values.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,19 @@ zenml:
306306
enableImplicitAuthMethods: false
307307

308308
# MySQL database configuration. If not set, a local sqlite database will be
309-
# used, which will not be persisted across pod restarts.
309+
# used. To ensure data are not lost, check the persistence part.
310310
# NOTE: the certificate files need to be copied in the helm chart folder and
311311
# the paths configured here need to be relative to the root of the helm chart.
312312
database:
313313

314+
# If set to true, path where the local database is created will be
315+
# mounted as a persistent volume so the data is not lost on pod restarts.
316+
# Only relevant for local sqlite database.
317+
persistence:
318+
enabled: false
319+
size: 1Gi
320+
storageClassName: ""
321+
314322
# The database URL. If not set, a local sqlite database will be used, which
315323
# will not be persisted across pod restarts. The URL can contain the
316324
# password or it can be provided in a secret using the `passwordSecretRef`

0 commit comments

Comments
 (0)