Skip to content

Commit e184aed

Browse files
Merge pull request #1986 from Thushani-Jayasekera/documentation
Enhance PostgreSQL support in gateway Helm chart configuration.
2 parents 2d18acc + 860ef38 commit e184aed

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

kubernetes/helm/gateway-helm-chart/templates/gateway/controller/deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ spec:
105105
value: {{ printf "%d" (int $controller.metrics.port) | quote }}
106106
- name: APIP_GW_DEVELOPMENT_MODE
107107
value: {{ .Values.gateway.developmentMode | toString | quote }}
108+
{{- if and (eq .Values.gateway.config.controller.storage.type "postgres") $controller.postgres.passwordSecretRef.name }}
109+
- name: APIP_GW_CONTROLLER_STORAGE_POSTGRES_PASSWORD
110+
valueFrom:
111+
secretKeyRef:
112+
name: {{ $controller.postgres.passwordSecretRef.name }}
113+
key: {{ $controller.postgres.passwordSecretRef.key | default "password" }}
114+
{{- end }}
108115
{{- range $deployment.extraEnv }}
109116
- {{- toYaml . | nindent 14 }}
110117
{{- end }}

kubernetes/helm/gateway-helm-chart/templates/gateway/gateway-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{- $gc := .Values.gateway.config.controller -}}
33
{{- $router := .Values.gateway.config.router -}}
44
{{- $pe := .Values.gateway.config.policy_engine -}}
5+
{{- $pg := $gc.storage.postgres -}}
56
{{- $controllerHost := printf "%s-controller" (include "gateway-operator.fullname" .) -}}
67
apiVersion: v1
78
kind: ConfigMap
@@ -38,6 +39,25 @@ data:
3839
[controller.storage.sqlite]
3940
path = {{ $gc.storage.sqlite.path | quote }}
4041
42+
{{- if eq $gc.storage.type "postgres" }}
43+
[controller.storage.postgres]
44+
{{- if $pg.dsn }}
45+
dsn = {{ $pg.dsn | quote }}
46+
{{- else }}
47+
host = {{ required "gateway.config.controller.storage.postgres.host is required when storage.type is \"postgres\" and dsn is unset" $pg.host | quote }}
48+
port = {{ $pg.port | int }}
49+
database = {{ required "gateway.config.controller.storage.postgres.database is required when storage.type is \"postgres\" and dsn is unset" $pg.database | quote }}
50+
user = {{ required "gateway.config.controller.storage.postgres.user is required when storage.type is \"postgres\" and dsn is unset" $pg.user | quote }}
51+
sslmode = {{ $pg.sslmode | default "require" | quote }}
52+
connect_timeout = {{ $pg.connect_timeout | default "5s" | quote }}
53+
max_open_conns = {{ $pg.max_open_conns | default 25 | int }}
54+
max_idle_conns = {{ $pg.max_idle_conns | default 5 | int }}
55+
conn_max_lifetime = {{ $pg.conn_max_lifetime | default "30m" | quote }}
56+
conn_max_idle_time = {{ $pg.conn_max_idle_time | default "5m" | quote }}
57+
application_name = {{ $pg.application_name | default "gateway-controller" | quote }}
58+
{{- end }}
59+
{{- end }}
60+
4161
[controller.policies]
4262
definitions_path = {{ $gc.policies.definitions_path | quote }}
4363

kubernetes/helm/gateway-helm-chart/values.yaml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,39 @@ gateway:
7474

7575
# Storage configuration
7676
storage:
77-
# Storage type: "sqlite", "postgres" (future), or "memory"
78-
# - sqlite: Use SQLite embedded database for persistence
79-
# - postgres: Use PostgreSQL database for persistence (future support)
80-
# - memory: No persistent storage, all configs lost on restart (useful for testing)
77+
# Storage type: "sqlite", "postgres", or "memory"
78+
# - sqlite: Single-instance embedded database backed by a PersistentVolumeClaim
79+
# - postgres: External PostgreSQL database; enables multi-replica controller deployments
80+
# - memory: No persistence; all state is lost on restart (useful for testing only)
8181
type: sqlite
8282

8383
# SQLite configuration (used when type=sqlite)
8484
sqlite:
8585
path: ./data/gateway.db
8686

87+
# PostgreSQL configuration (used when type=postgres)
88+
# Password is injected separately via gateway.controller.postgres.passwordSecretRef
89+
postgres:
90+
# Full DSN takes precedence over individual fields when set.
91+
# Example: "postgres://user:password@host:5432/dbname?sslmode=require"
92+
dsn: ""
93+
94+
host: ""
95+
port: 5432
96+
database: ""
97+
user: ""
98+
99+
# SSL mode: disable, allow, prefer, require, verify-ca, verify-full
100+
# Use "require" or stronger in production.
101+
sslmode: require
102+
103+
connect_timeout: 5s
104+
max_open_conns: 25
105+
max_idle_conns: 5
106+
conn_max_lifetime: 30m
107+
conn_max_idle_time: 5m
108+
application_name: gateway-controller
109+
87110
# Policy configuration
88111
policies:
89112
# Directory containing policy definitions
@@ -438,6 +461,13 @@ gateway:
438461
storage:
439462
type: sqlite
440463
sqlitePath: ./data/gateway.db
464+
# PostgreSQL password secret reference (used when gateway.config.controller.storage.type=postgres).
465+
# The password is injected as an env var from a Kubernetes secret rather than stored in the ConfigMap.
466+
# Create with: kubectl create secret generic <name> --from-literal=password='<db-password>'
467+
postgres:
468+
passwordSecretRef:
469+
name: ""
470+
key: password
441471
metrics:
442472
port: 9091
443473
persistence:

0 commit comments

Comments
 (0)