Update postgres backup configuration to use library chart

This commit is contained in:
Waqar Ahmed committed 2021-02-02 15:14:44 +05:00
1 parent 2733aab5c5
commit e659fc1d17
4 files changed
+39 -44

No files matched your search

+22 -7
View File
@@ -5,18 +5,12 @@ Get Nextloud Postgres Database Name
{{- print "nextcloud" -}}
{{- end -}}
{{/*
Postgres Selector labels
*/}}
{{- define "nextcloud.postgres.selectorLabels" -}}
app.kubernetes.io/name: {{ include "nextcloud.name" . }}-postgres
app.kubernetes.io/instance: {{ .Release.Name }}-postgres
{{- end }}
{{- define "postgres.imageName" -}}
{{- print "postgres:13.1" -}}
{{- end -}}
{{/*
Retrieve postgres backup name
This will return a unique name based on revision and chart numbers specified.
@@ -26,3 +20,24 @@ This will return a unique name based on revision and chart numbers specified.
{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}}
{{- end }}
{{/*
Retrieve postgres credentials for environment variables configuration
*/}}
{{- define "postgres.envVariableConfiguration" -}}
{{ $envList := list }}
{{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user") }}
{{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password") }}
{{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) }}
{{- end -}}
{{/*
Retrieve postgres volume configuration
*/}}
{{- define "postgres.volumeConfiguration" -}}
{{ $vols := list }}
{{ $vols = mustAppend $vols (dict "name" "postgres-data" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" false "pathField" nil "datasetName" (.Values.postgresDataVolume | default dict).datasetName ) }}
{{ $vols = mustAppend $vols (dict "name" "postgres-backup" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" false "pathField" nil "datasetName" (.Values.postgresBackupVolume | default dict).datasetName ) }}
{{ include "common.storage.volumesConfiguration" (dict "ixVolumes" .Values.ixVolumes "volumes" $vols) }}
{{- end -}}
@@ -1,4 +1,6 @@
{{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := . }}
{{ $_ := set $values "nameSuffix" "postgres" }}
apiVersion: batch/v1
kind: Job
metadata:
@@ -14,24 +16,14 @@ spec:
name: "pre-upgrade-hook2"
spec:
restartPolicy: Never
serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}"
serviceAccountName: "{{ template "common.names.serviceAccountName" . }}"
containers:
- name: {{ .Chart.Name }}-postgres-backup
image: {{ template "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: db-details
key: db-user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: db-details
key: db-password
- name: BACKUP_NAME
value: {{ template "postgres.backupName" . }}
env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
- name: BACKUP_NAME
value: {{ template "postgres.backupName" . }}
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
@@ -43,15 +35,9 @@ spec:
subPath: entrypoint.sh
command:
- "/bin/backup_entrypoint.sh"
volumes:
- name: postgres-data
hostPath:
path: {{ template "configuredPostgresHostPath" . }}
- name: postgres-backup
hostPath:
path: {{ template "configuredBackupPostgresHostPath" . }}
- name: backup-script-configmap
configMap:
defaultMode: 0700
name: "postgres-backup-hook-config-map"
volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }}
- name: backup-script-configmap
configMap:
defaultMode: 0700
name: "postgres-backup-hook-config-map"
{{- end -}}
@@ -1,4 +1,6 @@
{{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := . }}
{{ $_ := set $values "nameSuffix" "postgres" }}
apiVersion: batch/v1
kind: Job
metadata:
@@ -14,9 +16,9 @@ spec:
name: "pre-upgrade-hook1"
spec:
restartPolicy: Never
serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}"
serviceAccountName: "{{ template "common.names.serviceAccountName" . }}"
containers:
- name: kubectl
image: "bitnami/kubectl:1.19"
command: ["kubectl", "delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"]
command: ["kubectl", "delete" , "deployment", "{{ template "common.names.fullname" . }}", "{{ template "common.names.fullname" $values }}"]
{{- end -}}
@@ -20,11 +20,7 @@ spec:
- name: {{ .Chart.Name }}-postgres
image: {{ template "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{ $envList := list }}
{{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user") }}
{{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password") }}
{{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }}
env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
@@ -34,8 +30,4 @@ spec:
- name: postgres-tcp
containerPort: 5432
protocol: TCP
volumes:
{{ $vols := list }}
{{ $vols = mustAppend $vols (dict "name" "postgres-data" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" false "pathField" nil "datasetName" (.Values.postgresDataVolume | default dict).datasetName ) }}
{{ $vols = mustAppend $vols (dict "name" "postgres-backup" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" false "pathField" nil "datasetName" (.Values.postgresBackupVolume | default dict).datasetName ) }}
{{ include "common.storage.volumesConfiguration" (dict "ixVolumes" .Values.ixVolumes "volumes" $vols) | nindent 8 }}
volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }}