Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions charts/drupal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,24 @@ fi

{{- end }}

{{- define "drupal.pre-release-command" -}}
set -e

{{- include "drupal.wait-for-db-command" . }}

{{- if .Values.elasticsearch.enabled }}
{{ include "drupal.wait-for-elasticsearch-command" . }}
{{ end }}

{{- if .Values.php.preupgrade.backup }}
{{- include "drupal.backup-command" . }}
{{- end }}

{{- if .Values.php.preupgrade.command }}
{{- .Values.php.preupgrade.command }}
{{- end }}
{{- end }}

{{- define "cert-manager.api-version" }}
{{- if ( .Capabilities.APIVersions.Has "cert-manager.io/v1" ) }}
cert-manager.io/v1
Expand Down
2 changes: 1 addition & 1 deletion charts/drupal/templates/backup-volume.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.backup.enabled }}
{{- if or .Values.backup.enabled ( or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup ) }}
{{- if eq .Values.backup.storageClassName "silta-shared" }}
{{- if eq ( include "silta-cluster.rclone.has-provisioner" $ ) "false" }}
apiVersion: v1
Expand Down
60 changes: 60 additions & 0 deletions charts/drupal/templates/pre-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{- if or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup }}
{{- $claimName := printf "%s-backup" .Release.Name }}
{{- if and ( eq $.Values.backup.storageClassName "silta-shared" ) ( eq ( include "silta-cluster.rclone.has-provisioner" $ ) "true" ) }}
{{- $claimName = printf "%s-backup2" .Release.Name }}
{{- end }}
{{- if lookup "v1" "PersistentVolumeClaim" .Release.Namespace $claimName }}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-pre-release"
labels:
{{- include "drupal.release_labels" . | nindent 4 }}
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": "pre-upgrade"
"helm.sh/hook-delete-policy": "before-hook-creation"
spec:
completions: 1
backoffLimit: 0
template:
metadata:
labels:
{{- include "drupal.release_labels" . | nindent 8 }}
spec:
restartPolicy: Never
enableServiceLinks: false
containers:
- name: pre-release
{{- include "drupal.php-container" . | nindent 8 }}
command: ["/bin/bash", "-c"]
args:
- |
{{- include "drupal.pre-release-command" . | nindent 12 }}
volumeMounts:
{{- include "drupal.volumeMounts" . | nindent 10 }}
{{- if .Values.php.preupgrade.backup }}
- name: {{ .Release.Name }}-backup
mountPath: /backups
{{- end }}
resources:
{{- .Values.php.preupgrade.resources | toYaml | nindent 10 }}
nodeSelector:
{{- .Values.php.preupgrade.nodeSelector | toYaml | nindent 8 }}
tolerations:
{{- include "drupal.tolerations" .Values.php.preupgrade.nodeSelector | nindent 8 }}
serviceAccountName: {{ include "drupal.serviceAccountName" . }}
volumes:
{{- include "drupal.volumes" . | nindent 8 }}
{{- if .Values.php.preupgrade.backup }}
- name: {{ .Release.Name }}-backup
persistentVolumeClaim:
{{- if and ( eq $.Values.backup.storageClassName "silta-shared" ) ( eq ( include "silta-cluster.rclone.has-provisioner" $ ) "true" ) }}
claimName: {{ .Release.Name }}-backup2
{{- else }}
claimName: {{ .Release.Name }}-backup
{{- end }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 2 additions & 2 deletions charts/drupal/templates/shell-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ spec:
mountPath: /etc/ssh/authorized_keys
subPath: authorizedKeys
readOnly: true
{{- if .Values.backup.enabled }}
{{- if or .Values.backup.enabled ( or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup ) }}
- name: {{ .Release.Name }}-backup
mountPath: /backups
readOnly: true
Expand Down Expand Up @@ -119,7 +119,7 @@ spec:
- name: shell-configmap
configMap:
name: {{ .Release.Name }}-shell
{{- if .Values.backup.enabled }}
{{- if or .Values.backup.enabled ( or (ne .Values.php.preupgrade.command "") .Values.php.preupgrade.backup ) }}
- name: {{ .Release.Name }}-backup
persistentVolumeClaim:
{{- if and ( eq $.Values.backup.storageClassName "silta-shared" ) ( eq ( include "silta-cluster.rclone.has-provisioner" $ ) "true" ) }}
Expand Down
31 changes: 30 additions & 1 deletion charts/drupal/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,35 @@
}
}
},
"preupgrade": {
"type": "object",
"additionalProperties": false,
"properties": {
"backup": { "type": "boolean" },
"command": { "type": "string" },
"nodeSelector": { "type": "object" },
"resources": {
"type": "object",
"additionalProperties": false,
"properties": {
"requests": {
"type": "object",
"properties": {
"cpu": { "type": ["integer", "string"] },
"memory": { "type": "string" }
}
},
"limits": {
"type": "object",
"properties": {
"cpu": { "type": ["integer", "string"] },
"memory": { "type": "string" }
}
}
}
}
}
},
"postupgrade": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -572,7 +601,7 @@
}
}
}
},
},
"mariadb": {
"type": "object",
"properties": {
Expand Down
11 changes: 11 additions & 0 deletions charts/drupal/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ php:
afterCommand: |


# Executes before the environment is installed. Could be useful for backups before environment is upgraded.
preupgrade:
backup: false
command: ""
resources:
requests:
cpu: 500m
memory: 488Mi
limits:
memory: 488Mi

# Pass additional environment variables to all php containers as key-value pairs.
env: {}

Expand Down
6 changes: 6 additions & 0 deletions silta/silta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ php:
# The ~ symbol will be replaced by a random digit from 0 to 9.
# This will avoid running all cron jobs at the same time.
schedule: '~ 0 31 2 *'

php:
preupgrade:
# backup: true
command: "echo 'Pre-upgrade command'"