Skip to content

Commit 082cfbb

Browse files
authored
Merge pull request #40 from noratanxz/ssl
feat: SSL connectivity to postgres db
2 parents 9f7fb99 + 91e58e2 commit 082cfbb

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ values which are defined [here](https://github.com/grafana/helm-charts/tree/main
258258
| global.dashboards.timerange | string | `"12h"` | how far back dashboards should look |
259259
| global.externalScheme | string | `"http"` | |
260260
| global.externalZone | string | `"svc.cluster.local"` | |
261-
| global.postgres | object | `{"alerts":{"groups":{"Basic":{"delay":"1m","enabled":true},"Connections":{"delay":"5m","enabled":true,"thresholds":{"critical":0.9,"notify":0.5,"warning":0.8}},"Notifications":{"delay":"15m","enabled":true,"thresholds":{"critical":0.9,"notify":0.5,"warning":0.8}}}},"database":"coder","exporter":{"image":"quay.io/prometheuscommunity/postgres-exporter"},"hostname":"localhost","mountSecret":"secret-postgres","password":null,"port":5432,"sslmode":"disable","username":"coder"}` | postgres connection information NOTE: these settings are global so we can parameterise some values which get rendered by subcharts |
261+
| global.postgres | object | `{"alerts":{"groups":{"Basic":{"delay":"1m","enabled":true},"Connections":{"delay":"5m","enabled":true,"thresholds":{"critical":0.9,"notify":0.5,"warning":0.8}},"Notifications":{"delay":"15m","enabled":true,"thresholds":{"critical":0.9,"notify":0.5,"warning":0.8}}}},"database":"coder","exporter":{"image":"quay.io/prometheuscommunity/postgres-exporter"},"hostname":"localhost","mountSecret":"secret-postgres","password":null,"port":5432,"sslmode":"disable","sslrootcert":"/home/coder/.postgresql/rootcert.pem","username":"coder","volumeMounts":[{"mountPath":"/home/coder/.postgresql","name":"pg-certs-mount","readOnly":true}],"volumes":[{"configMap":{"name":"pg-certs-mount-config-map"},"name":"pg-certs-mount"}]}` | postgres connection information NOTE: these settings are global so we can parameterise some values which get rendered by subcharts |
262262
| global.postgres.alerts | object | `{"groups":{"Basic":{"delay":"1m","enabled":true},"Connections":{"delay":"5m","enabled":true,"thresholds":{"critical":0.9,"notify":0.5,"warning":0.8}},"Notifications":{"delay":"15m","enabled":true,"thresholds":{"critical":0.9,"notify":0.5,"warning":0.8}}}}` | alerts for postgres |
263263
| global.telemetry | object | `{"metrics":{"scrape_interval":"15s","scrape_timeout":"12s"}}` | control telemetry collection |
264264
| global.telemetry.metrics | object | `{"scrape_interval":"15s","scrape_timeout":"12s"}` | control metric collection |

coder-observability/templates/_helpers.tpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ Create the name of the service account to use
6363

6464
{{/* Postgres connector string */}}
6565
{{- define "postgres-connector-string" -}}
66-
{{- if .Values.global.postgres.password -}}
66+
{{- if and .Values.global.postgres.password (eq .Values.global.postgres.sslmode "disable") -}}
6767
postgresql://{{ .Values.global.postgres.username }}:{{ urlquery .Values.global.postgres.password }}@{{ .Values.global.postgres.hostname }}:{{ .Values.global.postgres.port }}/{{ .Values.global.postgres.database }}?sslmode={{ .Values.global.postgres.sslmode }}
68-
{{- else if .Values.global.postgres.mountSecret -}}
68+
{{- else if and .Values.global.postgres.password (ne .Values.global.postgres.sslmode "disable") -}}
69+
postgresql://{{ .Values.global.postgres.username }}:{{ urlquery .Values.global.postgres.password }}@{{ .Values.global.postgres.hostname }}:{{ .Values.global.postgres.port }}/{{ .Values.global.postgres.database }}?sslmode={{ .Values.global.postgres.sslmode }}&sslrootcert={{ .Values.global.postgres.sslrootcert }}
70+
{{- else if and .Values.global.postgres.mountSecret (eq .Values.global.postgres.sslmode "disable") -}}
6971
postgresql://{{ .Values.global.postgres.username }}@{{ .Values.global.postgres.hostname }}:{{ .Values.global.postgres.port }}/{{ .Values.global.postgres.database }}?sslmode={{ .Values.global.postgres.sslmode }}
72+
{{- else if and .Values.global.postgres.mountSecret (ne .Values.global.postgres.sslmode "disable") -}}
73+
postgresql://{{ .Values.global.postgres.username }}@{{ .Values.global.postgres.hostname }}:{{ .Values.global.postgres.port }}/{{ .Values.global.postgres.database }}?sslmode={{ .Values.global.postgres.sslmode }}&sslrootcert={{ .Values.global.postgres.sslrootcert }}
7074
{{- else -}}
7175
{{ fail "either postgres.password or postgres.mountSecret must be defined" }}
7276
{{- end -}}

coder-observability/templates/statefulset-postgres-exporter.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ spec:
2929
env:
3030
- name: DATA_SOURCE_NAME
3131
value: '{{ include "postgres-connector-string" . }}'
32-
{{ include "postgres-secret-mount" . | nindent 10 }}
32+
{{ include "postgres-secret-mount" . | nindent 10 }}
33+
34+
volumeMounts:
35+
{{ toYaml .Values.global.postgres.volumeMounts | nindent 12 }}
36+
37+
volumes:
38+
{{ toYaml .Values.global.postgres.volumes | nindent 8 }}

coder-observability/values.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,24 @@ global:
123123
password:
124124
database: coder
125125
sslmode: disable
126+
# add root cert path if using SSL
127+
sslrootcert: /home/coder/.postgresql/rootcert.pem
128+
126129
# ensure that your secret has a field named `PGPASSWORD`
127130
mountSecret: "secret-postgres"
128131
exporter:
129132
image: "quay.io/prometheuscommunity/postgres-exporter"
130133

134+
volumes:
135+
- name: "pg-certs-mount"
136+
configMap:
137+
name: "pg-certs-mount-config-map"
138+
139+
volumeMounts:
140+
- name: "pg-certs-mount"
141+
mountPath: "/home/coder/.postgresql"
142+
readOnly: true
143+
131144
# global.postgres.alerts -- alerts for postgres
132145
alerts:
133146
groups:

compiled/resources.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12219,6 +12219,14 @@ spec:
1221912219
envFrom:
1222012220
- secretRef:
1222112221
name: secret-postgres
12222+
volumeMounts:
12223+
- mountPath: /home/coder/.postgresql
12224+
name: pg-certs-mount
12225+
readOnly: true
12226+
volumes:
12227+
- configMap:
12228+
name: pg-certs-mount-config-map
12229+
name: pg-certs-mount
1222212230
---
1222312231
# Source: coder-observability/templates/statefulset-runbook-viewer.yaml
1222412232
apiVersion: apps/v1

0 commit comments

Comments
 (0)