Skip to content

Commit

Permalink
feat(helm): add support for PgBouncer (#818)
Browse files Browse the repository at this point in the history
Closes #819
  • Loading branch information
mdonadoni committed Aug 23, 2024
1 parent cd94d12 commit 7b472fe
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 55 deletions.
3 changes: 3 additions & 0 deletions helm/configurations/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ components:
image: docker.io/reanahub/reana-message-broker
reana_ui:
image: docker.io/reanahub/reana-ui

pgbouncer:
enabled: true
6 changes: 6 additions & 0 deletions helm/reana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ This Helm automatically prefixes all names using the release name to avoid colli
| `reana_hostname` | REANA hostname (e.g. reana.example.org) | None |
| `namespace_runtime` | Namespace in which the REANA runtime pods (workflow engines, jobs etc...) will run | `.Release.Namespace` |
| `naming_scheme` | REANA component naming scheme | None |
| `pgbouncer.enabled` | Instantiate PgBouncer inside the cluster to pool database connections | false |
| `pgbouncer.image` | [PgBouncer image](https://hub.docker.com/r/bitnami/pgbouncer/) to use | `bitnami/pgbouncer:1.23.1` |
| `pgbouncer.pool_mode` | Pool mode to use (session, transaction, statement) | transaction |
| `pgbouncer.max_client_conn` | Maximum number of client connections allowed | 1000 |
| `pgbouncer.max_db_connections` | Maximum number of server connections allowed | 100 |
| `pgbouncer.environment` | Additional PgBouncer environment variables | `{}` |
| `secrets.cern.sso.CERN_CONSUMER_KEY` | CERN SSO consumer key | None |
| `secrets.cern.sso.CERN_CONSUMER_SECRET` | **[Do not use in production, use secrets instead]** CERN SSO consumer secret | None |
| `secrets.database.password` | **[Do not use in production, use secrets instead]** PostgreSQL database password | None |
Expand Down
40 changes: 16 additions & 24 deletions helm/reana/templates/cronjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ spec:
tty: true
stdin: true
{{- end }}
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-database-config
env:
{{- if .Values.reana_hostname }}
- name: REANA_HOSTNAME
value: {{ .Values.reana_hostname }}
{{- end }}
{{- range $key, $value := .Values.db_env_config }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.debug.enabled }}
- name: FLASK_ENV
value: "development"
{{- else }}
{{- end }}
- name: REANA_DB_USERNAME
valueFrom:
secretKeyRef:
Expand All @@ -53,7 +52,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
- name: REANA_NOTIFICATIONS_ENABLED
value: "{{ .Values.notifications.enabled }}"
- name: REANA_EMAIL_RECEIVER
Expand Down Expand Up @@ -154,21 +152,20 @@ spec:
tty: true
stdin: true
{{- end }}
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-database-config
env:
- name: REANA_PERIODIC_RESOURCE_QUOTA_UPDATE_POLICY
value: "true"
{{- if .Values.reana_hostname }}
- name: REANA_HOSTNAME
value: {{ .Values.reana_hostname }}
{{- end }}
{{- range $key, $value := .Values.db_env_config }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.debug.enabled }}
- name: FLASK_ENV
value: "development"
{{- else }}
{{- end }}
- name: REANA_DB_USERNAME
valueFrom:
secretKeyRef:
Expand All @@ -179,7 +176,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
- name: REANA_COMPONENT_PREFIX
value: {{ include "reana.prefix" . }}
- name: REANA_INFRASTRUCTURE_KUBERNETES_NAMESPACE
Expand Down Expand Up @@ -239,19 +235,18 @@ spec:
tty: true
stdin: true
{{- end }}
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-database-config
env:
{{- if .Values.reana_hostname }}
- name: REANA_HOSTNAME
value: {{ .Values.reana_hostname }}
{{- end }}
{{- range $key, $value := .Values.db_env_config }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.debug.enabled }}
- name: FLASK_ENV
value: "development"
{{- else }}
{{- end }}
- name: REANA_DB_USERNAME
valueFrom:
secretKeyRef:
Expand All @@ -262,7 +257,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
- name: REANA_COMPONENT_PREFIX
value: {{ include "reana.prefix" . }}
- name: REANA_ADMIN_ACCESS_TOKEN
Expand Down Expand Up @@ -333,19 +327,18 @@ spec:
tty: true
stdin: true
{{- end }}
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-database-config
env:
{{- if .Values.reana_hostname }}
- name: REANA_HOSTNAME
value: {{ .Values.reana_hostname }}
{{- end }}
{{- range $key, $value := .Values.db_env_config }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.debug.enabled }}
- name: FLASK_ENV
value: "development"
{{- else }}
{{- end }}
- name: REANA_DB_USERNAME
valueFrom:
secretKeyRef:
Expand All @@ -356,7 +349,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
- name: REANA_COMPONENT_PREFIX
value: {{ include "reana.prefix" . }}
- name: REANA_ADMIN_ACCESS_TOKEN
Expand Down
17 changes: 17 additions & 0 deletions helm/reana/templates/database-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "reana.prefix" . }}-database-config
namespace: {{ .Release.Namespace }}
data:
REANA_DB_NAME: {{ .Values.db_env_config.REANA_DB_NAME | quote }}
{{- if .Values.pgbouncer.enabled }}
REANA_DB_HOST: {{ include "reana.prefix" . }}-pgbouncer
REANA_DB_PORT: "6432"
{{- else if .Values.components.reana_db.enabled }}
REANA_DB_HOST: {{ include "reana.prefix" . }}-db
REANA_DB_PORT: "5432"
{{- else }}
REANA_DB_HOST: {{ .Values.db_env_config.REANA_DB_HOST | quote }}
REANA_DB_PORT: {{ .Values.db_env_config.REANA_DB_PORT | quote }}
{{- end }}
88 changes: 88 additions & 0 deletions helm/reana/templates/pgbouncer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{{- if .Values.pgbouncer.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "reana.prefix" . }}-pgbouncer
namespace: {{ .Release.Namespace }}
spec:
type: ClusterIP
selector:
app: {{ include "reana.prefix" . }}-pgbouncer
ports:
- port: 6432
targetPort: 6432
protocol: TCP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "reana.prefix" . }}-pgbouncer-conf
namespace: {{ .Release.Namespace }}
data:
PGBOUNCER_POOL_MODE: {{ .Values.pgbouncer.pool_mode | quote }}
PGBOUNCER_MAX_CLIENT_CONN: {{ .Values.pgbouncer.max_client_conn | quote }}
PGBOUNCER_MAX_DB_CONNECTIONS: {{ .Values.pgbouncer.max_db_connections | quote }}
PGBOUNCER_DEFAULT_POOL_SIZE: {{ .Values.pgbouncer.max_db_connections | quote }}
{{- if .Values.components.reana_db.enabled }}
PGBOUNCER_DATABASE: reana
POSTGRESQL_HOST: {{ include "reana.prefix" . }}-db
POSTGRESQL_PORT: "5432"
{{- else }}
PGBOUNCER_DATABASE: {{ .Values.db_env_config.REANA_DB_NAME | quote }}
POSTGRESQL_HOST: {{ .Values.db_env_config.REANA_DB_HOST | quote }}
POSTGRESQL_PORT: {{ .Values.db_env_config.REANA_DB_PORT | quote }}
{{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "reana.prefix" . }}-pgbouncer
namespace: {{ .Release.Namespace }}
spec:
replicas: {{ if .Values.maintenance.enabled -}} 0 {{- else -}} 1 {{- end }}
selector:
matchLabels:
app: {{ include "reana.prefix" . }}-pgbouncer
template:
metadata:
labels:
app: {{ include "reana.prefix" . }}-pgbouncer
spec:
containers:
- name: pgbouncer
image: {{ .Values.pgbouncer.image | quote }}
ports:
- containerPort: 6432
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-pgbouncer-conf
env:
- name: POSTGRESQL_USERNAME
valueFrom:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: user
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
- name: PGBOUNCER_USERLIST
valueFrom:
secretKeyRef:
name: {{ include "reana.prefix" . }}-pgbouncer-secrets
key: userlist
{{- range $key, $value := .Values.pgbouncer.environment }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.node_label_infrastructuredb }}
{{- $full_label := split "=" .Values.node_label_infrastructuredb }}
nodeSelector:
{{ $full_label._0 }}: {{ $full_label._1 }}
{{- else if .Values.node_label_infrastructure }}
{{- $full_label := split "=" .Values.node_label_infrastructure }}
nodeSelector:
{{ $full_label._0 }}: {{ $full_label._1 }}
{{- end }}
{{- end }}
7 changes: 0 additions & 7 deletions helm/reana/templates/reana-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ spec:
value: "Europe/Zurich"
- name: POSTGRES_DB
value: reana
{{- if not .Values.debug.enabled }}
- name: POSTGRES_USER
value: reana
- name: POSTGRES_PASSWORD
value: reana
{{- else }}
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
Expand All @@ -75,7 +69,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
volumeMounts:
- mountPath: /var/lib/postgresql/data
subPath: db
Expand Down
20 changes: 8 additions & 12 deletions helm/reana/templates/reana-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ spec:
mountPath: '/var/reana/uwsgi'
- name: reana-config
mountPath: '/var/reana/config'
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-database-config
env:
- name: REANA_COMPONENT_PREFIX
value: {{ include "reana.prefix" . }}
Expand Down Expand Up @@ -100,10 +103,6 @@ spec:
- name: REANA_WORKFLOW_TERMINATION_QUOTA_UPDATE_POLICY
value: {{ tpl .Values.quota.workflow_termination_update_policy . | default "null" }}
{{- end }}
{{- range $key, $value := .Values.db_env_config }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- range $key, $value := .Values.components.reana_server.environment }}
- name: {{ $key }}
value: {{ $value | quote }}
Expand Down Expand Up @@ -169,7 +168,7 @@ spec:
value: ""
- name: GIT_SSL_NO_VERIFY
value: "true"
{{- else }}
{{- end }}
- name: REANA_DB_USERNAME
valueFrom:
secretKeyRef:
Expand All @@ -180,7 +179,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
- name: REANA_NOTIFICATIONS_ENABLED
value: "{{ .Values.notifications.enabled }}"
{{- if .Values.notifications.enabled }}
Expand Down Expand Up @@ -223,17 +221,16 @@ spec:
{{- end }}
- mountPath: {{ .Values.shared_storage.shared_volume_mount_path }}
name: reana-shared-volume
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-database-config
env:
- name: REANA_COMPONENT_PREFIX
value: {{ include "reana.prefix" . }}
- name: REANA_INFRASTRUCTURE_KUBERNETES_NAMESPACE
value: {{ .Release.Namespace }}
- name: REANA_RUNTIME_KUBERNETES_NAMESPACE
value: {{ .Values.namespace_runtime | default .Release.Namespace }}
{{- range $key, $value := .Values.db_env_config }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- range $key, $value := .Values.components.reana_server.environment }}
- name: {{ $key }}
value: {{ $value | quote }}
Expand All @@ -256,7 +253,7 @@ spec:
value: ""
- name: GIT_SSL_NO_VERIFY
value: "true"
{{- else }}
{{- end }}
- name: REANA_DB_USERNAME
valueFrom:
secretKeyRef:
Expand All @@ -267,7 +264,6 @@ spec:
secretKeyRef:
name: {{ include "reana.prefix" . }}-db-secrets
key: password
{{- end }}
{{- if .Values.login }}
- name: LOGIN_PROVIDERS_CONFIGS
value: {{ .Values.login | toJson | quote }}
Expand Down
Loading

0 comments on commit 7b472fe

Please sign in to comment.