feat(mongodb): run in single replicaset (take3) (#2505)

* feat(mongodb): run in single replicaset (take3)

* use secret

* add replicaset name

* ui also

* add oplog user creation script
This commit is contained in:
Stavros Kois 2022-04-24 12:57:37 +03:00 committed by GitHub
parent 4b4e967288
commit d8d4706967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 2 deletions

View File

@ -23,7 +23,7 @@ sources:
- https://github.com/bitnami/bitnami-docker-mongodb
- https://www.mongodb.com
type: application
version: 0.0.31
version: 0.1.0
annotations:
truecharts.org/catagories: |
- database

View File

@ -97,6 +97,27 @@ questions:
type: string
default: ""
required: true
- variable: mongodbReplicasetMode
group: "App Configuration"
label: "ReplicaSet Mode"
schema:
type: string
default: "primary"
required: true
- variable: mongodbReplicasetName
group: "App Configuration"
label: "ReplicaSet Name"
schema:
type: string
default: "rs0"
required: true
- variable: mongodbReplicasetKey
group: "App Configuration"
label: "ReplicaSet Key"
schema:
type: string
default: "testreplicasetkey"
required: true
- variable: service
group: "Networking and Services"

View File

@ -1 +1,20 @@
{{ include "common.all" . }}
{{- include "common.setup" . }}
{{/* Append the hardcoded settings */}}
{{- define "mongodb.harcodedValues" -}}
persistence:
focalboard-config:
enabled: "true"
mountPath: "/docker-entrypoint-initdb.d/create-oplog-user.sh"
subPath: "create-oplog-user.sh"
type: "custom"
volumeSpec:
configMap:
name: {{ printf "%v-create-oplog-user" (include "common.names.fullname" .) }}
{{- end -}}
{{- $_ := mergeOverwrite .Values (include "mongodb.harcodedValues" . | fromYaml) -}}
{{- include "mongodb.configmap" . }}
{{/* Render the templates */}}
{{ include "common.postSetup" . }}

View File

@ -0,0 +1,27 @@
{{- define "mongodb.configmap" -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "common.names.fullname" . }}-create-oplog-user
labels:
{{- include "common.labels" . | nindent 4 }}
data:
create-oplog-user.sh: |-
#!/bin/bash
echo "Generating command for oplog user creation...";
# '.script' extension is just to avoid the bitnami init script to executing it. (bitnami executes .sh and .js files automatically)
echo 'use '$MONGODB_DATABASE > /docker-entrypoint-initdb.d/createOpLogUser.script;
echo 'db.createUser({user: "'$MONGODB_USERNAME'-oplog", pwd: "'$MONGODB_PASSWORD'", roles: [ { role: "read", db: "local" } ]})' >> /docker-entrypoint-initdb.d/createOpLogUser.script;
echo "Command Generated!";
echo "Creating the user...";
mongo admin -u root -p $MONGODB_ROOT_PASSWORD < /docker-entrypoint-initdb.d/createOpLogUser.script;
echo "User Created!";
echo "Removing mongodb generated command"...;
rm /docker-entrypoint-initdb.d/createOpLogUser.script;
echo "Removed mongodb generated command!";
{{- end -}}

View File

@ -12,3 +12,4 @@ type: Opaque
data:
mongodb-password: {{ ( .Values.mongodbPassword | default "empty" ) | b64enc | quote }}
mongodb-root-password: {{ ( .Values.mongodbRootPassword | default "empty" ) | b64enc | quote }}
mongodb-replicaset-key: {{ ( .Values.mongodbReplicasetKey | default "empty" ) | b64enc | quote }}

View File

@ -99,6 +99,9 @@ mongodbPassword: "testpass"
mongodbUsername: "test"
mongodbDatabase: "test"
mongodbRootPassword: "testroot"
mongodbReplicasetMode: "primary"
mongodbReplicasetName: "rs0"
mongodbReplicasetKey: "testreplicasetkey"
existingSecret: ""
envValueFrom:
@ -110,7 +113,13 @@ envValueFrom:
secretKeyRef:
name: '{{ ( tpl .Values.existingSecret $ ) | default ( include "common.names.fullname" . ) }}'
key: "mongodb-root-password"
MONGODB_REPLICA_SET_KEY:
secretKeyRef:
name: '{{ ( tpl .Values.existingSecret $ ) | default ( include "common.names.fullname" . ) }}'
key: "mongodb-replicaset-key"
env:
MONGODB_USERNAME: "{{ .Values.mongodbUsername }}"
MONGODB_DATABASE: "{{ .Values.mongodbDatabase }}"
MONGODB_REPLICA_SET_MODE: "{{ .Values.mongodbReplicasetMode }}"
MONGODB_REPLICA_SET_NAME: "{{ .Values.mongodbReplicasetName }}"