Skip to content

Commit 5480733

Browse files
committed
Drupal: Pre-release hook, _installing file improvements
1 parent d6bc5b5 commit 5480733

9 files changed

Lines changed: 160 additions & 6 deletions

drupal/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: drupal
3-
version: 1.30.0
3+
version: 1.31.0
44
dependencies:
55
- name: mariadb
66
version: 7.5.x

drupal/templates/_helpers.tpl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,10 @@ wait
428428
set -e
429429

430430
INSTALLING_FILE="{{ include "drupal.installing-file" . }}"
431-
432431
rm -f "$INSTALLING_FILE" || true
433432

433+
trap 'rm -f "$INSTALLING_FILE" || true' EXIT
434+
434435
{{ if and .Release.IsInstall .Values.referenceData.enabled -}}
435436
{{ include "drupal.import-reference-files" . }}
436437
{{- end }}
@@ -708,6 +709,10 @@ fi
708709
ls -lh /backups/*
709710
{{- end }}
710711
712+
{{- define "drupal.cleanup-job" }}
713+
rm -f "{{ include "drupal.installing-file" . }}" || true
714+
{{- end }}
715+
711716
{{- define "mariadb.db-validation" -}}
712717
713718
set -e
@@ -739,6 +744,24 @@ fi
739744
740745
{{- end }}
741746
747+
{{- define "drupal.pre-release-command" -}}
748+
set -e
749+
750+
{{- include "drupal.wait-for-db-command" . }}
751+
752+
{{- if .Values.elasticsearch.enabled }}
753+
{{ include "drupal.wait-for-elasticsearch-command" . }}
754+
{{ end }}
755+
756+
{{- if .Values.php.preupgrade.backup }}
757+
{{- include "drupal.backup-command" . }}
758+
{{- end }}
759+
760+
{{- if .Values.php.preupgrade.command }}
761+
{{- .Values.php.preupgrade.command }}
762+
{{- end }}
763+
{{- end }}
764+
742765
{{- define "cert-manager.api-version" }}
743766
{{- if ( .Capabilities.APIVersions.Has "cert-manager.io/v1" ) }}
744767
cert-manager.io/v1

drupal/templates/backup-volume.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.backup.enabled }}
1+
{{- if or .Values.backup.enabled ( or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup ) }}
22
{{- if eq .Values.backup.storageClassName "silta-shared" }}
33
{{- if eq ( include "silta-cluster.rclone.has-provisioner" $ ) "false" }}
44
apiVersion: v1

drupal/templates/drupal-configmap.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ data:
834834
835835
# Prevent requests during the site installation process.
836836
if [ {{ include "drupal.installation-in-progress-test" $ }} ]; then
837+
PID=$(pgrep -o php-fpm || true)
838+
if [ -n "$PID" ]; then
839+
echo "Installation in progress, failing health check." > /proc/$PID/fd/2;
840+
fi
837841
exit 1;
838842
fi
839843
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: "{{ .Release.Name }}-cleanup"
5+
labels:
6+
{{- include "drupal.release_labels" . | nindent 4 }}
7+
spec:
8+
ttlSecondsAfterFinished: 0
9+
template:
10+
metadata:
11+
labels:
12+
{{- include "drupal.release_labels" . | nindent 8 }}
13+
spec:
14+
enableServiceLinks: false
15+
restartPolicy: Never
16+
containers:
17+
- name: cleanup
18+
{{- include "drupal.php-container" . | nindent 8 }}
19+
command: ["/bin/bash", "-c"]
20+
args:
21+
- |
22+
{{- include "drupal.cleanup-job" . | nindent 12 }}
23+
volumeMounts:
24+
{{- include "drupal.volumeMounts" . | nindent 12 }}
25+
serviceAccountName: {{ include "drupal.serviceAccountName" . }}
26+
volumes:
27+
{{- include "drupal.volumes" . | nindent 8 }}

drupal/templates/pre-release.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{{- if or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup }}
2+
{{- $claimName := printf "%s-backup" .Release.Name }}
3+
{{- if and ( eq $.Values.backup.storageClassName "silta-shared" ) ( eq ( include "silta-cluster.rclone.has-provisioner" $ ) "true" ) }}
4+
{{- $claimName = printf "%s-backup2" .Release.Name }}
5+
{{- end }}
6+
{{- if lookup "v1" "PersistentVolumeClaim" .Release.Namespace $claimName }}
7+
apiVersion: batch/v1
8+
kind: Job
9+
metadata:
10+
name: "{{ .Release.Name }}-pre-release"
11+
labels:
12+
{{- include "drupal.release_labels" . | nindent 4 }}
13+
annotations:
14+
# This is what defines this resource as a hook. Without this line, the
15+
# job is considered part of the release.
16+
"helm.sh/hook": "pre-upgrade"
17+
"helm.sh/hook-delete-policy": "before-hook-creation"
18+
spec:
19+
completions: 1
20+
backoffLimit: 0
21+
template:
22+
metadata:
23+
labels:
24+
{{- include "drupal.release_labels" . | nindent 8 }}
25+
spec:
26+
restartPolicy: Never
27+
enableServiceLinks: false
28+
containers:
29+
- name: pre-release
30+
{{- include "drupal.php-container" . | nindent 8 }}
31+
command: ["/bin/bash", "-c"]
32+
args:
33+
- |
34+
{{- include "drupal.pre-release-command" . | nindent 12 }}
35+
volumeMounts:
36+
{{- include "drupal.volumeMounts" . | nindent 10 }}
37+
{{- if .Values.php.preupgrade.backup }}
38+
- name: {{ .Release.Name }}-backup
39+
mountPath: /backups
40+
{{- end }}
41+
resources:
42+
{{- .Values.php.preupgrade.resources | toYaml | nindent 10 }}
43+
nodeSelector:
44+
{{- .Values.php.preupgrade.nodeSelector | toYaml | nindent 8 }}
45+
tolerations:
46+
{{- include "drupal.tolerations" .Values.php.preupgrade.nodeSelector | nindent 8 }}
47+
serviceAccountName: {{ include "drupal.serviceAccountName" . }}
48+
volumes:
49+
{{- include "drupal.volumes" . | nindent 8 }}
50+
{{- if .Values.php.preupgrade.backup }}
51+
- name: {{ .Release.Name }}-backup
52+
persistentVolumeClaim:
53+
{{- if and ( eq $.Values.backup.storageClassName "silta-shared" ) ( eq ( include "silta-cluster.rclone.has-provisioner" $ ) "true" ) }}
54+
claimName: {{ .Release.Name }}-backup2
55+
{{- else }}
56+
claimName: {{ .Release.Name }}-backup
57+
{{- end }}
58+
{{- end }}
59+
{{- end }}
60+
{{- end }}

drupal/templates/shell-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ spec:
6161
mountPath: /etc/ssh/authorized_keys
6262
subPath: authorizedKeys
6363
readOnly: true
64-
{{- if .Values.backup.enabled }}
64+
{{- if or .Values.backup.enabled ( or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup ) }}
6565
- name: {{ .Release.Name }}-backup
6666
mountPath: /backups
6767
readOnly: true
@@ -119,7 +119,7 @@ spec:
119119
- name: shell-configmap
120120
configMap:
121121
name: {{ .Release.Name }}-shell
122-
{{- if .Values.backup.enabled }}
122+
{{- if or .Values.backup.enabled ( or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup ) }}
123123
- name: {{ .Release.Name }}-backup
124124
persistentVolumeClaim:
125125
{{- if and ( eq $.Values.backup.storageClassName "silta-shared" ) ( eq ( include "silta-cluster.rclone.has-provisioner" $ ) "true" ) }}

drupal/values.schema.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,35 @@
366366
}
367367
}
368368
},
369+
"preupgrade": {
370+
"type": "object",
371+
"additionalProperties": false,
372+
"properties": {
373+
"backup": { "type": "boolean" },
374+
"command": { "type": "string" },
375+
"nodeSelector": { "type": "object" },
376+
"resources": {
377+
"type": "object",
378+
"additionalProperties": false,
379+
"properties": {
380+
"requests": {
381+
"type": "object",
382+
"properties": {
383+
"cpu": { "type": ["integer", "string"] },
384+
"memory": { "type": "string" }
385+
}
386+
},
387+
"limits": {
388+
"type": "object",
389+
"properties": {
390+
"cpu": { "type": ["integer", "string"] },
391+
"memory": { "type": "string" }
392+
}
393+
}
394+
}
395+
}
396+
}
397+
},
369398
"postupgrade": {
370399
"type": "object",
371400
"additionalProperties": false,
@@ -582,7 +611,7 @@
582611
}
583612
}
584613
}
585-
},
614+
},
586615
"mariadb": {
587616
"type": "object",
588617
"properties": {

drupal/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ php:
363363
afterCommand: |
364364
365365
366+
# Executes before the environment is installed. Could be useful for backups before environment is upgraded.
367+
preupgrade:
368+
backup: false
369+
command: ""
370+
resources:
371+
requests:
372+
cpu: 500m
373+
memory: 488Mi
374+
limits:
375+
memory: 488Mi
376+
366377
# Pass additional environment variables to all php containers as key-value pairs.
367378
env: {}
368379

0 commit comments

Comments
 (0)