Skip to content

Pre-release hook #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -672,6 +672,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 @@ -60,7 +60,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 @@ -91,7 +91,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 @@ -342,6 +342,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 @@ -549,7 +578,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 @@ -352,6 +352,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 @@ -55,3 +55,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'"