Skip to content

Commit 1ca39bc

Browse files
committed
feat(RHIDP-9113): add custom PostgreSQL StatefulSet for Keycloak
- Add dedicated PostgreSQL StatefulSet/Service/Secret for Keycloak - Update deploy.sh to generate password and apply DB resources - Prepare Keycloak to use external PostgreSQL instead of in-memory DB Signed-off-by: skestwal <[email protected]>
1 parent 36aeb72 commit 1ca39bc

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

ci-scripts/rhdh-setup/deploy.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,26 @@ keycloak_install() {
188188
envsubst <template/backstage/perf-test-secrets.yaml | $clin apply -f -
189189
grep -m 1 "rhbk-operator" <($clin get pods -w)
190190
wait_to_start deployment rhbk-operator 300 300
191+
192+
export KEYCLOAK_DB_PASSWORD
193+
KEYCLOAK_DB_PASSWORD=$(mktemp -u XXXXXXXXXX)
194+
export KEYCLOAK_DB_STORAGE
195+
KEYCLOAK_DB_STORAGE=${KEYCLOAK_DB_STORAGE:-${RHDH_DB_STORAGE:-1Gi}}
196+
197+
log_info "Creating Keycloak PostgreSQL database with storage: $KEYCLOAK_DB_STORAGE"
198+
envsubst <template/keycloak/keycloak-postgresql.yaml | $clin apply -f -
199+
wait_to_start statefulset keycloak-postgresql 300 300
200+
201+
$clin create secret generic keycloak-db-user --from-literal=keycloak-db-user=keycloak --dry-run=client -o yaml | $clin apply -f -
202+
191203
envsubst <template/keycloak/keycloak.yaml | $clin apply -f -
192204
wait_to_start statefulset rhdh-keycloak 450 600
205+
206+
$clin create route edge keycloak \
207+
--service=rhdh-keycloak-service \
208+
--port=8080 \
209+
--dry-run=client -o yaml | $clin apply -f -
210+
193211
if [ "$INSTALL_METHOD" == "helm" ]; then
194212
export OAUTH2_REDIRECT_URI=https://${RHDH_HELM_RELEASE_NAME}-${RHDH_HELM_CHART}-${RHDH_NAMESPACE}.${OPENSHIFT_APP_DOMAIN}/oauth2/callback
195213
elif [ "$INSTALL_METHOD" == "olm" ]; then
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: keycloak-postgresql
6+
labels:
7+
app: keycloak-postgresql
8+
type: Opaque
9+
stringData:
10+
postgres-password: ${KEYCLOAK_DB_PASSWORD}
11+
password: ${KEYCLOAK_DB_PASSWORD}
12+
replication-password: ${KEYCLOAK_DB_PASSWORD}
13+
---
14+
apiVersion: v1
15+
kind: Service
16+
metadata:
17+
name: keycloak-postgresql
18+
labels:
19+
app: keycloak-postgresql
20+
spec:
21+
type: ClusterIP
22+
ports:
23+
- name: tcp-postgresql
24+
port: 5432
25+
targetPort: tcp-postgresql
26+
selector:
27+
app: keycloak-postgresql
28+
---
29+
apiVersion: apps/v1
30+
kind: StatefulSet
31+
metadata:
32+
name: keycloak-postgresql
33+
labels:
34+
app: keycloak-postgresql
35+
spec:
36+
serviceName: keycloak-postgresql
37+
replicas: 1
38+
selector:
39+
matchLabels:
40+
app: keycloak-postgresql
41+
template:
42+
metadata:
43+
labels:
44+
app: keycloak-postgresql
45+
spec:
46+
containers:
47+
- name: postgresql
48+
image: registry.redhat.io/rhel9/postgresql-15:latest
49+
imagePullPolicy: IfNotPresent
50+
ports:
51+
- name: tcp-postgresql
52+
containerPort: 5432
53+
env:
54+
- name: POSTGRESQL_USER
55+
value: keycloak
56+
- name: POSTGRESQL_PASSWORD
57+
valueFrom:
58+
secretKeyRef:
59+
name: keycloak-postgresql
60+
key: password
61+
- name: POSTGRESQL_DATABASE
62+
value: keycloak
63+
- name: POSTGRESQL_ADMIN_PASSWORD
64+
valueFrom:
65+
secretKeyRef:
66+
name: keycloak-postgresql
67+
key: postgres-password
68+
- name: PGDATA
69+
value: /var/lib/pgsql/data/userdata
70+
volumeMounts:
71+
- name: data
72+
mountPath: /var/lib/pgsql/data
73+
livenessProbe:
74+
exec:
75+
command:
76+
- /bin/sh
77+
- -c
78+
- exec pg_isready -U keycloak -d keycloak -h 127.0.0.1 -p 5432
79+
initialDelaySeconds: 30
80+
periodSeconds: 10
81+
timeoutSeconds: 5
82+
successThreshold: 1
83+
failureThreshold: 6
84+
readinessProbe:
85+
exec:
86+
command:
87+
- /bin/sh
88+
- -c
89+
- exec pg_isready -U keycloak -d keycloak -h 127.0.0.1 -p 5432
90+
initialDelaySeconds: 5
91+
periodSeconds: 10
92+
timeoutSeconds: 5
93+
successThreshold: 1
94+
failureThreshold: 6
95+
volumeClaimTemplates:
96+
- metadata:
97+
name: data
98+
spec:
99+
accessModes:
100+
- ReadWriteOnce
101+
resources:
102+
requests:
103+
storage: ${KEYCLOAK_DB_STORAGE}

0 commit comments

Comments
 (0)