Use unique name for backup
This commit is contained in:
parent
8d8fe11e6b
commit
e52e28fa3c
|
@ -13,4 +13,12 @@ app.kubernetes.io/name: {{ include "nextcloud.name" . }}-postgres
|
|||
app.kubernetes.io/instance: {{ .Release.Name }}-postgres
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Retrieve postgres backup name
|
||||
This will return a unique name based on revision and chart numbers specified.
|
||||
*/}}
|
||||
{{- define "postgres.backupName" -}}
|
||||
{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}}
|
||||
{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}}
|
||||
{{- end }}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: "postgres-backup-hook-config-map"
|
||||
annotations:
|
||||
rollme: {{ randAlphaNum 5 | quote }}
|
||||
data:
|
||||
entrypoint.sh: |-
|
||||
#!/bin/sh
|
||||
cmd="/docker-entrypoint.sh postgres"
|
||||
eval "${cmd}" & disown;
|
||||
until pg_isready; do
|
||||
sleep 5;
|
||||
done;
|
||||
pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName" . }} > /postgres_backups/$BACKUP_NAME;
|
|
@ -1,19 +1,4 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: "postgres-backup-hook-config-map"
|
||||
data:
|
||||
entrypoint.sh: |-
|
||||
#!/bin/sh
|
||||
cmd="/docker-entrypoint.sh postgres"
|
||||
eval "${cmd}" & disown;
|
||||
until pg_isready; do
|
||||
sleep 5;
|
||||
done;
|
||||
pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName"}} > /postgres_backups/update_dump;
|
||||
|
||||
---
|
||||
|
||||
{{- if .Values.ixChartContext.isUpgrade -}}
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
|
@ -22,6 +7,7 @@ metadata:
|
|||
"helm.sh/hook": pre-upgrade
|
||||
"helm.sh/hook-weight": "1"
|
||||
"helm.sh/hook-delete-policy": hook-succeeded
|
||||
rollme: {{ randAlphaNum 5 | quote }}
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
|
@ -44,6 +30,8 @@ spec:
|
|||
secretKeyRef:
|
||||
name: db-details
|
||||
key: db-password
|
||||
- name: BACKUP_NAME
|
||||
value: {{ template "postgres.backupName" . }}
|
||||
volumeMounts:
|
||||
- name: postgres-data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
|
@ -66,3 +54,4 @@ spec:
|
|||
configMap:
|
||||
defaultMode: 0700
|
||||
name: "postgres-backup-hook-config-map"
|
||||
{{- end -}}
|
||||
|
|
|
@ -49,7 +49,7 @@ spec:
|
|||
- name: POSTGRES_HOST
|
||||
value: {{ template "nextcloud.fullname" . }}-postgres:5432
|
||||
- name: POSTGRES_DB
|
||||
value: {{ template "postgres.DatabaseName" }}
|
||||
value: {{ template "postgres.DatabaseName" . }}
|
||||
- name: POSTGRES_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{{- if .Values.ixChartContext.isUpgrade -}}
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
|
@ -6,6 +7,7 @@ metadata:
|
|||
"helm.sh/hook": pre-upgrade
|
||||
"helm.sh/hook-weight": "-1"
|
||||
"helm.sh/hook-delete-policy": hook-succeeded
|
||||
rollme: {{ randAlphaNum 5 | quote }}
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
|
@ -17,3 +19,4 @@ spec:
|
|||
- name: kubectl
|
||||
image: "bitnami/kubectl:1.19"
|
||||
command: ["kubectl", "delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"]
|
||||
{{- end -}}
|
||||
|
|
Loading…
Reference in New Issue