From 0072b14a6a7fb044ac2ecf916ba8061d34828a93 Mon Sep 17 00:00:00 2001 From: Tim Campbell Date: Thu, 11 Jan 2024 03:56:14 -0800 Subject: [PATCH] Add support for read replica (#105) --- templates/configmap-env.yaml | 15 +++++++++++++++ templates/deployment-sidekiq.yaml | 7 +++++++ templates/deployment-streaming.yaml | 7 +++++++ templates/deployment-web.yaml | 7 +++++++ values.yaml | 13 +++++++++++++ 5 files changed, 49 insertions(+) diff --git a/templates/configmap-env.yaml b/templates/configmap-env.yaml index 96e70c3d..51fc9daf 100644 --- a/templates/configmap-env.yaml +++ b/templates/configmap-env.yaml @@ -15,6 +15,21 @@ data: DB_NAME: {{ .Values.postgresql.auth.database }} DB_POOL: {{ include "mastodon.maxDbPool" . }} DB_USER: {{ .Values.postgresql.auth.username }} + {{- if .Values.postgresql.readReplica.hostname }} + REPLICA_DB_HOST: {{ .Values.postgresql.readReplica.hostname }} + {{- end }} + {{- if .Values.postgresql.readReplica.port }} + REPLICA_DB_PORT: {{ .Values.postgresql.readReplica.port }} + {{- end }} + {{- if .Values.postgresql.readReplica.auth.database }} + REPLICA_DB_NAME: {{ .Values.postgresql.readReplica.auth.database }} + {{- end }} + {{- if .Values.postgresql.readReplica.auth.username }} + REPLICA_DB_USER: {{ .Values.postgresql.readReplica.auth.username }} + {{- end }} + {{- if .Values.postgresql.readReplica.auth.password }} + REPLICA_DB_PASS: {{ .Values.postgresql.readReplica.auth.password }} + {{- end }} PREPARED_STATEMENTS: {{ .Values.mastodon.preparedStatements | quote }} DEFAULT_LOCALE: {{ .Values.mastodon.locale }} {{- if .Values.elasticsearch.enabled }} diff --git a/templates/deployment-sidekiq.yaml b/templates/deployment-sidekiq.yaml index 2f75309d..9bece8f4 100644 --- a/templates/deployment-sidekiq.yaml +++ b/templates/deployment-sidekiq.yaml @@ -102,6 +102,13 @@ spec: secretKeyRef: name: {{ template "mastodon.postgresql.secretName" $context }} key: password + {{- if $context.Values.postgresql.readReplica.auth.existingSecret }} + - name: "REPLICA_DB_PASS" + valueFrom: + secretKeyRef: + name: {{ $context.Values.postgresql.readReplica.auth.existingSecret }} + key: password + {{- end }} - name: "REDIS_PASSWORD" valueFrom: secretKeyRef: diff --git a/templates/deployment-streaming.yaml b/templates/deployment-streaming.yaml index 9924fe19..7ce100a0 100644 --- a/templates/deployment-streaming.yaml +++ b/templates/deployment-streaming.yaml @@ -56,6 +56,13 @@ spec: secretKeyRef: name: {{ template "mastodon.postgresql.secretName" . }} key: password + {{- if .Values.postgresql.readReplica.auth.existingSecret }} + - name: "REPLICA_DB_PASS" + valueFrom: + secretKeyRef: + name: {{ .Values.postgresql.readReplica.auth.existingSecret }} + key: password + {{- end }} - name: "REDIS_PASSWORD" valueFrom: secretKeyRef: diff --git a/templates/deployment-web.yaml b/templates/deployment-web.yaml index b736a9d1..5bf035f6 100644 --- a/templates/deployment-web.yaml +++ b/templates/deployment-web.yaml @@ -79,6 +79,13 @@ spec: secretKeyRef: name: {{ template "mastodon.postgresql.secretName" . }} key: password + {{- if .Values.postgresql.readReplica.auth.existingSecret }} + - name: "REPLICA_DB_PASS" + valueFrom: + secretKeyRef: + name: {{ .Values.postgresql.readReplica.auth.existingSecret}} + key: password + {{- end }} - name: "REDIS_PASSWORD" valueFrom: secretKeyRef: diff --git a/values.yaml b/values.yaml index 6a0abcf3..b9fd707c 100644 --- a/values.yaml +++ b/values.yaml @@ -362,6 +362,19 @@ postgresql: # with a key of password set to the password you want existingSecret: "" + # Options for a read-only replica. + # If enabled, mastodon uses existing defaults for postgres for these values as well. + # Documentation for more information on this feature: + # https://docs.joinmastodon.org/admin/scaling/#read-replicas + readReplica: + hostname: + port: + auth: + database: + username: + password: + existingSecret: + # https://github.com/bitnami/charts/tree/master/bitnami/redis#parameters redis: # disable if you want to use an existing redis instance; in which case the