Skip to content

Commit c2910cb

Browse files
authored
Merge pull request #2705 from bcgov/DESENG-925-capture-patroni-cluster-in-helm
DESENG-925: Capture Patroni cluster in Helm charts
2 parents 3b5faa7 + eb36ef8 commit c2910cb

13 files changed

Lines changed: 123 additions & 58 deletions

File tree

.github/workflows/infrastructure-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
default: "all"
2222
type: choice
2323
options:
24-
- met-db
24+
- engagement-db
2525
- notify-api
2626
- met-api
2727
- met-web
@@ -93,7 +93,7 @@ jobs:
9393
run: |
9494
# Define chart directories
9595
declare -A chart_dirs=(
96-
[met-db]="openshift/db"
96+
[engagement-db]="openshift/db"
9797
[notify-api]="openshift/notify"
9898
[met-api]="openshift/api"
9999
[met-web]="openshift/web"

.github/workflows/infrastructure-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
default: "all"
1616
type: choice
1717
options:
18-
- met-db
18+
- engagement-db
1919
- notify-api
2020
- met-api
2121
- met-web
@@ -78,7 +78,7 @@ jobs:
7878
run: |
7979
# Define chart directories
8080
declare -A chart_dirs=(
81-
[met-db]="openshift/db"
81+
[engagement-db]="openshift/db"
8282
[notify-api]="openshift/notify"
8383
[met-api]="openshift/api"
8484
[met-web]="openshift/web"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,7 @@ met-api/.DS_Store
142142

143143
# VSCode config and Chrome extension user data
144144
.vscode/chrome
145-
met-web/.vscode/
145+
met-web/.vscode/
146+
147+
# Helm dependency files
148+
openshift/**/charts/

CHANGELOG.MD

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## December 11, 2025
2+
3+
- **Feature** Capture Patroni cluster in Helm charts [🎟️ DESENG-925](https://citz-gdx.atlassian.net/browse/DESENG-925)
4+
- Updated Helm charts for `openshift/db` to include Patroni cluster configuration.
5+
- Patroni cluster state is now managed by Helm via Github Actions CI/CD pipeline.
6+
- Leverages https://github.com/bcgov/nr-patroni-chart/ as a subchart for Patroni deployment.
7+
- Renamed DB to `engagement-patroni` to reflect ongoing branding changes.
8+
- Updated backup and restore scripts to work with Patroni clusters.
9+
- Updated backup/restore documentation in `openshift/README.md`.
10+
- Confirmed app still runs correctly after DB reconfiguration.
11+
112
## December 9, 2025
213

314
- **Feature** Add CI pipeline for ETL workflow [🎟️ DESENG-880](https://citz-gdx.atlassian.net/browse/DESENG-880)
@@ -86,7 +97,6 @@
8697
## August 22, 2025
8798

8899
- **Chore** Resolve Dependabot vulnerability reports [🎟️ DESENG-845](https://citz-gdx.atlassian.net/browse/DESENG-845)
89-
90100
- Update several packages to the latest version, resolving Dependabot PRs that are too old to be rebased.
91101

92102
- **Bugfix** Finish upgrading DeploymentConfigs -> Deployments cross-app [🎟️ DESENG-847](https://citz-gdx.atlassian.net/browse/DESENG-847)
@@ -245,7 +255,6 @@
245255
- **Bugfix** Resolve conflicting versions for Dagster ETL pipeline [🎟️ DESENG-677](https://citz-gdx.atlassian.net/browse/DESENG-677)
246256
- Tweak dagster versions and python base image
247257
- **Feature** Redesign event widget [🎟️ DESENG-698](https://citz-gdx.atlassian.net/browse/DESENG-698)
248-
249258
- Modified api to accomodate additional field required in event widget design
250259
- Modified forms and cards on admin side to show new field
251260
- Implemented front-end design
@@ -262,7 +271,6 @@
262271
## April 22, 2025
263272

264273
- **Feature** Redesign poll widget [🎟️ DESENG-697](https://citz-gdx.atlassian.net/browse/DESENG-697)
265-
266274
- Refactor PollWidget.tsx implementing Figma design
267275
- Improved layout, similar to DocumentWidget
268276
- Load data more efficiently
@@ -272,15 +280,13 @@
272280
## April 15, 2025
273281

274282
- **Feature** Redesign document widget [🎟️ DESENG-696](https://citz-gdx.atlassian.net/browse/DESENG-696)
275-
276283
- Significant refactor to DocumentWidget.tsx implementing Figma design
277284
- Use recursive rendering to support theoretically infinite subfolders in future
278285
- Many accessibility/QoL improvements
279286
- Improved layout - minimizes layout shift by forcing the list widget to be at least as tall as the copy it appears beside.
280287
- Improved skeleton while loading
281288

282289
- **Chore** Update GitHub Actions workflows to use ubuntu-latest instead of ubuntu-20.04
283-
284290
- This is to stay ahead of the deprecation of ubuntu-20.04 in GitHub Actions as of today's date
285291

286292
## _Interregnum break_: _October 2024 - March 2025_
@@ -290,7 +296,6 @@
290296
## October 2, 2024
291297

292298
- **Feature** New Who is Listening widget front end [🎟️ DESENG-695](https://citz-gdx.atlassian.net/browse/DESENG-695)
293-
294299
- Implemented Figma design
295300
- Added widget_listening table to db for widget instance data
296301
- Added option to enter widget description text (below title, above contacts)
@@ -300,7 +305,6 @@
300305
- Updated Who is Listening widget form
301306

302307
- **Feature** New Video Widget front end [🎟️ DESENG-692](https://citz-gdx.atlassian.net/browse/DESENG-692)
303-
304308
- Changed icon colour from yellow to white to accomodate company branding requests
305309

306310
- **Feature** New Map Widget front end [🎟️ DESENG-693](https://citz-gdx.atlassian.net/browse/DESENG-693)
@@ -315,7 +319,6 @@
315319
## September 25, 2024
316320

317321
- **Feature** New Video Widget front end [🎟️ DESENG-692](https://citz-gdx.atlassian.net/browse/DESENG-692)
318-
319322
- Removed unneeded tables from db
320323
- Updated all other met_api and met_web logic to accomodate this
321324

@@ -334,7 +337,6 @@
334337
## September 18, 2024
335338

336339
- **Feature** New Video Widget front end [🎟️ DESENG-692](https://citz-gdx.atlassian.net/browse/DESENG-692)
337-
338340
- Implemented Figma design
339341
- Created custom layover bar for videos that shows video provider and has a custom logo
340342
- Transcripts will not be implemented at this time
@@ -392,7 +394,6 @@
392394
## August 15, 2024
393395

394396
- **Feature** Add engagement configuration summary [🎟️ DESENG-667](https://citz-gdx.atlassian.net/browse/DESENG-667)
395-
396397
- Added a tabbed layout to the new engagement view page
397398
- Added a new "Configuration" tab to display the engagement's configuration details
398399
- The other tabs are blank for now, but will be filled in future tickets
@@ -432,7 +433,6 @@
432433
## July 30, 2024
433434

434435
- **Feature** New admin header [🎟️ DESENG-660](https://citz-gdx.atlassian.net/browse/DESENG-660)
435-
436436
- Added a new API endpoint to fetch a list of a user's tenants, required for the new header
437437
- Redesigned the admin header to match the new design system
438438
- Added a new dropdown to the header to allow users to switch between tenants
@@ -450,7 +450,6 @@
450450
## July 17, 2024
451451

452452
- **Feature** Admin authoring experience - language selector [🎟️ DESENG-657](https://citz-gdx.atlassian.net/browse/DESENG-657)
453-
454453
- Created loader for engagement creation wizard
455454
- Created language selector field in engagement creation wizard
456455

met-api/src/met_api/services/authorization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def check_auth(**kwargs):
2929
if not user_from_db:
3030
abort(HTTPStatus.FORBIDDEN, 'User not found')
3131

32-
# Retrieve tenant specific user roles from met-db
32+
# Retrieve tenant specific user roles from OIDC token info
3333
user_roles = current_app.config['JWT_ROLE_CALLBACK'](user_from_context.token_info)
3434

3535
if not user_roles:

openshift/README.md

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,37 @@ roleRef:
176176
177177
## Database Configuration
178178
179-
Inntall an instance of patroni using helm chart:
179+
Create a highly available PostgreSQL database using Patroni:
180180
181-
```
182-
helm repo add patroni-chart https://bcgov.github.io/nr-patroni-chart
183-
helm install -n <namespace> met-patroni patroni-chart/patroni
181+
```bash
182+
helm install engagement-db . --values values_<env>.yaml
184183
```
185184

186-
If HA is not necessary create a instance of a postgresql database:
185+
If the cluster is not starting, remove any existing ConfigMaps and PersistentVolumeClaims:
187186

187+
```bash
188+
oc delete configmap -l app.kubernetes.io/instance=engagement-db
189+
oc delete pvc -l app.kubernetes.io/instance=engagement-db
188190
```
189-
oc new-app --template=postgresql-persistent -p POSTGRESQL_DATABASE=app -p DATABASE_SERVICE_NAME=met-postgresql
191+
192+
For technical reasons, we cannot load secrets from Vault during the initial database setup. Therefore, a Secret must be created in each namespace containing the initial database user passwords. These values should match those stored in Vault.
193+
194+
```bash
195+
oc create secret generic engagement-patroni \
196+
--from-literal=superuser-username=postgres \
197+
--from-literal=superuser-password=<superuser-password> \
198+
--from-literal=replication-username=replicator \
199+
--from-literal=replication-password=<replication-password> \
200+
--from-literal=app-db-username=<app-username> \
201+
--from-literal=app-db-password=<app-password> \
202+
--from-literal=app-db-name=app \
203+
-n e903c2-<env>
190204
```
191205

192206
### Setup
193207

194208
1. Users Setup script is located at /tools/postgres/init/00_postgresql-user-setup.sql
195209
1. Initial database setup script is located at /tools/postgres/init/01_postgresql-schema-setup.sql
196-
1. Openshift secret yaml is located at ./database-users.secret.yml
197210

198211
## IP Whitelist Management
199212

@@ -266,69 +279,72 @@ This should be stored at:
266279

267280
Backups are generated daily by the "backup" deployment in each namespace and are saved as a gzipped SQL script containing the database structure + data.
268281

269-
Backups are verified nightly at 4 AM by creating a temporary database instance, restoring the backup into it, and checking for tables in the restored database. This is configured in the `backup.conf` file, mounted from the `met-db-backup-config` ConfigMap.
282+
Backups are verified nightly at 4 AM by creating a temporary database instance, restoring the backup into it, and checking for tables in the restored database. This is configured in the `backup.conf` file, mounted from the `engagement-db-backup` ConfigMap.
270283

271284
Backups are also uploaded to S3-compatible storage for offsite retention.
272285

273-
## Restoring from S3
286+
### Restoring from S3
274287

275288
**Note**: The backup container does not support restoring directly from S3. If a backup has already been removed from the local FS, you must download it from S3 to the local `/backups/` directory first, then restore using the standard process.
276289

277290
To restore a backup stored in S3:
278291

279292
```bash
280293
# Connect to backup container
281-
oc rsh deploy/met-db-backup
294+
oc rsh deploy/engagement-db-backup
282295

283296
# Source S3 credentials
284297
source /vault/secrets/s3
285298

299+
# Configure mc (MinIO Client) for S3 access
300+
mc alias set dell_s3 $S3_ENDPOINT $S3_USER $S3_PASSWORD
301+
286302
# List backups in S3 bucket
287-
mc ls minio_s3/engagement-dev-backup/
303+
mc ls dell_s3/engagement-dev-backup/
288304

289305
# Download the desired backup file
290-
mc cp minio_s3/engagement-dev-backup/met-patroni-app_YYYY-MM-DD_HH-MM-SS.sql.gz /backups/
306+
mc cp dell_s3/engagement-dev-backup/engagement-patroni-app_YYYY-MM-DD_HH-MM-SS.sql.gz /backups/
291307

292308
# Now proceed with normal restore process (see scenarios below)
293309
```
294310

295-
## Scenarios
311+
### Scenarios
296312

297-
### 1. Normal Production Restore (Roles Exist)
313+
#### 1. Normal Production Restore (Roles Exist)
298314

299315
**Use case**: Restoring to existing Patroni cluster where roles are already defined.
300316

301317
```bash
302318
# Connect to backup container
303-
oc rsh deploy/met-db-backup
319+
oc rsh deploy/engagement-db-backup
304320

305321
# Add credentials to environment
306-
source /vault/secrets/met-patroni
322+
source /vault/secrets/engagement-patroni
307323

308324
# List available backups
309325
./backup.sh -l # press Enter if prompted for password
310326

311327
# Restore with -I flag to ignore duplicate role errors
312-
./backup.sh -I -r postgres=met-patroni:5432/app -f /backups/<period>/<YYYY-MM-DD>/met-patroni-app_<YYYY-MM-DD_HH-MM-SS>.sql.gz
328+
./backup.sh -I -r postgres=engagement-patroni:5432/app -f /backups/<period>/<YYYY-MM-DD>/engagement-patroni-app_<YYYY-MM-DD_HH-MM-SS>.sql.gz
313329
```
314330

315331
**Why `-I`?**: The backup contains `CREATE ROLE` statements at the end. Since roles already exist in production, these will fail but can be safely ignored.
316332

317333
---
318334

319-
### 2. Emergency Restore (Fresh Database)
335+
#### 2. Emergency Restore (Fresh Database)
320336

321337
**Use case**: Restoring to a completely new PostgreSQL instance that has no existing roles.
322338

323339
```bash
324340
# Connect to backup container
325-
oc rsh deploy/met-db-backup
341+
oc rsh deploy/engagement-db-backup
326342

327343
# Source credentials
328-
source /vault/secrets/met-patroni
344+
source /vault/secrets/engagement-patroni
329345

330346
# Use the emergency restore script
331-
./emergency-restore.sh /backups/daily/YYYY-MM-DD/met-patroni-app_YYYY-MM-DD_HH-MM-SS.sql.gz app
347+
./emergency-restore.sh /backups/daily/YYYY-MM-DD/engagement-patroni-app_YYYY-MM-DD_HH-MM-SS.sql.gz app
332348
```
333349

334350
**What it does**:
@@ -342,7 +358,7 @@ Note: the users are created without passwords; you will need to set passwords ma
342358

343359
```bash
344360
# Connect as superuser
345-
oc rsh pod/met-patroni-0
361+
oc rsh pod/engagement-patroni-0
346362
psql -U postgres -d app
347363

348364
# Set passwords for each role

openshift/db/Chart.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: patroni
3+
repository: https://bcgov.github.io/nr-patroni-chart
4+
version: 0.0.4
5+
digest: sha256:d7bc2a92b8b07c58f069af160f02486c5f1b6f8d80b00e016473501f84aee502
6+
generated: "2025-12-10T13:43:11.389446729-08:00"

openshift/db/Chart.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ description: |
1111
type: application
1212
version: 0.1.0
1313
appVersion: "1.0"
14-
# dependencies:
15-
# - name: patroni
16-
# version: 0.0.1
17-
# repository: https://bcgov.github.io/nr-patroni-chart
14+
dependencies:
15+
- name: patroni
16+
alias: postgres
17+
version: 0.0.4
18+
repository: https://bcgov.github.io/nr-patroni-chart
19+
condition: postgres.enabled

openshift/db/files/backup.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Daily backup at 1 AM
22
0 1 * * * default ./backup.sh -s
33
# Daily verification at 4 AM using verify connection spec with -I to ignore role errors
4-
0 4 * * * default ./backup.sh -I -s -v postgres=verify:5432/app -f met-patroni-app
4+
0 4 * * * default ./backup.sh -I -s -v postgres=verify:5432/app -f engagement-patroni-app

openshift/db/files/emergency-restore.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ set -e
1111

1212
if [[ $# -ne 2 ]]; then
1313
echo "Usage: $0 <backup-file.sql.gz> <database-name>"
14-
echo "Example: $0 /backups/daily/2025-11-25/met-patroni-app_2025-11-25_10-34-33.sql.gz app"
14+
echo "Example: $0 /backups/daily/2025-11-25/engagement-patroni-app_2025-11-25_10-34-33.sql.gz app"
1515
exit 1
1616
fi
1717

1818
BACKUP_FILE="$1"
1919
DATABASE="$2"
2020

21-
source /vault/secrets/met-patroni
21+
source /vault/secrets/engagement-patroni
2222
export PGPASSWORD="$MET_PATRONI_PASSWORD"
23-
export DB_HOST="${DATABASE_SERVICE_NAME:-met-patroni}"
23+
export DB_HOST="${DATABASE_SERVICE_NAME:-engagement-patroni}"
2424

2525
# Check the file exists
2626
if [[ ! -f "$BACKUP_FILE" ]]; then

0 commit comments

Comments
 (0)