danhuawang commented on code in PR #14941:
URL: https://github.com/apache/gravitino/pull/14941#discussion_r4560841613


##########
dev/charts/gravitino/templates/_helpers.tpl:
##########
@@ -108,7 +108,189 @@ 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 -}}
+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). For those forms, set
+postgresql.init.host and postgresql.init.port explicitly.
+*/}}
+{{- define "gravitino.entityJdbcAuthorityFromUrl" -}}
+{{- $url := .Values.entity.jdbcUrl | default "" -}}
+{{- if hasPrefix "jdbc:postgresql://" $url -}}
+{{- $path := trimPrefix "jdbc:postgresql://" $url -}}
+{{- (splitList "/" $path | first) -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Hostname from entity.jdbcUrl authority (external PostgreSQL).
+
+Supports a single hostname or IPv4 host only (see entityJdbcAuthorityFromUrl).
+*/}}
+{{- define "gravitino.entityJdbcHostFromUrl" -}}

Review Comment:
   Addressed in 3315644c3c. When `entity.jdbcUrl` authority contains `[` (IPv6) 
or `,` (multi-host) and host/port would be derived from the URL, Helm now fails 
at render and asks for `postgresql.init.host` / `postgresql.init.port`, instead 
of mis-parsing and hanging in the wait loop. Explicit host+port still works 
with those URL forms (covered by unit tests).



##########
dev/charts/gravitino/templates/deployment.yaml:
##########
@@ -155,29 +160,35 @@ 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

Review Comment:
   Same stance as earlier 
([#4548657835](https://github.com/apache/gravitino/pull/14941#discussion_r4548657835)):
 no code change in this PR. For external PostgreSQL the path stays opt-in 
(`postgresql.init.enabled` defaults to `false`), so operator-managed production 
DBs are untouched unless explicitly enabled. When enabled, behavior matches 
today’s in-chart Bitnami initContainer (schema + upgrade on every pod start). 
Baseline schema scripts are largely idempotent (`CREATE TABLE IF NOT EXISTS`, 
etc.); upgrade scripts are only partially so (many `IF NOT EXISTS` paths, but 
some `ALTER … TYPE` statements can fail on re-run — hence upgrade failures are 
warned and the schema script continues). For databases operators manage 
separately, leave init disabled or move to the hook Job in #9013 rather than 
relying on per-pod re-apply.



-- 
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]

Reply via email to