jerryshao commented on code in PR #14941:
URL: https://github.com/apache/gravitino/pull/14941#discussion_r4623945277
##########
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:
[P2] With `currentSchema=App`, this creates `"App"`, while `PGOPTIONS=-c
search_path=App` resolves to lowercase `app`. On a fresh database the baseline
then has no usable target schema; with a pre-created `app`, the exact-name
lookup also misses it and can fail on database CREATE privileges. Please
normalize the accepted unquoted identifier consistently for lookup, creation,
and search_path, preserving JDBC semantics, and add a mixed-case regression
case.
--
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]