From 45579c9f55cdddf2a1ba767125ed427bc6cad3f8 Mon Sep 17 00:00:00 2001 From: darteaga Date: Tue, 24 Dec 2019 10:06:51 +0000 Subject: [PATCH] add psql query to postgresql container liveness probe --- bitnami/postgresql-ha/Chart.yaml | 2 +- bitnami/postgresql-ha/templates/_helpers.tpl | 18 ++++++++++++++---- .../templates/postgresql/statefulset.yaml | 18 ++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bitnami/postgresql-ha/Chart.yaml b/bitnami/postgresql-ha/Chart.yaml index 66047431f..19690e122 100644 --- a/bitnami/postgresql-ha/Chart.yaml +++ b/bitnami/postgresql-ha/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: postgresql-ha -version: 1.1.2 +version: 1.1.3 appVersion: 11.6.0 description: Chart for PostgreSQL with HA architecture (using Replication Manager (repmgr) and Pgpool). keywords: diff --git a/bitnami/postgresql-ha/templates/_helpers.tpl b/bitnami/postgresql-ha/templates/_helpers.tpl index 582a1b33b..1415d36bd 100644 --- a/bitnami/postgresql-ha/templates/_helpers.tpl +++ b/bitnami/postgresql-ha/templates/_helpers.tpl @@ -314,18 +314,19 @@ Helm 2.11 supports the assignment of a value to a variable defined in a differen but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. Also, we can't use a single if because lazy evaluation is not an option */}} +{{- $postgresqlDatabase := default "" .Values.postgresql.database -}} {{- if .Values.global }} {{- if .Values.global.postgresql }} {{- if .Values.global.postgresql.database }} - {{- .Values.global.postgresql.database -}} + {{- default "" .Values.global.postgresql.database -}} {{- else -}} - {{- .Values.postgresql.database -}} + {{- $postgresqlDatabase -}} {{- end -}} {{- else -}} - {{- .Values.postgresql.database -}} + {{- $postgresqlDatabase -}} {{- end -}} {{- else -}} - {{- .Values.postgresql.database -}} + {{- $postgresqlDatabase -}} {{- end -}} {{- end -}} @@ -734,3 +735,12 @@ postgresql-ha: Upgrade repmgr extension --set postgresql.upgradeRepmgrExtension=true {{- end -}} {{- end -}} + +{{/* Set PGPASSWORD as environment variable depends on configuration */}} +{{- define "postgresql-ha.pgpassword" -}} +{{- if .Values.postgresql.usePasswordFile -}} +PGPASSWORD=$(cat $POSTGRES_PASSWORD_FILE) +{{- else -}} +PGPASSWORD=$POSTGRES_PASSWORD +{{- end -}} +{{- end -}} diff --git a/bitnami/postgresql-ha/templates/postgresql/statefulset.yaml b/bitnami/postgresql-ha/templates/postgresql/statefulset.yaml index b9793247e..6563a2869 100644 --- a/bitnami/postgresql-ha/templates/postgresql/statefulset.yaml +++ b/bitnami/postgresql-ha/templates/postgresql/statefulset.yaml @@ -150,11 +150,10 @@ spec: command: - sh - -c - {{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} - - exec pg_isready -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} -h 127.0.0.1 - {{- else }} - - exec pg_isready -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} -h 127.0.0.1 - {{- end }} + - '{{include "postgresql-ha.pgpassword" . }} psql -w -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} + {{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) -}} + -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} + {{- end }} -h 127.0.0.1 -c "SELECT 1"' initialDelaySeconds: {{ .Values.postgresql.livenessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.postgresql.livenessProbe.periodSeconds }} timeoutSeconds: {{ .Values.postgresql.livenessProbe.timeoutSeconds }} @@ -167,11 +166,10 @@ spec: command: - sh - -c - {{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} - - exec pg_isready -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} -h 127.0.0.1 - {{- else }} - - exec pg_isready -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} -h 127.0.0.1 - {{- end }} + - '{{include "postgresql-ha.pgpassword" . }} psql -w -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} + {{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) -}} + -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} + {{- end }} -h 127.0.0.1 -c "SELECT 1"' initialDelaySeconds: {{ .Values.postgresql.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.postgresql.readinessProbe.periodSeconds }} timeoutSeconds: {{ .Values.postgresql.readinessProbe.timeoutSeconds }}