Skip to content

Commit 07157bd

Browse files
authored
feat: pgbouncer for postgresql (#1607)
1 parent aea8024 commit 07157bd

File tree

5 files changed

+206
-0
lines changed

5 files changed

+206
-0
lines changed

charts/sentry/templates/_helper.tpl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ Common Sentry environment variables
703703
- name: POSTGRES_NAME
704704
value: {{ include "sentry.postgresql.database" . | quote }}
705705
{{- end }}
706+
{{- if .Values.pgbouncer.enabled }}
707+
- name: POSTGRES_HOST
708+
value: {{ template "sentry.fullname" . }}-pgbouncer
709+
{{- else }}
706710
{{- if and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretKeys.host }}
707711
- name: POSTGRES_HOST
708712
valueFrom:
@@ -713,6 +717,11 @@ Common Sentry environment variables
713717
- name: POSTGRES_HOST
714718
value: {{ include "sentry.postgresql.host" . | quote }}
715719
{{- end }}
720+
{{- end }}
721+
{{- if .Values.pgbouncer.enabled }}
722+
- name: POSTGRES_PORT
723+
value: "5432"
724+
{{- else }}
716725
{{- if and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretKeys.port }}
717726
- name: POSTGRES_PORT
718727
valueFrom:
@@ -723,6 +732,7 @@ Common Sentry environment variables
723732
- name: POSTGRES_PORT
724733
value: {{ include "sentry.postgresql.port" . | quote }}
725734
{{- end }}
735+
{{- end }}
726736
{{- if and (eq .Values.filestore.backend "s3") .Values.filestore.s3.existingSecret }}
727737
- name: S3_ACCESS_KEY_ID
728738
valueFrom:
@@ -876,3 +886,66 @@ Common Sentry environment variables
876886
{{- print "autoscaling/v1" -}}
877887
{{- end -}}
878888
{{- end -}}
889+
890+
891+
{{/*
892+
Pgbouncer environment variables
893+
*/}}
894+
{{- define "sentry.pgbouncer.env" -}}
895+
{{- if and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretKeys.host }}
896+
- name: POSTGRESQL_HOST
897+
valueFrom:
898+
secretKeyRef:
899+
name: {{ .Values.externalPostgresql.existingSecret }}
900+
key: {{ default .Values.externalPostgresql.existingSecretKeys.host }}
901+
{{- else }}
902+
- name: POSTGRESQL_HOST
903+
value: {{ include "sentry.postgresql.host" . | quote }}
904+
{{- end }}
905+
{{- if and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretKeys.port }}
906+
- name: POSTGRESQL_PORT
907+
valueFrom:
908+
secretKeyRef:
909+
name: {{ .Values.externalPostgresql.existingSecret }}
910+
key: {{ default .Values.externalPostgresql.existingSecretKeys.port }}
911+
{{- else }}
912+
- name: POSTGRESQL_PORT
913+
value: {{ include "sentry.postgresql.port" . | quote }}
914+
{{- end }}
915+
{{- if and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretKeys.database }}
916+
- name: PGBOUNCER_DATABASE
917+
valueFrom:
918+
secretKeyRef:
919+
name: {{ .Values.externalPostgresql.existingSecret }}
920+
key: {{ default .Values.externalPostgresql.existingSecretKeys.database }}
921+
{{- else }}
922+
- name: PGBOUNCER_DATABASE
923+
value: {{ include "sentry.postgresql.database" . | quote }}
924+
{{- end }}
925+
{{- if .Values.postgresql.enabled }}
926+
- name: POSTGRESQL_PASSWORD
927+
valueFrom:
928+
secretKeyRef:
929+
name: {{ default (include "sentry.postgresql.fullname" .) .Values.postgresql.auth.existingSecret }}
930+
key: {{ default "postgres-password" .Values.postgresql.auth.secretKeys.adminPasswordKey }}
931+
{{- else if .Values.externalPostgresql.password }}
932+
- name: POSTGRESQL_PASSWORD
933+
value: {{ .Values.externalPostgresql.password | quote }}
934+
{{- else if .Values.externalPostgresql.existingSecret }}
935+
- name: POSTGRESQL_PASSWORD
936+
valueFrom:
937+
secretKeyRef:
938+
name: {{ .Values.externalPostgresql.existingSecret }}
939+
key: {{ or .Values.externalPostgresql.existingSecretKeys.password .Values.externalPostgresql.existingSecretKey "postgresql-password" }}
940+
{{- end }}
941+
{{- if and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretKeys.username }}
942+
- name: POSTGRESQL_USERNAME
943+
valueFrom:
944+
secretKeyRef:
945+
name: {{ .Values.externalPostgresql.existingSecret }}
946+
key: {{ default .Values.externalPostgresql.existingSecretKeys.username }}
947+
{{- else }}
948+
- name: POSTGRESQL_USERNAME
949+
value: {{ include "sentry.postgresql.username" . | quote }}
950+
{{- end }}
951+
{{- end -}}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{- if .Values.pgbouncer.enabled }}
2+
---
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: {{ template "sentry.fullname" . }}-pgbouncer
7+
labels:
8+
app: {{ template "sentry.fullname" . }}-pgbouncer
9+
spec:
10+
replicas: {{ .Values.pgbouncer.replicas }}
11+
selector:
12+
matchLabels:
13+
app: {{ template "sentry.fullname" . }}-pgbouncer
14+
{{- if .Values.pgbouncer.updateStrategy }}
15+
strategy:
16+
{{ toYaml .Values.pgbouncer.updateStrategy | nindent 4 }}
17+
{{- end }}
18+
template:
19+
metadata:
20+
labels:
21+
app: {{ template "sentry.fullname" . }}-pgbouncer
22+
spec:
23+
containers:
24+
- name: pgbouncer
25+
image: {{ .Values.pgbouncer.image.repository }}:{{ .Values.pgbouncer.image.tag }}
26+
imagePullPolicy: {{ .Values.pgbouncer.image.pullPolicy }}
27+
resources:
28+
{{ toYaml .Values.pgbouncer.resources | nindent 10 }}
29+
env:
30+
{{ include "sentry.pgbouncer.env" . | nindent 10 }}
31+
- name: PGBOUNCER_PORT
32+
value: "5432"
33+
- name: PGBOUNCER_AUTH_TYPE
34+
value: {{ .Values.pgbouncer.authType | quote }}
35+
- name: PGBOUNCER_MAX_CLIENT_CONN
36+
value: {{ .Values.pgbouncer.maxClientConn | quote }}
37+
- name: PGBOUNCER_DEFAULT_POOL_SIZE
38+
value: {{ .Values.pgbouncer.poolSize | quote }}
39+
- name: PGBOUNCER_POOL_MODE
40+
value: {{ .Values.pgbouncer.poolMode | quote }}
41+
ports:
42+
- containerPort: 5432
43+
name: pgbouncer
44+
protocol: TCP
45+
{{- if .Values.pgbouncer.nodeSelector }}
46+
nodeSelector:
47+
{{ toYaml .Values.pgbouncer.nodeSelector | nindent 8 }}
48+
{{- end }}
49+
{{- if .Values.pgbouncer.tolerations }}
50+
tolerations:
51+
{{ toYaml .Values.pgbouncer.tolerations | nindent 8 }}
52+
{{- end }}
53+
{{- if .Values.pgbouncer.affinity }}
54+
affinity:
55+
{{ toYaml .Values.pgbouncer.affinity | nindent 8 }}
56+
{{- end }}
57+
{{- if .Values.pgbouncer.topologySpreadConstraints }}
58+
topologySpreadConstraints:
59+
{{ toYaml .Values.pgbouncer.topologySpreadConstraints | nindent 8 }}
60+
{{- end }}
61+
{{- if .Values.pgbouncer.priorityClassName }}
62+
priorityClassName: "{{ .Values.pgbouncer.priorityClassName }}"
63+
{{- end }}
64+
terminationGracePeriodSeconds: 10
65+
{{- end }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{- if .Values.pgbouncer.enabled }}
2+
{{- if .Values.pgbouncer.podDisruptionBudget.enabled }}
3+
---
4+
apiVersion: policy/v1
5+
kind: PodDisruptionBudget
6+
metadata:
7+
name: {{ template "sentry.fullname" . }}-pgbouncer
8+
spec:
9+
{{- if and .Values.pgbouncer.podDisruptionBudget.minAvailable (not (hasKey .Values.pgbouncer.podDisruptionBudget "maxUnavailable")) }}
10+
minAvailable: {{ .Values.pgbouncer.podDisruptionBudget.minAvailable }}
11+
{{- else if .Values.pgbouncer.podDisruptionBudget.maxUnavailable }}
12+
maxUnavailable: {{ .Values.pgbouncer.podDisruptionBudget.maxUnavailable }}
13+
{{- end }}
14+
selector:
15+
matchLabels:
16+
app: {{ template "sentry.fullname" . }}-pgbouncer
17+
{{- end }}
18+
{{- end }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.pgbouncer.enabled }}
2+
---
3+
apiVersion: v1
4+
kind: Service
5+
metadata:
6+
name: {{ template "sentry.fullname" . }}-pgbouncer
7+
spec:
8+
selector:
9+
app: {{ template "sentry.fullname" . }}-pgbouncer
10+
ports:
11+
- name: pgbouncer
12+
port: 5432
13+
targetPort: 5432
14+
{{- end }}

charts/sentry/values.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,3 +2474,39 @@ revisionHistoryLimit: 10
24742474
# options: []
24752475

24762476
extraManifests: []
2477+
2478+
pgbouncer:
2479+
enabled: false
2480+
postgres:
2481+
cp_max: 10
2482+
cp_min: 5
2483+
host: ''
2484+
dbname: ''
2485+
user: ''
2486+
password: ''
2487+
image:
2488+
repository: "bitnami/pgbouncer"
2489+
tag: "1.23.1-debian-12-r5"
2490+
pullPolicy: IfNotPresent
2491+
replicas: 2
2492+
podDisruptionBudget:
2493+
enabled: true
2494+
# Define either 'minAvailable' or 'maxUnavailable', never both.
2495+
minAvailable: 1
2496+
# -- Maximum unavailable pods set in PodDisruptionBudget. If set, 'minAvailable' is ignored.
2497+
# maxUnavailable: 1
2498+
authType: "md5"
2499+
maxClientConn: "8192"
2500+
poolSize: "50"
2501+
poolMode: "transaction"
2502+
resources: {}
2503+
nodeSelector: {}
2504+
tolerations: []
2505+
affinity: {}
2506+
updateStrategy:
2507+
type: RollingUpdate
2508+
rollingUpdate:
2509+
maxUnavailable: 1
2510+
maxSurge: 25%
2511+
priorityClassName: ''
2512+
topologySpreadConstraints: []

0 commit comments

Comments
 (0)