Skip to content

Commit

Permalink
feat(helm): roll deployments when database config changes (#818)
Browse files Browse the repository at this point in the history
Automatically restart deployed pods when the database configuration
changes by setting the checksums of the ConfigMaps and Secrets as
annotations of the pod.
  • Loading branch information
mdonadoni committed Aug 23, 2024
1 parent 7b472fe commit 04082f4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 46 deletions.
11 changes: 11 additions & 0 deletions helm/reana/templates/database-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "reana.prefix" . }}-db-secrets
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/resource-policy": keep
type: Opaque
data:
user: {{ .Values.secrets.database.user | default "reana" | b64enc }}
password: {{ .Values.secrets.database.password | default "reana" | b64enc }}
21 changes: 21 additions & 0 deletions helm/reana/templates/pgbouncer-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.pgbouncer.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "reana.prefix" . }}-pgbouncer-config
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 }}
{{- end }}
12 changes: 12 additions & 0 deletions helm/reana/templates/pgbouncer-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.pgbouncer.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "reana.prefix" . }}-pgbouncer-secrets
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/resource-policy": keep
type: Opaque
data:
userlist: {{ printf "%s %s" (.Values.secrets.database.user | default "reana" | quote) (.Values.secrets.database.password | default "reana" | quote) | b64enc}}
{{- end }}
26 changes: 5 additions & 21 deletions helm/reana/templates/pgbouncer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@ spec:
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:
Expand All @@ -47,6 +27,10 @@ spec:
metadata:
labels:
app: {{ include "reana.prefix" . }}-pgbouncer
annotations:
checksum/pgbouncer-config: {{ include (print $.Template.BasePath "/pgbouncer-config.yaml") . | sha256sum }}
checksum/pgbouncer-secrets: {{ include (print $.Template.BasePath "/pgbouncer-secrets.yaml") . | sha256sum }}
checksum/database-secrets: {{ include (print $.Template.BasePath "/database-secrets.yaml") . | sha256sum }}
spec:
containers:
- name: pgbouncer
Expand All @@ -55,7 +39,7 @@ spec:
- containerPort: 6432
envFrom:
- configMapRef:
name: {{ include "reana.prefix" . }}-pgbouncer-conf
name: {{ include "reana.prefix" . }}-pgbouncer-config
env:
- name: POSTGRESQL_USERNAME
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions helm/reana/templates/reana-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ spec:
metadata:
labels:
app: {{ include "reana.prefix" . }}-server
annotations:
checksum/database-config: {{ include (print $.Template.BasePath "/database-config.yaml") . | sha256sum }}
checksum/database-secrets: {{ include (print $.Template.BasePath "/database-secrets.yaml") . | sha256sum }}
spec:
serviceAccountName: {{ include "reana.prefixed_infrastructure_svaccount_name" . }}
containers:
Expand Down
3 changes: 3 additions & 0 deletions helm/reana/templates/reana-workflow-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ spec:
metadata:
labels:
app: {{ include "reana.prefix" . }}-workflow-controller
annotations:
checksum/database-config: {{ include (print $.Template.BasePath "/database-config.yaml") . | sha256sum }}
checksum/database-secrets: {{ include (print $.Template.BasePath "/database-secrets.yaml") . | sha256sum }}
spec:
serviceAccountName: {{ include "reana.prefixed_infrastructure_svaccount_name" . }}
containers:
Expand Down
25 changes: 0 additions & 25 deletions helm/reana/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "reana.prefix" . }}-db-secrets
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/resource-policy": keep
type: Opaque
data:
user: {{ .Values.secrets.database.user | default "reana" | b64enc }}
password: {{ .Values.secrets.database.password | default "reana" | b64enc }}
{{- if .Values.pgbouncer.enabled }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "reana.prefix" . }}-pgbouncer-secrets
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/resource-policy": keep
type: Opaque
data:
userlist: {{ printf "%s %s" (.Values.secrets.database.user | default "reana" | quote) (.Values.secrets.database.password | default "reana" | quote) | b64enc}}
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "reana.prefix" . }}-cern-sso-secrets
namespace: {{ .Release.Namespace }}
Expand Down

0 comments on commit 04082f4

Please sign in to comment.