From 5f74107cde2b4e1cf2ea0df9796a270c1b10b544 Mon Sep 17 00:00:00 2001
From: dengzhaosen <jorhson_deng@163.com>
Date: Tue, 9 Apr 2024 14:14:54 +0800
Subject: [PATCH] Add conf file for MongoDB

Change-Id: If6635557d4b0f65188da0d7450ad37630b811996
---
 mongodb/Chart.yaml                         |  2 +-
 mongodb/templates/bin/_start.sh.tpl        |  2 +-
 mongodb/templates/configmap-etc.yaml       | 26 ++++++++++++++++++++++
 mongodb/templates/secrets/_mongodb.cnf.tpl | 18 +++++++++++++++
 mongodb/templates/statefulset.yaml         |  8 +++++++
 mongodb/values.yaml                        |  2 ++
 releasenotes/notes/mongodb.yaml            |  1 +
 7 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 mongodb/templates/configmap-etc.yaml
 create mode 100644 mongodb/templates/secrets/_mongodb.cnf.tpl

diff --git a/mongodb/Chart.yaml b/mongodb/Chart.yaml
index d7fe37525e..7b7ca0bbaf 100644
--- a/mongodb/Chart.yaml
+++ b/mongodb/Chart.yaml
@@ -15,7 +15,7 @@ apiVersion: v1
 appVersion: v3.4.9
 description: OpenStack-Helm MongoDB
 name: mongodb
-version: 0.1.4
+version: 0.1.5
 home: https://www.mongodb.com
 sources:
   - https://github.com/mongodb/mongo
diff --git a/mongodb/templates/bin/_start.sh.tpl b/mongodb/templates/bin/_start.sh.tpl
index f4a4b7faa5..08a77b505c 100644
--- a/mongodb/templates/bin/_start.sh.tpl
+++ b/mongodb/templates/bin/_start.sh.tpl
@@ -16,7 +16,7 @@ limitations under the License.
 
 set -ex
 
-mongod --auth &
+mongod --config /etc/mongodb.conf --auth &
 
 t=0
 until mongo --eval "db.adminCommand('ping')"; do
diff --git a/mongodb/templates/configmap-etc.yaml b/mongodb/templates/configmap-etc.yaml
new file mode 100644
index 0000000000..f2cbbf24cb
--- /dev/null
+++ b/mongodb/templates/configmap-etc.yaml
@@ -0,0 +1,26 @@
+{{/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/}}
+
+{{- if .Values.manifests.configmap_etc }}
+{{- $envAll := . }}
+
+---
+apiVersion: v1
+kind: Secret
+metadata:
+  name: mongodb-etc
+type: Opaque
+data:
+  mongodb.conf: {{ tuple "secrets/_mongodb.cnf.tpl" . | include "helm-toolkit.utils.template"  | b64enc }}
+{{- end }}
\ No newline at end of file
diff --git a/mongodb/templates/secrets/_mongodb.cnf.tpl b/mongodb/templates/secrets/_mongodb.cnf.tpl
new file mode 100644
index 0000000000..9180c2dfa9
--- /dev/null
+++ b/mongodb/templates/secrets/_mongodb.cnf.tpl
@@ -0,0 +1,18 @@
+{{/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/}}
+
+bind_ip = {{ .Values.endpoints.mongodb.bind_ip}}
+port = {{ .Values.endpoints.mongodb.port.mongodb.default}}
+# Where to store the data.
+dbpath=/var/lib/mongodb
diff --git a/mongodb/templates/statefulset.yaml b/mongodb/templates/statefulset.yaml
index e5e0b48df2..7456a0778d 100644
--- a/mongodb/templates/statefulset.yaml
+++ b/mongodb/templates/statefulset.yaml
@@ -110,6 +110,10 @@ spec:
               mountPath: /tmp/setup_admin_user.sh
               subPath: setup_admin_user.sh
               readOnly: true
+            - name: mongodb-etc
+              mountPath: /etc/mongodb.conf
+              subPath: mongodb.conf
+              readOnly: true
             - name: mongodb-data
               mountPath: /data/db
       volumes:
@@ -119,6 +123,10 @@ spec:
           configMap:
             name: mongodb-bin
             defaultMode: 0555
+        - name: mongodb-etc
+          secret:
+            secretName: mongodb-etc
+            defaultMode: 0444
 {{- if not .Values.volume.enabled }}
         - name: mongodb-data
           hostPath:
diff --git a/mongodb/values.yaml b/mongodb/values.yaml
index 90167a0d8f..d50e790a6e 100644
--- a/mongodb/values.yaml
+++ b/mongodb/values.yaml
@@ -118,6 +118,7 @@ endpoints:
       default: null
     path: null
     scheme: mongodb
+    bind_ip: 0.0.0.0
     port:
       mongodb:
         default: 27017
@@ -141,6 +142,7 @@ dependencies:
 
 manifests:
   configmap_bin: true
+  configmap_etc: true
   job_image_repo_sync: true
   secret_db_root_creds: true
   secret_registry: true
diff --git a/releasenotes/notes/mongodb.yaml b/releasenotes/notes/mongodb.yaml
index 30f2bb1faa..2cf4590009 100644
--- a/releasenotes/notes/mongodb.yaml
+++ b/releasenotes/notes/mongodb.yaml
@@ -5,4 +5,5 @@ mongodb:
   - 0.1.2 Use full image ref for docker official images
   - 0.1.3 Update htk requirements
   - 0.1.4 Added OCI registry authentication
+  - 0.1.5 Add conf file for MongoDB
 ...