From c23b291f250a3f0d9671872c5ae826e42e4848ac Mon Sep 17 00:00:00 2001 From: jon4hz Date: Sat, 14 Jan 2023 19:48:07 +0100 Subject: [PATCH] fix: mongodb connection --- helm-charts/infisical/templates/_helpers.tpl | 24 +++++++++++++++++++ .../templates/backend-deployment.yaml | 2 ++ helm-charts/infisical/values.yaml | 13 ++++++---- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/helm-charts/infisical/templates/_helpers.tpl b/helm-charts/infisical/templates/_helpers.tpl index 8012f636a6..2f2bf2a3ab 100644 --- a/helm-charts/infisical/templates/_helpers.tpl +++ b/helm-charts/infisical/templates/_helpers.tpl @@ -112,3 +112,27 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- end -}} {{- end -}} +{{/* +Create the mongodb connection string. +*/}} +{{- define "infisical.mongodb.connectionString" -}} +{{- $host := include "infisical.mongodb.fullname" . -}} +{{- $port := 27017 -}} +{{- $user := "root" -}} +{{- $pass := "root" -}} +{{- if .Values.mongodbConnection -}} +{{- if .Values.mongodbConnection.host -}} +{{- $host = .Values.mongodbConnection.host -}} +{{- end -}} +{{- if .Values.mongodbConnection.port -}} +{{- $port = .Values.mongodbConnection.port -}} +{{- end -}} +{{- if .Values.mongodbConnection.username -}} +{{- $user = .Values.mongodbConnection.username -}} +{{- end -}} +{{- if .Values.mongodbConnection.password -}} +{{- $pass = .Values.mongodbConnection.password -}} +{{- end -}} +{{- end -}} +{{- printf "mongodb://%s:%s@%s:%d/" $user $pass $host $port -}} +{{- end -}} diff --git a/helm-charts/infisical/templates/backend-deployment.yaml b/helm-charts/infisical/templates/backend-deployment.yaml index 01e216092e..7e4b922a25 100644 --- a/helm-charts/infisical/templates/backend-deployment.yaml +++ b/helm-charts/infisical/templates/backend-deployment.yaml @@ -30,6 +30,8 @@ spec: name: {{ .Values.backend.kubeSecretRef }} {{- end }} env: + - name: MONGO_URL + value: {{ include "infisical.mongodb.connectionString" . | quote }} {{- range $key, $value := .Values.backendEnvironmentVariables }} {{- if $value | quote | eq "MUST_REPLACE" }} {{ fail "Environment variables are not set. Please set all environment variables to continue." }} diff --git a/helm-charts/infisical/values.yaml b/helm-charts/infisical/values.yaml index 584ec78605..e51f081d3d 100644 --- a/helm-charts/infisical/values.yaml +++ b/helm-charts/infisical/values.yaml @@ -43,6 +43,14 @@ mongodb: service: annotations: {} + +# Recommended to replace with Mongo Cloud URI as the DB instance in the cluster does not have persistence yet +mongodbConnection: {} + # host: mymongodb.com # defaults to the internal mongo service + # port: 27017 + # username: root + # password: root + ingress: enabled: true annotations: @@ -56,6 +64,7 @@ ingress: pathType: Prefix tls: [] + ## Complete Ingress example # ingress: # enabled: true @@ -94,8 +103,4 @@ backendEnvironmentVariables: SMTP_USERNAME: MUST_REPLACE SMTP_PASSWORD: MUST_REPLACE - # Recommended to replace with Mongo Cloud URI as the DB instance in the cluster does not have persistence yet - MONGO_URL: mongodb://root:root@mongodb-service:27017/ - # frontendEnvironmentVariables: - \ No newline at end of file