Skip to content

Commit a2c3467

Browse files
author
shubham singh mahar
committed
(chore): add a init container to make goalerts wait for pgsql and fix secrets
Signed-off-by: shubham singh mahar <smahar@obmondo.com>
1 parent bc6d0f0 commit a2c3467

3 files changed

Lines changed: 52 additions & 45 deletions

File tree

argocd-helm-charts/goalerts/readme.md

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,29 @@ GoAlert - open source on-call scheduling, automated escalations, and notificatio
44

55
## 1. How to setup
66

7-
GoAlert reads two values from an existing Secret (default name `goalert`, set via
8-
`goalert.existingSecret.name`):
7+
Goalert reads data encryption key from the secret
8+
you provide.
99

1010
| Key | What it is |
1111
|---|---|
12-
| `GOALERT_DB_URL` | Postgres connection string |
1312
| `GOALERT_DATA_ENCRYPTION_KEY` | Encrypts data at rest. **Back this up** - losing it makes encrypted data unrecoverable, and it must never change once set. |
1413

15-
### Create it
14+
### Create it (sealed-secrets)
1615

1716
```bash
1817
NS=goalert # your target namespace
19-
20-
# 1. A strong data-encryption key (store a copy somewhere safe):
2118
ENC_KEY="$(openssl rand -base64 32)"
2219

23-
# 2. The DB URL. If you're using the CNPG cluster this chart provisions, read it
24-
DB_URL="$(kubectl -n "$NS" get secret goalert-pgsql-app \
25-
-o jsonpath='{.data.uri}' | base64 -d)?sslmode=require"
26-
27-
# 3. Create the Secret:
28-
kubectl create secret generic goalert -n "$NS" \
29-
--from-literal=GOALERT_DB_URL="$DB_URL" \
30-
--from-literal=GOALERT_DATA_ENCRYPTION_KEY="$ENC_KEY"
31-
```
32-
33-
Note: the CNPG cluster (and its `goalert-pgsql-app` secret) must exist first, so sync/deploy the chart once to provision the DB, then create this Secret.
34-
35-
### GitOps (sealed-secrets)
36-
37-
Seal the same object instead of applying it:
38-
39-
```bash
4020
kubectl create secret generic goalert -n "$NS" \
41-
--from-literal=GOALERT_DB_URL="$DB_URL" \
4221
--from-literal=GOALERT_DATA_ENCRYPTION_KEY="$ENC_KEY" \
4322
--dry-run=client -o yaml \
4423
| kubeseal --format yaml > goalert-sealed-secret.yaml
4524
```
46-
(Offline sealing: `kubeseal --cert <controller-cert.pem>`.)
4725

4826
## 2. First admin user
4927

5028
GoAlert has **no default login** - create the first admin with its CLI inside the
51-
pod (it uses `GOALERT_DB_URL` from the Secret above):
29+
pod (it reads the DB URL from the CNPG secret):
5230

5331
```bash
5432
kubectl -n "$NS" exec -it deploy/goalerts -- goalert add-user --admin --user admin
@@ -66,7 +44,9 @@ service (`:8081`) to reach the web UI.
6644

6745
| Value | Default | Notes |
6846
|---|---|---|
69-
| `goalert.existingSecret.name` | `goalert` | Secret holding the two keys above |
47+
| `goalert.dbUrlSecret.name` | `<instanceName>-pgsql-app` | CNPG secret the DB URL is read from |
48+
| `goalert.dbUrlSecret.key` | `fqdn-uri` | Key in that secret |
49+
| `goalert.encryptionKeySecret.name` | `goalert` | Secret holding the encryption key |
7050
| `postgresql.enabled` | `false` | Bundled Postgres removed; use CNPG |
7151
| `global.postgresql.enabled` | `true` | Provision the CNPG cluster via kubeaid-addons |
7252
| `global.postgresql.instanceName` | `goalert` | → cluster `goalert-pgsql` |

argocd-helm-charts/goalerts/templates/deployment.yaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,36 @@ spec:
2727
serviceAccountName: {{ include "goalert.serviceAccountName" . }}
2828
securityContext:
2929
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
{{- if .Values.pgchecker.enabled }}
31+
initContainers:
32+
- name: pgchecker
33+
image: "{{ .Values.pgchecker.image.repository }}:{{ .Values.pgchecker.image.tag }}"
34+
imagePullPolicy: {{ .Values.pgchecker.image.pullPolicy }}
35+
command:
36+
- sh
37+
- -c
38+
- |
39+
echo 'Waiting for PostgreSQL to become ready...'
40+
until nc -z -w 2 {{ .Values.pgchecker.host | default (printf "%s-pgsql-rw" .Values.global.postgresql.instanceName) }} {{ .Values.pgchecker.port }}; do
41+
sleep 2
42+
done
43+
echo 'PostgreSQL OK ✓'
44+
resources:
45+
{{- toYaml .Values.pgchecker.resources | nindent 12 }}
46+
{{- end }}
3047
containers:
3148
- name: {{ .Chart.Name }}
3249
env:
33-
{{- if .Values.goalert.existingSecret.name }}
34-
{{- range $key, $value := .Values.goalert.existingSecret.keys }}
35-
- name: {{ $key }}
50+
- name: GOALERT_DB_URL
3651
valueFrom:
3752
secretKeyRef:
38-
name: {{ $.Values.goalert.existingSecret.name }}
39-
key: {{ $value }}
40-
{{- end }}
41-
{{- else }}
42-
- name: GOALERT_DB_URL
43-
value: {{ include "goalert.databaseUrl" . | quote }}
53+
name: {{ .Values.goalert.dbUrlSecret.name }}
54+
key: {{ .Values.goalert.dbUrlSecret.key }}
4455
- name: GOALERT_DATA_ENCRYPTION_KEY
45-
value: {{ .Values.goalert.environment.GOALERT_DATA_ENCRYPTION_KEY | quote }}
46-
{{- end }}
56+
valueFrom:
57+
secretKeyRef:
58+
name: {{ .Values.goalert.encryptionKeySecret.name }}
59+
key: {{ .Values.goalert.encryptionKeySecret.key }}
4760
securityContext:
4861
{{- toYaml .Values.securityContext | nindent 12 }}
4962
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"

argocd-helm-charts/goalerts/values.yaml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ fullnameOverride: ""
99

1010
# DB URL + data-encryption key come from a sealed Secret in kubeaid-config-enableit.
1111
goalert:
12-
existingSecret:
12+
dbUrlSecret:
13+
name: goalert-pgsql-app
14+
key: fqdn-uri
15+
encryptionKeySecret:
1316
name: goalert
14-
keys:
15-
GOALERT_DB_URL: "GOALERT_DB_URL"
16-
GOALERT_DATA_ENCRYPTION_KEY: "GOALERT_DATA_ENCRYPTION_KEY"
17-
environment:
18-
GOALERT_DB_URL: ""
19-
GOALERT_DATA_ENCRYPTION_KEY: ""
17+
key: GOALERT_DATA_ENCRYPTION_KEY
2018

2119
# Postgres is a CloudNativePG cluster (see global.postgresql), not the bundled one.
2220
postgresql:
@@ -61,6 +59,22 @@ podSecurityContext: {}
6159
securityContext: {}
6260
replicaCount: 1
6361

62+
# Init container that blocks GoAlert until the database accepts connections.
63+
pgchecker:
64+
enabled: true
65+
image:
66+
repository: busybox
67+
tag: "1.37"
68+
pullPolicy: IfNotPresent
69+
host: ""
70+
port: 5432
71+
resources:
72+
requests:
73+
cpu: 10m
74+
memory: 16Mi
75+
limits:
76+
memory: 32Mi
77+
6478
# CloudNativePG cluster (goalert-pgsql) provisioned via the kubeaid-addons subchart.
6579
global:
6680
postgresql:

0 commit comments

Comments
 (0)