Skip to content

Commit c03db82

Browse files
authored
chore: add params to make crunchy optional, and document the steps needed. (#2150)
Signed-off-by: OMPRAKASH MISHRA <omprakashmishra3978@gmail.com>
1 parent b316e31 commit c03db82

File tree

9 files changed

+35
-18
lines changed

9 files changed

+35
-18
lines changed

.github/workflows/.dbdeployer.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ on:
2626
default: 'values.yaml'
2727
required: false
2828
type: string
29+
enabled:
30+
description: 'Enable the deployment of the crunchy database, easy switch to turn it on/off'
31+
default: true
32+
required: false
33+
type: boolean
34+
2935
secrets:
3036
oc_namespace:
3137
description: OpenShift namespace
@@ -48,6 +54,7 @@ on:
4854
jobs:
4955
deploy_db:
5056
runs-on: ubuntu-24.04
57+
if: ${{ inputs.enabled }}
5158
name: Deploy Or Upgrade Crunchy DB
5259
environment: ${{ inputs.environment }}
5360
steps:

.github/workflows/pr-close.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ jobs:
4040
- name: Remove PR user and database from crunchy.
4141
shell: bash
4242
run: |
43-
43+
# check if postgres-crunchy exists or else exit
44+
oc get PostgresCluster/postgres-crunchy || exit 0
45+
46+
# Remove the user from the crunchy cluster yaml and apply the changes
4447
USER_TO_REMOVE='{"databases":["app-${{ github.event.number }}"],"name":"app-${{ github.event.number }}"}'
4548
4649
echo 'getting current users from crunchy'

.github/workflows/pr-open.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
# https://github.com/bcgov/quickstart-openshift-helpers
3737
deploys:
3838
name: Deploys
39-
needs: [builds, deploy_db]
39+
needs: [builds]
4040
uses: ./.github/workflows/.deployer.yml
4141
secrets:
4242
oc_namespace: ${{ secrets.OC_NAMESPACE }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ Crunchy is the default choice for HA postgres/postgis DB in BCGov. provided char
363363

364364
* For specifying different resources for different envs, just add values-test.yml and values-prod.yml , then provide them to the [DB Deployer in GHA](.github/workflows/.dbdeployer.yml#L24).
365365
* For enabling S3 backups/recovery, please enable in [values file](./charts/crunchy/values.yaml#L62), and in the [DB Deployer in GHA](.github/workflows/.dbdeployer.yml#L20), then provide necessary secret values which are prefixed with `s3` [DB Deployer in GHA](.github/workflows/.dbdeployer.yml#L36)
366+
* To disable crunchy deployment, make the following changes
367+
* make crunchy enabled to false in [values.yaml](./charts/app/values.yaml#L117)
368+
* make bitnami postgis enabled to true in [values.yaml](./charts/app/values.yaml#L120)
369+
* make the db-deployer false in gha workflow [.dbdeployer.yaml](./.github/workflows/.dbdeployer.yml#L31)
366370

367371
## Alternative Backends
368372

charts/app/Chart.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
- name: postgresql
33
repository: https://charts.bitnami.com/bitnami
4-
version: 16.0.4
5-
digest: sha256:f35e9a099b4b8a5fb19be545d31397682125da77cbfcbdc7312da2a6d5858cce
6-
generated: "2024-10-28T14:47:12.015716693Z"
4+
version: 16.0.6
5+
digest: sha256:3de96304f1e196bad8c10cf426762b3e42eb88771cc1c11386ae459148720f1b
6+
generated: "2024-10-28T14:15:45.2855055-07:00"

charts/app/Chart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ appVersion: "1.16.0"
2626

2727
dependencies:
2828
- name: postgresql
29-
condition: bitnamiPostgis.enabled
30-
version: 16.0.4
29+
condition: bitnamipg.enabled
30+
version: 16.0.6
3131
repository: https://charts.bitnami.com/bitnami
32-
alias: bitnamiPostgis
32+
alias: bitnamipg
3333
maintainers:
3434
- name: Om Mishra
3535
email: omprakash.2.mishra@gov.bc.ca

charts/app/templates/_helpers.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ app.kubernetes.io/instance: {{ .Release.Name }}
4646
{{- end }}
4747

4848
{{- define "validation" -}}
49-
{{- if and (not .Values.crunchy.enabled) (not .Values.bitnamiPostgis.enabled ) }}
49+
{{- if and (not .Values.crunchy.enabled) (not .Values.bitnamipg.enabled ) }}
5050
{{- fail "Both Database options are disabled" }}
5151
{{- end }}
52-
{{- if and (.Values.crunchy.enabled) (.Values.bitnamiPostgis.enabled) }}
52+
{{- if and (.Values.crunchy.enabled) (.Values.bitnamipg.enabled) }}
5353
{{- fail "Both Database options are enabled" }}
5454
{{- end }}
5555
{{- if and (.Values.crunchy.enabled) (not .Values.global.config.databaseUser) }}

charts/app/templates/secret.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
{{- $databaseName = b64dec (get $secretData "dbname") }}
1515
{{- $host = printf "%s:%s" (b64dec (get $secretData "host")) (b64dec (get $secretData "port")) }}
1616
{{- $hostWithoutPort = printf "%s" (b64dec (get $secretData "host")) }}
17-
{{- else}}
18-
{{- $databaseUser = .Values.global.config.databaseUser| default "quickstart" }}
19-
{{- $databasePassword := .Values.global.secrets.databasePassword | default (randAlphaNum 10) }}
17+
{{- else }}
18+
{{- $databaseUser = "quickstart" }}
19+
{{- $databasePassword = .Values.global.secrets.databasePassword | default (randAlphaNum 10) }}
2020
{{- $secretName := printf "%s-database" .Release.Name }}
2121
{{- $secretObj := (lookup "v1" "Secret" .Release.Namespace $secretName ) | default dict }}
2222
{{- $secretData := (get $secretObj "data") | default dict }}
2323
# set below to existing secret data or generate a random one when not exists
2424
{{- $databasePassword = (get $secretData "postgres-password") | default ($databasePassword | b64enc) }}
25-
{{- $databaseName = .Values.global.secrets.databaseName| default "quickstart" }}
25+
{{- $databaseName = "quickstart" }}
2626
{{- $host = printf "%s-%s:5432" .Release.Name .Values.global.databaseAlias }}
2727
{{- $hostWithoutPort = printf "%s-%s" .Release.Name .Values.global.databaseAlias }}
2828

@@ -63,6 +63,7 @@ data:
6363
FLYWAY_PASSWORD: {{ $databasePassword | quote }}
6464

6565
---
66+
{{- if not .Values.crunchy.enabled}} # only when it is bitnami-postgres
6667
apiVersion: v1
6768
kind: Secret
6869
metadata:
@@ -76,3 +77,4 @@ data:
7677
postgres-password: {{ $databasePassword | quote }}
7778
password: {{ $databasePassword | quote }}
7879
{{- end }}
80+
{{- end }}

charts/app/values.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ global:
2121
#-- domain of the application, it is required, apps.silver.devops.gov.bc.ca for silver cluster and apps.devops.gov.bc.ca for gold cluster
2222
domain: "apps.silver.devops.gov.bc.ca" # it is apps.gold.devops.gov.bc.ca for gold cluster
2323
#-- the database Alias gives a nice way to switch to different databases, crunchy, patroni ... etc.
24-
databaseAlias: postgres-crunchy #bitnamiPostgis # when using crunchy make it postgres-crunchy
24+
#databaseAlias: bitnamipg #uncomment when using bitnami pg and comment below.
25+
databaseAlias: postgres-crunchy #uncomment when using crunchy and comment above.
2526

2627
#-- the components of the application, backend.
2728
backend:
@@ -116,16 +117,16 @@ frontend:
116117
crunchy:
117118
enabled: true # make this false and bitnami-pg true to switch from crunchy to bitnami single postgis.
118119

119-
bitnamiPostgis:
120+
bitnamipg:
120121
enabled: false
121122
image:
122123
registry: ghcr.io
123124
repository: bcgov/nr-containers/bitnami/postgresql
124125
tag: 15.8.0
125126
auth:
126127
existingSecret: '{{ .Release.Name }}-database'
127-
username: 'quickstart'
128-
database: quickstart
128+
username: 'quickstart' # make sure this is aligned with secret.yaml
129+
database: quickstart # make sure this is aligned with secret.yaml
129130
shmVolume:
130131
enabled: false
131132
backup:

0 commit comments

Comments
 (0)