Commit e659fc1d authored by Waqar Ahmed's avatar Waqar Ahmed

Update postgres backup configuration to use library chart

parent 2733aab5
...@@ -5,18 +5,12 @@ Get Nextloud Postgres Database Name ...@@ -5,18 +5,12 @@ Get Nextloud Postgres Database Name
{{- print "nextcloud" -}} {{- print "nextcloud" -}}
{{- end -}} {{- 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" -}} {{- define "postgres.imageName" -}}
{{- print "postgres:13.1" -}} {{- print "postgres:13.1" -}}
{{- end -}} {{- end -}}
{{/* {{/*
Retrieve postgres backup name Retrieve postgres backup name
This will return a unique name based on revision and chart numbers specified. 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. ...@@ -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) -}} {{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}}
{{- end }} {{- 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 -}}
{{- if .Values.ixChartContext.isUpgrade -}} {{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := . }}
{{ $_ := set $values "nameSuffix" "postgres" }}
apiVersion: batch/v1 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
...@@ -14,24 +16,14 @@ spec: ...@@ -14,24 +16,14 @@ spec:
name: "pre-upgrade-hook2" name: "pre-upgrade-hook2"
spec: spec:
restartPolicy: Never restartPolicy: Never
serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" serviceAccountName: "{{ template "common.names.serviceAccountName" . }}"
containers: containers:
- name: {{ .Chart.Name }}-postgres-backup - name: {{ .Chart.Name }}-postgres-backup
image: {{ template "postgres.imageName" . }} image: {{ template "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.image.pullPolicy }}
env: env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
- name: POSTGRES_USER - name: BACKUP_NAME
valueFrom: value: {{ template "postgres.backupName" . }}
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" . }}
volumeMounts: volumeMounts:
- name: postgres-data - name: postgres-data
mountPath: /var/lib/postgresql/data mountPath: /var/lib/postgresql/data
...@@ -43,15 +35,9 @@ spec: ...@@ -43,15 +35,9 @@ spec:
subPath: entrypoint.sh subPath: entrypoint.sh
command: command:
- "/bin/backup_entrypoint.sh" - "/bin/backup_entrypoint.sh"
volumes: volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }}
- name: postgres-data - name: backup-script-configmap
hostPath: configMap:
path: {{ template "configuredPostgresHostPath" . }} defaultMode: 0700
- name: postgres-backup name: "postgres-backup-hook-config-map"
hostPath:
path: {{ template "configuredBackupPostgresHostPath" . }}
- name: backup-script-configmap
configMap:
defaultMode: 0700
name: "postgres-backup-hook-config-map"
{{- end -}} {{- end -}}
{{- if .Values.ixChartContext.isUpgrade -}} {{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := . }}
{{ $_ := set $values "nameSuffix" "postgres" }}
apiVersion: batch/v1 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
...@@ -14,9 +16,9 @@ spec: ...@@ -14,9 +16,9 @@ spec:
name: "pre-upgrade-hook1" name: "pre-upgrade-hook1"
spec: spec:
restartPolicy: Never restartPolicy: Never
serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" serviceAccountName: "{{ template "common.names.serviceAccountName" . }}"
containers: containers:
- name: kubectl - name: kubectl
image: "bitnami/kubectl:1.19" 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 -}} {{- end -}}
...@@ -20,11 +20,7 @@ spec: ...@@ -20,11 +20,7 @@ spec:
- name: {{ .Chart.Name }}-postgres - name: {{ .Chart.Name }}-postgres
image: {{ template "postgres.imageName" . }} image: {{ template "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.image.pullPolicy }}
env: env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
{{ $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 }}
volumeMounts: volumeMounts:
- name: postgres-data - name: postgres-data
mountPath: /var/lib/postgresql/data mountPath: /var/lib/postgresql/data
...@@ -34,8 +30,4 @@ spec: ...@@ -34,8 +30,4 @@ spec:
- name: postgres-tcp - name: postgres-tcp
containerPort: 5432 containerPort: 5432
protocol: TCP protocol: TCP
volumes: volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }}
{{ $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 }}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment