Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add params to make crunchy optional, and document the steps needed. #2150

Merged
merged 6 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/.dbdeployer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ on:
default: 'values.yaml'
required: false
type: string
enabled:
description: 'Enable the deployment of the crunchy database, easy switch to turn it on/off'
default: true
required: false
type: boolean

secrets:
oc_namespace:
description: OpenShift namespace
Expand All @@ -48,6 +54,7 @@ on:
jobs:
deploy_db:
runs-on: ubuntu-24.04
if: ${{ inputs.enabled }}
name: Deploy Or Upgrade Crunchy DB
environment: ${{ inputs.environment }}
steps:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:
- name: Remove PR user and database from crunchy.
shell: bash
run: |
# check if postgres-crunchy exists or else exit
oc get PostgresCluster/postgres-crunchy || exit 0
# Remove the user from the crunchy cluster yaml and apply the changes
USER_TO_REMOVE='{"databases":["app-${{ github.event.number }}"],"name":"app-${{ github.event.number }}"}'
echo 'getting current users from crunchy'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
name: Deploys
needs: [builds, deploy_db]
needs: [builds]
uses: ./.github/workflows/.deployer.yml
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ Crunchy is the default choice for HA postgres/postgis DB in BCGov. provided char

* 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).
* 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)
* To disable crunchy deployment, make the following changes
* make crunchy enabled to false in [values.yaml](./charts/app/values.yaml#L117)
* make bitnami postgis enabled to true in [values.yaml](./charts/app/values.yaml#L120)
* make the db-deployer false in gha workflow [.dbdeployer.yaml](./.github/workflows/.dbdeployer.yml#L31)

## Alternative Backends

Expand Down
6 changes: 3 additions & 3 deletions charts/app/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 16.0.4
digest: sha256:f35e9a099b4b8a5fb19be545d31397682125da77cbfcbdc7312da2a6d5858cce
generated: "2024-10-28T14:47:12.015716693Z"
version: 16.0.6
digest: sha256:3de96304f1e196bad8c10cf426762b3e42eb88771cc1c11386ae459148720f1b
generated: "2024-10-28T14:15:45.2855055-07:00"
6 changes: 3 additions & 3 deletions charts/app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ appVersion: "1.16.0"

dependencies:
- name: postgresql
condition: bitnamiPostgis.enabled
version: 16.0.4
condition: bitnamipg.enabled
version: 16.0.6
repository: https://charts.bitnami.com/bitnami
alias: bitnamiPostgis
alias: bitnamipg
maintainers:
- name: Om Mishra
email: [email protected]
Expand Down
4 changes: 2 additions & 2 deletions charts/app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "validation" -}}
{{- if and (not .Values.crunchy.enabled) (not .Values.bitnamiPostgis.enabled ) }}
{{- if and (not .Values.crunchy.enabled) (not .Values.bitnamipg.enabled ) }}
{{- fail "Both Database options are disabled" }}
{{- end }}
{{- if and (.Values.crunchy.enabled) (.Values.bitnamiPostgis.enabled) }}
{{- if and (.Values.crunchy.enabled) (.Values.bitnamipg.enabled) }}
{{- fail "Both Database options are enabled" }}
{{- end }}
{{- if and (.Values.crunchy.enabled) (not .Values.global.config.databaseUser) }}
Expand Down
10 changes: 6 additions & 4 deletions charts/app/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
{{- $databaseName = b64dec (get $secretData "dbname") }}
{{- $host = printf "%s:%s" (b64dec (get $secretData "host")) (b64dec (get $secretData "port")) }}
{{- $hostWithoutPort = printf "%s" (b64dec (get $secretData "host")) }}
{{- else}}
{{- $databaseUser = .Values.global.config.databaseUser| default "quickstart" }}
{{- $databasePassword := .Values.global.secrets.databasePassword | default (randAlphaNum 10) }}
{{- else }}
{{- $databaseUser = "quickstart" }}
{{- $databasePassword = .Values.global.secrets.databasePassword | default (randAlphaNum 10) }}
{{- $secretName := printf "%s-database" .Release.Name }}
{{- $secretObj := (lookup "v1" "Secret" .Release.Namespace $secretName ) | default dict }}
{{- $secretData := (get $secretObj "data") | default dict }}
# set below to existing secret data or generate a random one when not exists
{{- $databasePassword = (get $secretData "postgres-password") | default ($databasePassword | b64enc) }}
{{- $databaseName = .Values.global.secrets.databaseName| default "quickstart" }}
{{- $databaseName = "quickstart" }}
{{- $host = printf "%s-%s:5432" .Release.Name .Values.global.databaseAlias }}
{{- $hostWithoutPort = printf "%s-%s" .Release.Name .Values.global.databaseAlias }}

Expand Down Expand Up @@ -63,6 +63,7 @@ data:
FLYWAY_PASSWORD: {{ $databasePassword | quote }}

---
{{- if not .Values.crunchy.enabled}} # only when it is bitnami-postgres
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -76,3 +77,4 @@ data:
postgres-password: {{ $databasePassword | quote }}
password: {{ $databasePassword | quote }}
{{- end }}
{{- end }}
9 changes: 5 additions & 4 deletions charts/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ global:
#-- 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
domain: "apps.silver.devops.gov.bc.ca" # it is apps.gold.devops.gov.bc.ca for gold cluster
#-- the database Alias gives a nice way to switch to different databases, crunchy, patroni ... etc.
databaseAlias: postgres-crunchy #bitnamiPostgis # when using crunchy make it postgres-crunchy
#databaseAlias: bitnamipg #uncomment when using bitnami pg and comment below.
databaseAlias: postgres-crunchy #uncomment when using crunchy and comment above.

#-- the components of the application, backend.
backend:
Expand Down Expand Up @@ -116,16 +117,16 @@ frontend:
crunchy:
enabled: true # make this false and bitnami-pg true to switch from crunchy to bitnami single postgis.

bitnamiPostgis:
bitnamipg:
enabled: false
image:
registry: ghcr.io
repository: bcgov/nr-containers/bitnami/postgresql
tag: 15.8.0
auth:
existingSecret: '{{ .Release.Name }}-database'
username: 'quickstart'
database: quickstart
username: 'quickstart' # make sure this is aligned with secret.yaml
database: quickstart # make sure this is aligned with secret.yaml
shmVolume:
enabled: false
backup:
Expand Down
Loading