Skip to content

Commit

Permalink
Added changes requires for mongo support
Browse files Browse the repository at this point in the history
Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya-jena committed Sep 27, 2023
1 parent e9ff5e8 commit dbe5441
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 9 deletions.
12 changes: 12 additions & 0 deletions charts/litmus/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

41 changes: 40 additions & 1 deletion charts/litmus/templates/auth-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/litmus/templates/controlplane-configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
41 changes: 40 additions & 1 deletion charts/litmus/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 10 additions & 6 deletions charts/litmus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(&reg;) 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:
Expand Down

0 comments on commit dbe5441

Please sign in to comment.