Skip to content

feat: support external PostgreSQL with internal Keycloak#54

Merged
Tim-herbie merged 2 commits intoTim-herbie:mainfrom
bernardgut:feat/external-postgres-support
Mar 15, 2026
Merged

feat: support external PostgreSQL with internal Keycloak#54
Tim-herbie merged 2 commits intoTim-herbie:mainfrom
bernardgut:feat/external-postgres-support

Conversation

@bernardgut
Copy link
Copy Markdown

Summary

When postgres.enabled is false but oidc.enabled is true, Keycloak now constructs its JDBC URL from postgres.external.host and postgres.external.port instead of the chart's internal PostgreSQL service name.

This enables environments that run a PostgreSQL operator (e.g., CloudNativePG, Zalando, CrunchyData) to reuse their existing database infrastructure without deploying an additional PostgreSQL instance via the chart.

Closes #29

Changes

  • values.yaml: Added postgres.external.host and postgres.external.port fields with sensible defaults
  • templates/keycloak/deployment.yaml: Made KC_DB_URL conditional — uses the internal service name when postgres.enabled is true, uses postgres.external.host:port when false
  • README.md: Documented the new parameters and added a usage example

Backward Compatibility

Fully backward compatible. When postgres.enabled: true (the default), the JDBC URL is constructed exactly as before using the chart's internal PostgreSQL service name.

Example

postgres:
  enabled: false
  database: keycloak
  existingSecret: "my-pg-credentials"
  external:
    host: "my-cluster-pooler-rw.cnpg.svc.cluster.local"
    port: 5432

Testing

Verified with helm template:

  • ✅ External PostgreSQL: JDBC URL renders as jdbc:postgresql://my-cnpg-pooler:5432/keycloak
  • ✅ Internal PostgreSQL: JDBC URL renders as jdbc:postgresql://opencloud-postgres:5432/keycloak (backward compat)
  • ✅ No PostgreSQL deployment created when postgres.enabled: false

When postgres.enabled is false but oidc.enabled is true, Keycloak now
constructs its JDBC URL from postgres.external.host and
postgres.external.port instead of the chart's internal PostgreSQL
service name.

This enables environments that run a PostgreSQL operator (e.g.,
CloudNativePG) to reuse their existing database infrastructure without
deploying an additional PostgreSQL instance via the chart.

Closes Tim-herbie#29
@Tim-herbie Tim-herbie marked this pull request as ready for review March 15, 2026 14:04
Copilot AI review requested due to automatic review settings March 15, 2026 14:04
@Tim-herbie Tim-herbie assigned Tim-herbie and Copilot and unassigned Tim-herbie Mar 15, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Helm chart to allow the built-in Keycloak (when oidc.enabled: true) to connect to an external PostgreSQL instance when the chart’s internal PostgreSQL is disabled (postgres.enabled: false), by parameterizing the JDBC host/port and documenting the new configuration.

Changes:

  • Added postgres.external.host / postgres.external.port values.
  • Made Keycloak’s KC_DB_URL switch between internal Postgres service name vs. external host/port based on postgres.enabled.
  • Documented the new parameters and added an example in the README.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
charts/opencloud/values.yaml Introduces postgres.external.* values to support external DB connectivity.
charts/opencloud/templates/keycloak/deployment.yaml Updates Keycloak env var rendering to conditionally build the JDBC URL for internal vs external Postgres.
charts/opencloud/README.md Documents the new postgres.external.* parameters and provides a usage example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +53 to +57
{{- if .Values.postgres.enabled }}
value: "jdbc:postgresql://{{ include "opencloud.postgres.fullname" . }}:5432/{{ .Values.postgres.database }}"
{{- else }}
value: "jdbc:postgresql://{{ .Values.postgres.external.host }}:{{ .Values.postgres.external.port | default 5432 }}/{{ .Values.postgres.database }}"
{{- end }}
{{- if .Values.postgres.enabled }}
value: "jdbc:postgresql://{{ include "opencloud.postgres.fullname" . }}:5432/{{ .Values.postgres.database }}"
{{- else }}
value: "jdbc:postgresql://{{ .Values.postgres.external.host }}:{{ .Values.postgres.external.port | default 5432 }}/{{ .Values.postgres.database }}"
Comment on lines +55 to +57
{{- else }}
value: "jdbc:postgresql://{{ .Values.postgres.external.host }}:{{ .Values.postgres.external.port | default 5432 }}/{{ .Values.postgres.database }}"
{{- end }}
Comment thread charts/opencloud/templates/keycloak/deployment.yaml Outdated
Comment on lines +217 to +225
# External PostgreSQL configuration
# Used when postgres.enabled is false but oidc.enabled is true.
# Allows Keycloak to connect to an external PostgreSQL database
# (e.g., managed by an operator like CloudNativePG).
external:
# Hostname or service name of the external PostgreSQL instance
host: ""
# Port of the external PostgreSQL instance
port: 5432
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Tim-herbie Tim-herbie merged commit d709029 into Tim-herbie:main Mar 15, 2026
@Tim-herbie
Copy link
Copy Markdown
Owner

Thank you @bernardgut!

@bernardgut bernardgut deleted the feat/external-postgres-support branch March 15, 2026 14:22
@Tim-herbie Tim-herbie mentioned this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

External PostgreSQL with internal Keycloak

4 participants