|
@@ -18,6 +18,7 @@ backupChownMode (optional): Whether to chown the backup directory or
|
|
|
{{- $backupChownMode := .backupChownMode | default "check" -}}
|
|
|
{{- $ixChartContext := .ixChartContext -}}
|
|
|
{{- $resources := (required "Postgres - Resources are required" .resources) }}
|
|
|
+
|
|
|
{{ $name }}:
|
|
|
enabled: true
|
|
|
type: Deployment
|
|
@@ -61,20 +62,25 @@ backupChownMode (optional): Whether to chown the backup directory or
|
|
|
- -c
|
|
|
- "until pg_isready -U ${POSTGRES_USER} -h localhost; do sleep 2; done"
|
|
|
initContainers:
|
|
|
- {{- include "ix.v1.common.app.permissions" (dict "UID" 999 "GID" 999) | nindent 6 }}
|
|
|
-{{- $enableBackupJob := false -}}
|
|
|
-{{- if hasKey $ixChartContext "isUpgrade" -}}
|
|
|
- {{- if $ixChartContext.isUpgrade -}}
|
|
|
+ {{- include "ix.v1.common.app.permissions"
|
|
|
+ (dict
|
|
|
+ "UID" 999
|
|
|
+ "GID" 999
|
|
|
+ "type" "install"
|
|
|
+ "containerName" "permissions"
|
|
|
+ ) | nindent 6 }}
|
|
|
+
|
|
|
+ {{- $enableBackupJob := false -}}
|
|
|
+ {{- if hasKey $ixChartContext "isUpgrade" -}}
|
|
|
+ {{- if $ixChartContext.isUpgrade -}}
|
|
|
+ {{- $enableBackupJob = true -}}
|
|
|
+ {{- end -}}
|
|
|
+ {{- else -}}
|
|
|
+ {{/* If the key is not present in ixChartContext, means we
|
|
|
+ are outside SCALE (Probably CI), let upgrade job run */}}
|
|
|
{{- $enableBackupJob = true -}}
|
|
|
- {{- end -}}
|
|
|
-{{- else -}}
|
|
|
- {{/*
|
|
|
- If the key is not present in ixChartContext,
|
|
|
- means we are outside SCALE (Probably CI),
|
|
|
- let upgrade job run
|
|
|
- */}}
|
|
|
- {{- $enableBackupJob = true -}}
|
|
|
-{{- end }}
|
|
|
+ {{- end }}
|
|
|
+
|
|
|
postgresbackup:
|
|
|
enabled: {{ $enableBackupJob }}
|
|
|
type: Job
|
|
@@ -116,7 +122,14 @@ postgresbackup:
|
|
|
pg_dump --dbname=${POSTGRES_URL} --file {{ $backupPath }}/${POSTGRES_DB}_$(date +%Y-%m-%d_%H-%M-%S).sql || echo "Failed to create backup"
|
|
|
echo "Backup finished"
|
|
|
initContainers:
|
|
|
- {{- include "ix.v1.common.app.permissions" (dict "UID" 999 "GID" 999 "type" "init" "mode" $backupChownMode) | nindent 6 }}
|
|
|
+ {{- include "ix.v1.common.app.permissions"
|
|
|
+ (dict
|
|
|
+ "UID" 999
|
|
|
+ "GID" 999
|
|
|
+ "type" "init"
|
|
|
+ "mode" $backupChownMode
|
|
|
+ "containerName" "permissions"
|
|
|
+ ) | nindent 6 }}
|
|
|
{{- end -}}
|
|
|
|
|
|
{{/* Returns a postgres-wait container for waiting for postgres to be ready */}}
|
|
@@ -130,6 +143,7 @@ secretName (required): Name of the secret containing the postgres credentials
|
|
|
{{- define "ix.v1.common.app.postgresWait" -}}
|
|
|
{{- $name := .name | default "postgres-wait" -}}
|
|
|
{{- $secretName := (required "Postgres-Wait - Secret Name is required" .secretName) }}
|
|
|
+
|
|
|
{{ $name }}:
|
|
|
enabled: true
|
|
|
type: init
|
|
@@ -150,3 +164,65 @@ secretName (required): Name of the secret containing the postgres credentials
|
|
|
sleep 2
|
|
|
done
|
|
|
{{- end -}}
|
|
|
+
|
|
|
+{{/* Returns persistence entries for postgres */}}
|
|
|
+{{/* Call this template:
|
|
|
+{{ include "ix.v1.common.app.postgresPersistence" (dict "pgData" .Values.storage.pgData "pgBackup" .Values.storage.pgBackup) }}
|
|
|
+
|
|
|
+pgData (required): Data persistence configuration
|
|
|
+pgBackup (required): Data persistence configuration for backup
|
|
|
+*/}}
|
|
|
+
|
|
|
+{{- define "ix.v1.common.app.postgresPersistence" -}}
|
|
|
+ {{- $data := .pgData -}}
|
|
|
+ {{- $backup := .pgBackup }}
|
|
|
+
|
|
|
+ {{- if not $data -}}
|
|
|
+ {{- fail "Postgres - Data persistence configuration is required" -}}
|
|
|
+ {{- end -}}
|
|
|
+
|
|
|
+ {{- if not $backup -}}
|
|
|
+ {{- fail "Postgres - Backup persistence configuration is required" -}}
|
|
|
+ {{- end -}}
|
|
|
+
|
|
|
+postgresdata:
|
|
|
+ enabled: true
|
|
|
+ type: {{ $data.type }}
|
|
|
+ datasetName: {{ $data.datasetName | default "" }}
|
|
|
+ hostPath: {{ $data.hostPath | default "" }}
|
|
|
+ targetSelector:
|
|
|
+ postgres:
|
|
|
+ postgres:
|
|
|
+ mountPath: /var/lib/postgresql/data
|
|
|
+ permissions:
|
|
|
+ mountPath: /mnt/directories/postgres_data
|
|
|
+postgresbackup:
|
|
|
+ enabled: true
|
|
|
+ type: {{ $backup.type }}
|
|
|
+ datasetName: {{ $backup.datasetName | default "" }}
|
|
|
+ hostPath: {{ $backup.hostPath | default "" }}
|
|
|
+ targetSelector:
|
|
|
+ postgresbackup:
|
|
|
+ postgresbackup:
|
|
|
+ mountPath: /postgres_backup
|
|
|
+ permissions:
|
|
|
+ mountPath: /mnt/directories/postgres_backup
|
|
|
+{{- end -}}
|
|
|
+
|
|
|
+{{/* Returns service entry for postgres */}}
|
|
|
+{{/* Call this template:
|
|
|
+{{ include "ix.v1.common.app.postgresService" . }}
|
|
|
+*/}}
|
|
|
+{{- define "ix.v1.common.app.postgresService" -}}
|
|
|
+postgres:
|
|
|
+ enabled: true
|
|
|
+ type: ClusterIP
|
|
|
+ targetSelector: postgres
|
|
|
+ ports:
|
|
|
+ postgres:
|
|
|
+ enabled: true
|
|
|
+ primary: true
|
|
|
+ port: 5432
|
|
|
+ targetPort: 5432
|
|
|
+ targetSelector: postgres
|
|
|
+{{- end -}}
|