jerryshao commented on code in PR #14941:
URL: https://github.com/apache/gravitino/pull/14941#discussion_r4594816455
##########
dev/charts/gravitino/templates/deployment.yaml:
##########
@@ -155,29 +201,52 @@ spec:
fi
echo "Schema file: $schema_file"
echo "Upgrade file: $upgrade_file"
- if ! PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ .Release.Name
}}-postgresql -U $POSTGRES_USER -d $GRAVITINO_DB -f "$upgrade_file"; then
+ if ! PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ $pgInitHost }} -U
$POSTGRES_USER -d $GRAVITINO_DB -f "$upgrade_file"; then
echo "WARNING: Upgrade script failed: $upgrade_file" >&2
echo "Continuing with schema script..." >&2
fi
- PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ .Release.Name
}}-postgresql -U $POSTGRES_USER -d $GRAVITINO_DB -f "$schema_file"
+ PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ $pgInitHost }} -U
$POSTGRES_USER -d $GRAVITINO_DB -v ON_ERROR_STOP=1 -f "$schema_file"
Review Comment:
[P1] On the second pod start against the same database, the 2.0.0 baseline
tries to create `table_column_version_info_idx_mid` again. With
`ON_ERROR_STOP=1`, that duplicate index now stops init on every retry. Please
keep strict handling for genuine DDL failures and make the baseline safe to
reapply, including the other unguarded `CREATE INDEX` statements. Running the
shipped baseline twice against the same schema would catch this.
##########
dev/charts/gravitino/templates/deployment.yaml:
##########
@@ -155,29 +201,52 @@ spec:
fi
echo "Schema file: $schema_file"
echo "Upgrade file: $upgrade_file"
- if ! PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ .Release.Name
}}-postgresql -U $POSTGRES_USER -d $GRAVITINO_DB -f "$upgrade_file"; then
+ if ! PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ $pgInitHost }} -U
$POSTGRES_USER -d $GRAVITINO_DB -f "$upgrade_file"; then
echo "WARNING: Upgrade script failed: $upgrade_file" >&2
echo "Continuing with schema script..." >&2
fi
- PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ .Release.Name
}}-postgresql -U $POSTGRES_USER -d $GRAVITINO_DB -f "$schema_file"
+ PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ $pgInitHost }} -U
$POSTGRES_USER -d $GRAVITINO_DB -v ON_ERROR_STOP=1 -f "$schema_file"
resources:
{{- toYaml .Values.initResources | nindent 12 }}
securityContext:
{{- toYaml .Values.initContainerSecurityContext | nindent 12 }}
env:
- name: POSTGRES_USER
- value: {{ .Values.postgresql.auth.username }}
+ value: {{ include "gravitino.postgresqlInitUsername" . }}
- name: GRAVITINO_DB
- value: {{ .Values.postgresql.auth.database }}
+ value: {{ include "gravitino.postgresqlInitDatabase" . }}
Review Comment:
[P2] For `jdbc:postgresql://pg.example/12345`, this renders a numeric
`EnvVar.value` and Kubernetes rejects the Deployment. Please pipe the database
and username helper results through `quote` and assert that a numeric database
name renders as a string.
##########
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=$(timeout "$remaining" env PGPASSWORD=$POSTGRES_PASSWORD
psql -h {{ $pgInitHost }} -U $POSTGRES_USER -d $GRAVITINO_DB -c "SELECT 1" 2>&1)
Review Comment:
[P1] A password containing a space gets split after `env`, so the probe can
retry until timeout without ever running `psql`. Its last error can also
include a word from the password. Please move the assignment ahead of the
wrapper, as in `PGPASSWORD="$POSTGRES_PASSWORD" timeout "$remaining" psql ...`,
and exercise the probe with a password containing whitespace.
##########
dev/charts/gravitino/templates/_helpers.tpl:
##########
@@ -108,7 +108,258 @@ Return the proper MySQL image name for the init-mysql
initContainer
Return the proper Postgresql image name for the init-postgresql initContainer
*/}}
{{- define "init-postgresql.image" -}}
+{{- include "gravitino.imageReference" (dict "imageRoot"
.Values.postgresql.image "global" .Values.global) -}}
+{{- end -}}
+
+{{/*
+True when the entity store uses an external PostgreSQL JDBC URL (not in-chart
Bitnami).
+*/}}
+{{- define "gravitino.entityUsesExternalPostgresql" -}}
+{{- $url := .Values.entity.jdbcUrl | default "" -}}
+{{- if and (not .Values.mysql.enabled) (not .Values.postgresql.enabled)
(hasPrefix "jdbc:postgresql:" $url) -}}
+true
+{{- end -}}
+{{- end -}}
+
+{{/*
+True when the init-postgresql schema init container should be rendered.
+In-chart Bitnami PostgreSQL always runs schema init. External PostgreSQL runs
+only when postgresql.init.enabled is true (opt-in; see issue #9013 for hook
Job).
+*/}}
+{{- define "gravitino.postgresqlSchemaInitEnabled" -}}
{{- if .Values.postgresql.enabled -}}
- {{- include "gravitino.imageReference" (dict "imageRoot"
.Values.postgresql.image "global" .Values.global) -}}
+true
+{{- else if and (eq (include "gravitino.entityUsesExternalPostgresql" . |
trim) "true") .Values.postgresql.init.enabled -}}
+true
+{{- end -}}
+{{- end -}}
+
+{{/*
+Authority segment (host[:port]) from entity.jdbcUrl for PostgreSQL.
+
+Only a single host:port is supported. The helpers split authority on the first
+colon and do not parse IPv6 bracket literals (e.g. [::1]:5432) or multi-host
+JDBC authorities (host1:5432,host2:5432). When the authority contains "[" or
+"," and host/port would be derived from the URL, rendering fails and asks for
+postgresql.init.host and postgresql.init.port.
+*/}}
+{{- define "gravitino.entityJdbcAuthorityFromUrl" -}}
+{{- $url := .Values.entity.jdbcUrl | default "" -}}
+{{- if hasPrefix "jdbc:postgresql://" $url -}}
+{{- $path := trimPrefix "jdbc:postgresql://" $url -}}
+{{- $auth := (splitList "/" $path | first) -}}
+{{- if or (contains "[" $auth) (contains "," $auth) -}}
+{{- fail "entity.jdbcUrl authority is IPv6 or multi-host; set
postgresql.init.host and postgresql.init.port explicitly (JDBC URL host/port
fallback supports only a single host:port)" -}}
+{{- end -}}
+{{- $auth -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Hostname from entity.jdbcUrl authority (external PostgreSQL).
+
+Supports a single hostname or IPv4 host only (see entityJdbcAuthorityFromUrl).
+*/}}
+{{- define "gravitino.entityJdbcHostFromUrl" -}}
+{{- $auth := include "gravitino.entityJdbcAuthorityFromUrl" . | trim -}}
+{{- if $auth -}}
+{{- if contains ":" $auth -}}
+{{- $parts := splitList ":" $auth -}}
+{{- index $parts 0 -}}
+{{- else -}}
+{{- $auth -}}
+{{- end -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Port from entity.jdbcUrl authority (defaults to 5432 when omitted).
+
+Supports a single host:port only (see entityJdbcAuthorityFromUrl).
+*/}}
+{{- define "gravitino.entityJdbcPortFromUrl" -}}
+{{- $auth := include "gravitino.entityJdbcAuthorityFromUrl" . | trim -}}
+{{- if and $auth (contains ":" $auth) -}}
+{{- $parts := splitList ":" $auth -}}
+{{- index $parts 1 -}}
+{{- else -}}
+5432
+{{- end -}}
+{{- end -}}
+
+{{/*
+sslmode query parameter from entity.jdbcUrl.
+*/}}
+{{- define "gravitino.entityJdbcSslModeFromUrl" -}}
+{{- $url := .Values.entity.jdbcUrl | default "" -}}
+{{- $match := regexFind "sslmode=([^&]+)" $url -}}
Review Comment:
[P1] With external init enabled and `?ssl=true` in the JDBC URL, Gravitino
verifies the server hostname and certificate, while this helper leaves `psql`
on its weaker default. Please map JDBC `ssl=true` to `verify-full` when no
explicit SSL mode takes precedence, and reuse the existing CA Secret
validation. A render test should cover that URL both with and without a CA.
--
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]