From dbe5441e94c4ab63aec32556e333f041db73e426 Mon Sep 17 00:00:00 2001 From: Saranya-jena Date: Wed, 27 Sep 2023 22:14:03 +0530 Subject: [PATCH] Added changes requires for mongo support Signed-off-by: Saranya-jena --- charts/litmus/templates/_helpers.tpl | 12 ++++++ .../templates/auth-server-deployment.yaml | 41 ++++++++++++++++++- .../templates/controlplane-configs.yaml | 2 +- .../litmus/templates/server-deployment.yaml | 41 ++++++++++++++++++- charts/litmus/values.yaml | 16 +++++--- 5 files changed, 103 insertions(+), 9 deletions(-) diff --git a/charts/litmus/templates/_helpers.tpl b/charts/litmus/templates/_helpers.tpl index fbc169af..d5490fb5 100644 --- a/charts/litmus/templates/_helpers.tpl +++ b/charts/litmus/templates/_helpers.tpl @@ -78,4 +78,16 @@ Check for existing secret {{- end -}} {{- end -}} +{{/* + Returns mongodb connection string +*/}} +{{- define "litmus-portal.mongodbConnectionString" -}} +{{- $hosts := "" -}} +{{- $count := (.Values.mongodb.replicaCount | int) -}} +{{- range $i, $e := until $count -}} + {{- $host := printf "%s-mongodb-%d.%s-mongodb-headless" $.Release.Name $i $.Release.Name -}} + {{- $hosts = printf "%s%s:%d," $hosts $host 27017 -}} +{{- end -}} +mongodb://{{ trimSuffix "," $hosts }}/admin +{{- end -}} diff --git a/charts/litmus/templates/auth-server-deployment.yaml b/charts/litmus/templates/auth-server-deployment.yaml index e760f052..ce67ecc4 100644 --- a/charts/litmus/templates/auth-server-deployment.yaml +++ b/charts/litmus/templates/auth-server-deployment.yaml @@ -35,6 +35,45 @@ spec: imagePullSecrets: {{ toYaml .Values.image.imagePullSecrets | indent 8 }} {{- end }} + initContainers: + - name: wait-for-mongodb + image: mongo:latest + imagePullPolicy: {{ .Values.portal.server.waitForMongodb.image.pullPolicy }} + command: ["/bin/sh", "-c"] + env: + - name: DB_PASSWORD + {{- if .Values.mongodb.enabled }} + {{- if not .Values.mongodb.auth.existingSecret }} + value: {{ .Values.mongodb.auth.rootPassword | quote }} + {{- else }} + valueFrom: + secretKeyRef: + name: {{ .Values.mongodb.auth.existingSecret }} + key: mongodb-root-password + {{- end }} + {{- else }} + valueFrom: + secretKeyRef: + name: {{ include "litmus-portal.secretname" . }} + key: DB_PASSWORD + {{- end }} + - name: DB_USER + {{- if .Values.mongodb.enabled }} + value: {{ .Values.mongodb.auth.rootUser }} + {{- else }} + valueFrom: + secretKeyRef: + name: {{ include "litmus-portal.secretname" . }} + key: DB_USER + {{- end }} + args: + [ + "until mongosh -u ${DB_USER} -p ${DB_PASSWORD} {{ include "litmus-portal.mongodbConnectionString" . }} --eval 'rs.status()' | grep 'ok' &> /dev/null; do sleep 5; echo 'Waiting for the MongoDB to be ready...'; done; echo 'Connection with MongoDB established'", + ] + resources: + {{- toYaml .Values.portal.server.waitForMongodb.resources | nindent 12 }} + securityContext: + {{- toYaml .Values.portal.server.waitForMongodb.securityContext | nindent 12 }} containers: - name: auth-server image: {{ .Values.image.imageRegistryName }}/{{ .Values.portal.server.authServer.image.repository }}:{{ .Values.portal.server.authServer.image.tag }} @@ -54,7 +93,7 @@ spec: - name: DB_PASSWORD {{- if .Values.mongodb.enabled }} {{- if not .Values.mongodb.auth.existingSecret }} - value: {{ .Values.mongodb.auth.rootPassword }} + value: {{ .Values.mongodb.auth.rootPassword | quote }} {{- else }} valueFrom: secretKeyRef: diff --git a/charts/litmus/templates/controlplane-configs.yaml b/charts/litmus/templates/controlplane-configs.yaml index f85ddb96..0182aabb 100644 --- a/charts/litmus/templates/controlplane-configs.yaml +++ b/charts/litmus/templates/controlplane-configs.yaml @@ -12,7 +12,7 @@ data: {{- if .Values.adminConfig.DB_SERVER }} DB_SERVER: "{{ .Values.adminConfig.DB_SERVER }}" {{- else }} - DB_SERVER: "mongodb://{{ include "litmus-portal.mongodbServiceName" . }}:{{ .Values.mongodb.service.ports.mongodb }}" + DB_SERVER: "{{ include "litmus-portal.mongodbConnectionString" . }}" {{- end }} VERSION: "{{ .Values.adminConfig.VERSION }}" SKIP_SSL_VERIFY: "{{ .Values.adminConfig.SKIP_SSL_VERIFY }}" diff --git a/charts/litmus/templates/server-deployment.yaml b/charts/litmus/templates/server-deployment.yaml index 6916dedc..ea3387cd 100644 --- a/charts/litmus/templates/server-deployment.yaml +++ b/charts/litmus/templates/server-deployment.yaml @@ -34,6 +34,45 @@ spec: {{- end }} volumes: {{- toYaml .Values.portal.server.graphqlServer.volumes | default "" | nindent 8 }} + initContainers: + - name: wait-for-mongodb + image: mongo:latest + imagePullPolicy: {{ .Values.portal.server.waitForMongodb.image.pullPolicy }} + command: ["/bin/sh", "-c"] + env: + - name: DB_PASSWORD + {{- if .Values.mongodb.enabled }} + {{- if not .Values.mongodb.auth.existingSecret }} + value: {{ .Values.mongodb.auth.rootPassword | quote }} + {{- else }} + valueFrom: + secretKeyRef: + name: {{ .Values.mongodb.auth.existingSecret }} + key: mongodb-root-password + {{- end }} + {{- else }} + valueFrom: + secretKeyRef: + name: {{ include "litmus-portal.secretname" . }} + key: DB_PASSWORD + {{- end }} + - name: DB_USER + {{- if .Values.mongodb.enabled }} + value: {{ .Values.mongodb.auth.rootUser }} + {{- else }} + valueFrom: + secretKeyRef: + name: {{ include "litmus-portal.secretname" . }} + key: DB_USER + {{- end }} + args: + [ + "until [[ $(mongosh -u ${DB_USER} -p ${DB_PASSWORD} {{ include "litmus-portal.mongodbConnectionString" . }} --eval 'rs.status()' | grep 'ok' | wc -l) -eq 1 ]]; do sleep 5; echo 'Waiting for the MongoDB to be ready...'; done; echo 'Connection with MongoDB established'", + ] + resources: + {{- toYaml .Values.portal.server.waitForMongodb.resources | nindent 12 }} + securityContext: + {{- toYaml .Values.portal.server.waitForMongodb.securityContext | nindent 12 }} containers: - name: graphql-server image: {{ .Values.image.imageRegistryName }}/{{ .Values.portal.server.graphqlServer.image.repository }}:{{ .Values.portal.server.graphqlServer.image.tag }} @@ -65,7 +104,7 @@ spec: - name: DB_PASSWORD {{- if .Values.mongodb.enabled }} {{- if not .Values.mongodb.auth.existingSecret }} - value: {{ .Values.mongodb.auth.rootPassword }} + value: {{ .Values.mongodb.auth.rootPassword | quote}} {{- else }} valueFrom: secretKeyRef: diff --git a/charts/litmus/values.yaml b/charts/litmus/values.yaml index 44a858c1..4124a948 100644 --- a/charts/litmus/values.yaml +++ b/charts/litmus/values.yaml @@ -20,7 +20,7 @@ adminConfig: # -- leave empty if uses Mongo DB deployed by this chart DBPASSWORD: "1234" DBUSER: "root" - DB_SERVER: "mongodb://my-release-mongodb-0.my-release-mongodb-headless.litmus.svc.cluster.local:27017,my-release-mongodb-1.my-release-mongodb-headless.litmus.svc.cluster.local:27017,my-release-mongodb-2.my-release-mongodb-headless.litmus.svc.cluster.local:27017/admin" + DB_SERVER: "" DB_PORT: "" ADMIN_USERNAME: "admin" ADMIN_PASSWORD: "litmus" @@ -335,15 +335,19 @@ openshift: # -- Configure the Bitnami MongoDB subchart # see values at https://github.com/bitnami/charts/blob/master/bitnami/mongodb/values.yaml mongodb: - enabled: false + enabled: true auth: enabled: true - rootPassword: "superhardpassword" + rootUser: "root" + rootPassword: "1234" # -- existingSecret Existing secret with MongoDB(®) credentials (keys: `mongodb-passwords`, `mongodb-root-password`, `mongodb-metrics-password`, ` mongodb-replica-set-key`) existingSecret: "" - architecture: standalone - useStatefulSet: false - replicaCount: 1 + architecture: replicaset + replicaCount: 3 + persistence: + enabled: true + volumePermissions: + enabled: true metrics: enabled: false prometheusRule: