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


##########
dev/charts/gravitino/templates/deployment.yaml:
##########
@@ -125,15 +125,18 @@ 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" }}
         - 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:
   psql is called with only -h, so a non-5432 port in entity.jdbcUrl is 
ignored, and sslmode=require from the URL is not passed either (RDS and similar 
often require SSL). Parse the port from the URL (or add postgresql.init.port) 
and set PGSSLMODE; apply the same to the two psql calls below.



##########
dev/charts/gravitino/templates/_helpers.tpl:
##########
@@ -108,7 +108,97 @@ 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.
+*/}}
+{{- define "gravitino.postgresqlSchemaInitEnabled" -}}
+{{- if or .Values.postgresql.enabled (eq (include 
"gravitino.entityUsesExternalPostgresql" . | trim) "true") -}}
+true
+{{- end -}}
+{{- end -}}
+
+{{/*
+Hostname for init-postgresql psql (-h).
+*/}}
+{{- define "gravitino.postgresqlInitHost" -}}

Review Comment:
   Existing users with postgresql.enabled=false and a jdbc:postgresql: URL 
previously rendered no init container; they now fail to render until they set 
init.host and init.existingSecret. Consider skipping the init container (or 
falling back to the URL host) when these are unset, or call this out as a 
breaking change in the docs and release notes.



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

Review Comment:
   The schema script is rerun on every pod start against an external, possibly 
shared database, with upgrade failures only warned about. Is that intended for 
operator-managed databases, and should there be an opt-out flag?



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