danhuawang commented on code in PR #14941:
URL: https://github.com/apache/gravitino/pull/14941#discussion_r4627304503
##########
dev/charts/gravitino/templates/deployment.yaml:
##########
@@ -125,18 +125,64 @@ spec:
- mountPath: /scripts
name: scripts-emptydir
{{- end }}
- {{- if .Values.postgresql.enabled }}
+ {{- if eq (include "gravitino.postgresqlSchemaInitEnabled" . | trim)
"true" }}
+ {{- $_ := include "gravitino.postgresqlInitSslValidate" . }}
+ {{- $pgInitHost := include "gravitino.postgresqlInitHost" . | trim }}
+ {{- $pgInitSecret := include "gravitino.postgresqlInitSecretName" . |
trim }}
+ {{- $pgInitSecretKey :=
.Values.postgresql.init.existingSecretPasswordKey | default "password" }}
+ {{- $pgInitPort := include "gravitino.postgresqlInitPort" . | trim }}
+ {{- $pgInitSslMode := include "gravitino.postgresqlInitSslMode" . |
trim }}
+ {{- $pgInitCurrentSchema := include
"gravitino.postgresqlInitCurrentSchema" . | trim }}
+ {{- $pgInitSslCaSecret := include
"gravitino.postgresqlInitSslCaSecretName" . | trim }}
+ {{- $pgInitWaitTimeout := .Values.postgresql.init.waitTimeoutSeconds |
default 300 }}
+ {{- $pgInitConnectTimeout :=
.Values.postgresql.init.connectTimeoutSeconds | default 5 }}
- name: init-postgresql
image: {{ include "init-postgresql.image" . }}
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
command:
- /bin/bash
- -c
- |
- while ! PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ .Release.Name
}}-postgresql -U $POSTGRES_USER -c "SELECT 1"; do
+ set -e
+ timeout={{ $pgInitWaitTimeout }}
+ case "$timeout" in
+ ''|*[!0-9]*) echo "ERROR: waitTimeoutSeconds must be a
positive integer" >&2; exit 1 ;;
+ esac
+ if [ "$timeout" -lt 1 ]; then
+ echo "ERROR: waitTimeoutSeconds must be a positive integer" >&2
+ exit 1
+ fi
+ deadline=$((SECONDS + timeout))
+ last_err=""
+ while true; do
+ remaining=$((deadline - SECONDS))
+ if [ "$remaining" -lt 1 ]; then
+ echo "ERROR: timed out after ${timeout}s waiting for
PostgreSQL at {{ $pgInitHost }}:$PGPORT/$GRAVITINO_DB" >&2
+ echo "$last_err" >&2
+ exit 1
+ fi
+ set +e
+ err=$(PGPASSWORD="$POSTGRES_PASSWORD" timeout "$remaining"
psql -h {{ $pgInitHost }} -U $POSTGRES_USER -d $GRAVITINO_DB -c "SELECT 1" 2>&1)
+ rc=$?
+ set -e
+ if [ "$rc" -eq 0 ]; then
+ break
+ fi
+ last_err="$err"
+ if [ "$rc" -eq 124 ]; then
+ echo "ERROR: timed out after ${timeout}s waiting for
PostgreSQL at {{ $pgInitHost }}:$PGPORT/$GRAVITINO_DB" >&2
+ echo "$err" >&2
+ exit 1
+ fi
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done
+ if [ -n "${PG_CURRENT_SCHEMA:-}" ]; then
+ schema_exists=$(PGPASSWORD="$POSTGRES_PASSWORD" psql -h {{
$pgInitHost }} -U $POSTGRES_USER -d $GRAVITINO_DB -v ON_ERROR_STOP=1 -tAc
"SELECT 1 FROM pg_namespace WHERE nspname = '${PG_CURRENT_SCHEMA}'")
+ if [ "$schema_exists" != "1" ]; then
+ PGPASSWORD="$POSTGRES_PASSWORD" psql -h {{ $pgInitHost }} -U
$POSTGRES_USER -d $GRAVITINO_DB -v ON_ERROR_STOP=1 -c "CREATE SCHEMA
\"${PG_CURRENT_SCHEMA}\""
Review Comment:
Addressed in 42906fade2.
`gravitino.postgresqlInitCurrentSchema` now folds simple (unquoted-style)
identifiers to lowercase after validation, so `PG_CURRENT_SCHEMA`, `CREATE
SCHEMA \"…\"`, and `PGOPTIONS=-c search_path=…` all use the same name (e.g.
`currentSchema=App` → `app`). Documented in values comments; covered by
mixed-case helm unit tests for both `postgresql.init.currentSchema` and
`entity.jdbcUrl`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]