danhuawang commented on code in PR #14941:
URL: https://github.com/apache/gravitino/pull/14941#discussion_r4561728959
##########
dev/charts/gravitino/templates/_helpers.tpl:
##########
@@ -108,7 +108,194 @@ 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 -}}
+{{- if $match -}}
+{{- trimPrefix "sslmode=" $match -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Hostname for init-postgresql psql (-h).
+*/}}
+{{- define "gravitino.postgresqlInitHost" -}}
+{{- if .Values.postgresql.init.host -}}
+{{- .Values.postgresql.init.host -}}
+{{- else if .Values.postgresql.enabled -}}
+{{- printf "%s-postgresql" .Release.Name -}}
+{{- else -}}
+{{- $fromUrl := include "gravitino.entityJdbcHostFromUrl" . | trim -}}
+{{- if $fromUrl -}}
+{{- $fromUrl -}}
+{{- else -}}
+{{- fail "postgresql.init.host is required (or set a parseable entity.jdbcUrl
host) when postgresql.init.enabled is true for external PostgreSQL" -}}
+{{- end -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Port for init-postgresql (PGPORT).
+*/}}
+{{- define "gravitino.postgresqlInitPort" -}}
+{{- if .Values.postgresql.init.port -}}
+{{- .Values.postgresql.init.port | toString -}}
+{{- else if .Values.postgresql.enabled -}}
+5432
+{{- else -}}
+{{- include "gravitino.entityJdbcPortFromUrl" . | trim -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+sslmode for init-postgresql (PGSSLMODE).
+*/}}
+{{- define "gravitino.postgresqlInitSslMode" -}}
+{{- if .Values.postgresql.init.sslMode -}}
+{{- .Values.postgresql.init.sslMode -}}
+{{- else -}}
+{{- include "gravitino.entityJdbcSslModeFromUrl" . | trim -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Secret name for init-postgresql POSTGRES_PASSWORD secretKeyRef.
+*/}}
+{{- define "gravitino.postgresqlInitSecretName" -}}
+{{- if .Values.postgresql.init.existingSecret -}}
+{{- .Values.postgresql.init.existingSecret -}}
+{{- else if and .Values.postgresql.enabled
.Values.postgresql.auth.existingSecret -}}
+{{- .Values.postgresql.auth.existingSecret -}}
+{{- else if .Values.postgresql.enabled -}}
+{{- printf "%s-postgresql" .Release.Name -}}
+{{- else if eq (include "gravitino.entityUsesExternalPostgresql" . | trim)
"true" -}}
+{{- fail "postgresql.init.existingSecret is required when
postgresql.init.enabled is true for external PostgreSQL" -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Database name segment from entity.jdbcUrl (postgresql JDBC URLs only).
+*/}}
+{{- define "gravitino.entityJdbcDatabaseFromUrl" -}}
+{{- $url := .Values.entity.jdbcUrl | default "" -}}
+{{- if hasPrefix "jdbc:postgresql://" $url -}}
+{{- $path := trimPrefix "jdbc:postgresql://" $url -}}
+{{- $parts := splitList "/" $path -}}
+{{- if ge (len $parts) 2 -}}
+{{- $dbPart := index $parts 1 -}}
+{{- $db := splitList "?" $dbPart | first -}}
Review Comment:
Addressed in 4877420a99. Init now parses `currentSchema` from
`entity.jdbcUrl` (override with `postgresql.init.currentSchema`) into
`PGOPTIONS=-c search_path=...` so psql creates objects in the same schema
Gravitino reads. Also runs `CREATE SCHEMA IF NOT EXISTS` when set, and fails at
render for non-simple identifiers. Covered by helm unit tests.
##########
dev/charts/gravitino/templates/deployment.yaml:
##########
@@ -125,15 +125,20 @@ spec:
- mountPath: /scripts
name: scripts-emptydir
{{- end }}
- {{- if .Values.postgresql.enabled }}
+ {{- if eq (include "gravitino.postgresqlSchemaInitEnabled" . | trim)
"true" }}
+ {{- $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 }}
- 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
+ while ! PGPASSWORD=$POSTGRES_PASSWORD psql -h {{ $pgInitHost }}
-U $POSTGRES_USER -d $GRAVITINO_DB -c "SELECT 1"; do
Review Comment:
Addressed in 4877420a99. The readiness loop is bounded by
`postgresql.init.waitTimeoutSeconds` (default 300). On timeout the init
container exits non-zero and prints the last `psql` error instead of hanging
forever.
##########
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
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 -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" . }}
+ - name: PGPORT
+ value: {{ $pgInitPort | quote }}
+ {{- if $pgInitSslMode }}
+ - name: PGSSLMODE
Review Comment:
Addressed in 4877420a99. `sslmode=require` still needs no CA. `verify-ca` /
`verify-full` now fail at render unless `postgresql.init.ssl.existingSecret` (+
`caCert`) is set; that Secret is mounted at `/db-ssl/ca.crt` and exported as
`PGSSLROOTCERT`. Documented in values and NOTES (JDBC `sslrootcert` is not
inherited).
##########
dev/charts/gravitino/templates/_helpers.tpl:
##########
@@ -108,7 +108,194 @@ 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 -}}
+{{- if $match -}}
+{{- trimPrefix "sslmode=" $match -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Hostname for init-postgresql psql (-h).
+*/}}
+{{- define "gravitino.postgresqlInitHost" -}}
+{{- if .Values.postgresql.init.host -}}
+{{- .Values.postgresql.init.host -}}
+{{- else if .Values.postgresql.enabled -}}
+{{- printf "%s-postgresql" .Release.Name -}}
+{{- else -}}
+{{- $fromUrl := include "gravitino.entityJdbcHostFromUrl" . | trim -}}
+{{- if $fromUrl -}}
+{{- $fromUrl -}}
+{{- else -}}
+{{- fail "postgresql.init.host is required (or set a parseable entity.jdbcUrl
host) when postgresql.init.enabled is true for external PostgreSQL" -}}
+{{- end -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Port for init-postgresql (PGPORT).
+*/}}
+{{- define "gravitino.postgresqlInitPort" -}}
+{{- if .Values.postgresql.init.port -}}
+{{- .Values.postgresql.init.port | toString -}}
+{{- else if .Values.postgresql.enabled -}}
+5432
+{{- else -}}
+{{- include "gravitino.entityJdbcPortFromUrl" . | trim -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+sslmode for init-postgresql (PGSSLMODE).
+*/}}
+{{- define "gravitino.postgresqlInitSslMode" -}}
+{{- if .Values.postgresql.init.sslMode -}}
+{{- .Values.postgresql.init.sslMode -}}
+{{- else -}}
+{{- include "gravitino.entityJdbcSslModeFromUrl" . | trim -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Secret name for init-postgresql POSTGRES_PASSWORD secretKeyRef.
+*/}}
+{{- define "gravitino.postgresqlInitSecretName" -}}
+{{- if .Values.postgresql.init.existingSecret -}}
+{{- .Values.postgresql.init.existingSecret -}}
+{{- else if and .Values.postgresql.enabled
.Values.postgresql.auth.existingSecret -}}
+{{- .Values.postgresql.auth.existingSecret -}}
Review Comment:
Addressed in 4877420a99. `postgresql.auth.existingSecret` is now passed
through `tpl` when used as the Bitnami fallback for the init container password
Secret, matching the values.yaml note that the value is evaluated as a
template. Covered by a unit test with `{{ .Release.Name }}-pg-credentials`.
--
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]