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


##########
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 -c "SELECT 1"; do

Review Comment:
   The readiness probe runs psql without -d, so it connects to a database named 
after the user. On an external server that database often does not exist, so 
the loop retries forever and the pod never starts. Add -d $GRAVITINO_DB (or use 
the postgres database) to the probe.



##########
dev/charts/gravitino/templates/_helpers.tpl:
##########
@@ -108,7 +108,180 @@ 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.
+*/}}
+{{- 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).
+*/}}
+{{- define "gravitino.entityJdbcHostFromUrl" -}}
+{{- $auth := include "gravitino.entityJdbcAuthorityFromUrl" . | trim -}}
+{{- if $auth -}}
+{{- if contains ":" $auth -}}
+{{- $parts := splitList ":" $auth -}}

Review Comment:
   Splitting the authority on a colon breaks IPv6 hosts like [::1]:5432 and 
multi-host JDBC URLs. Either handle brackets and commas or document that only a 
single host:port is supported.



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