From ba6c1ca1ed3c93efa0e29451c6eb2fc02b72b12d Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Tue, 15 Nov 2022 20:19:57 +0100
Subject: [PATCH] fix(mastodon): Fix broken DB_POOL variable

This patch introduces some logic to automatically find the
ideal `DB_POOL` variable for the deployment and update the
mastodon source link to new organisation.
---
 charts/mastodon/Chart.yaml                   |  4 ++--
 charts/mastodon/README.md                    |  4 ++--
 charts/mastodon/templates/_helpers.tpl       | 12 ++++++++++++
 charts/mastodon/templates/configmap-env.yaml |  2 +-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/charts/mastodon/Chart.yaml b/charts/mastodon/Chart.yaml
index 6d49805e9..4a947aae2 100644
--- a/charts/mastodon/Chart.yaml
+++ b/charts/mastodon/Chart.yaml
@@ -7,11 +7,11 @@ keywords:
     - mastodon
     - activitypub
 sources:
-    - https://github.com/tootsuite/mastodon
+    - https://github.com/mastodon/mastodon
     - https://git.shivering-isles.com/shivering-isles/infrastructure-gitops/-/tree/main/charts/mastodon
 
 type: application
-version: 3.0.6
+version: 3.0.7
 appVersion: v3.5.5
 
 dependencies:
diff --git a/charts/mastodon/README.md b/charts/mastodon/README.md
index 7fbdde45d..a5187be30 100644
--- a/charts/mastodon/README.md
+++ b/charts/mastodon/README.md
@@ -1,6 +1,6 @@
 # mastodon
 
-![Version: 3.0.6](https://img.shields.io/badge/Version-3.0.6-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v3.5.5](https://img.shields.io/badge/AppVersion-v3.5.5-informational?style=flat-square)
+![Version: 3.0.7](https://img.shields.io/badge/Version-3.0.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v3.5.5](https://img.shields.io/badge/AppVersion-v3.5.5-informational?style=flat-square)
 
 Mastodon is a free, open-source social network server based on ActivityPub.
 
@@ -8,7 +8,7 @@ Mastodon is a free, open-source social network server based on ActivityPub.
 
 ## Source Code
 
-* <https://github.com/tootsuite/mastodon>
+* <https://github.com/mastodon/mastodon>
 * <https://git.shivering-isles.com/shivering-isles/infrastructure-gitops/-/tree/main/charts/mastodon>
 
 ## Requirements
diff --git a/charts/mastodon/templates/_helpers.tpl b/charts/mastodon/templates/_helpers.tpl
index 207780b34..2d1196e8d 100644
--- a/charts/mastodon/templates/_helpers.tpl
+++ b/charts/mastodon/templates/_helpers.tpl
@@ -136,3 +136,15 @@ Return true if a mastodon secret object should be created
     {{- true -}}
 {{- end -}}
 {{- end -}}
+
+{{/*
+Find highest number of needed database connections to set DB_POOL variable
+*/}}
+{{- define "mastodon.maxDbPool" -}}
+{{/* Default MAX_THREADS for Puma is 5 */}}
+{{- $poolSize := 5 }}
+{{- range .Values.mastodon.sidekiq.workers }}
+{{- $poolSize = max $poolSize .concurrency }}
+{{- end }}
+{{- $poolSize | quote }}
+{{- end }}
\ No newline at end of file
diff --git a/charts/mastodon/templates/configmap-env.yaml b/charts/mastodon/templates/configmap-env.yaml
index 3a1df65fa..4d0195568 100644
--- a/charts/mastodon/templates/configmap-env.yaml
+++ b/charts/mastodon/templates/configmap-env.yaml
@@ -13,7 +13,7 @@ data:
   DB_PORT: {{ .Values.postgresql.postgresqlPort | default "5432" | quote }}
   {{- end }}
   DB_NAME: {{ .Values.postgresql.auth.database }}
-  DB_POOL: {{ .Values.mastodon.sidekiq.concurrency | quote }}
+  DB_POOL: {{ include "mastodon.maxDbPool" . }}
   DB_USER: {{ .Values.postgresql.auth.username }}
   DEFAULT_LOCALE: {{ .Values.mastodon.locale }}
   {{- if .Values.elasticsearch.enabled }}
-- 
GitLab