feat: support external PostgreSQL with internal Keycloak#54
Merged
Tim-herbie merged 2 commits intoTim-herbie:mainfrom Mar 15, 2026
Merged
Conversation
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
There was a problem hiding this comment.
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.portvalues. - Made Keycloak’s
KC_DB_URLswitch between internal Postgres service name vs. external host/port based onpostgres.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 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>
Owner
|
Thank you @bernardgut! |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
postgres.enabledisfalsebutoidc.enabledistrue, Keycloak now constructs its JDBC URL frompostgres.external.hostandpostgres.external.portinstead 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: Addedpostgres.external.hostandpostgres.external.portfields with sensible defaultstemplates/keycloak/deployment.yaml: MadeKC_DB_URLconditional — uses the internal service name whenpostgres.enabledistrue, usespostgres.external.host:portwhenfalseREADME.md: Documented the new parameters and added a usage exampleBackward 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
Testing
Verified with
helm template:jdbc:postgresql://my-cnpg-pooler:5432/keycloakjdbc:postgresql://opencloud-postgres:5432/keycloak(backward compat)postgres.enabled: false