From 6b2d3eb773291451b67faa7df0d32e7b2b4671c2 Mon Sep 17 00:00:00 2001
From: Filip Rafaj <filip.rafaj@prusa3d.cz>
Date: Thu, 9 May 2024 15:46:38 +0200
Subject: [PATCH] fix mongodb secret condition and helper

---
 docker/kubernetes/helm/templates/_helpers.tpl    | 6 +++---
 docker/kubernetes/helm/templates/db-secrets.yaml | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/docker/kubernetes/helm/templates/_helpers.tpl b/docker/kubernetes/helm/templates/_helpers.tpl
index 659d845e2ae..604c7b09b52 100644
--- a/docker/kubernetes/helm/templates/_helpers.tpl
+++ b/docker/kubernetes/helm/templates/_helpers.tpl
@@ -245,12 +245,12 @@ Return mongodb username
 Return mongodb secretName
 */}}
 {{- define "novu.mongodb.secretName" -}}
-{{- if .Values.mongodb.enabled -}}
+{{- if and (not .Values.externalDatabase.existingSecret) (not .Values.mongodb.auth.existingSecret) }}
     {{- printf "%s-url-mongodb" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
 {{- else if .Values.externalDatabase.existingSecret -}}
     {{- printf "%s" .Values.externalDatabase.existingSecret -}}
-{{- else -}}
-     {{- printf "%s-externaldb" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
+{{- else if .Values.mongodb.auth.existingSecret -}}
+    {{- printf "%s" .Values.mongodb.auth.existingSecret -}}
 {{- end -}}
 {{- end -}}
 
diff --git a/docker/kubernetes/helm/templates/db-secrets.yaml b/docker/kubernetes/helm/templates/db-secrets.yaml
index 4bcfb9095f6..9ba65d864eb 100644
--- a/docker/kubernetes/helm/templates/db-secrets.yaml
+++ b/docker/kubernetes/helm/templates/db-secrets.yaml
@@ -1,8 +1,7 @@
-{{- if and (not .Values.externalDatabase.existingSecret) (not .Values.mongodb.existingSecret) }}
+{{- if and (not .Values.externalDatabase.existingSecret) (not .Values.mongodb.auth.existingSecret) }}
 apiVersion: v1
 kind: Secret
 metadata:
-  
   name: {{ include "novu.mongodb.secretName" . }}
   namespace: {{ include "common.names.namespace" . | quote }}
   labels: {{- include "common.labels.standard" . | nindent 4 }}