jerryshao commented on code in PR #14941:
URL: https://github.com/apache/gravitino/pull/14941#discussion_r4560252722
##########
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:
For IPv6 or multi-host JDBC URLs the host is parsed wrongly (for example
'[') and the wait loop then retries forever with no clear error. Consider
failing the render when the authority contains '[' or ',' and asking for
postgresql.init.host/port.
##########
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:
With init enabled, the upgrade script and schema script run against the
external database on every pod start. Is that safe for a production database
that an operator may manage separately, and are both scripts idempotent?
--
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]