@@ -2,6 +2,7 @@ package construct
2
2
3
3
import (
4
4
"fmt"
5
+ "github.com/stretchr/objx"
5
6
"os"
6
7
"strings"
7
8
@@ -43,8 +44,9 @@ const (
43
44
ReadinessProbeImageEnv = "READINESS_PROBE_IMAGE"
44
45
ManagedSecurityContextEnv = "MANAGED_SECURITY_CONTEXT"
45
46
46
- automationconfFilePath = "/data/automation-mongod.conf"
47
- keyfileFilePath = "/var/lib/mongodb-mms-automation/authentication/keyfile"
47
+ defaultDataDir = "/data"
48
+ automationMongodConfFileName = "automation-mongod.conf"
49
+ keyfileFilePath = "/var/lib/mongodb-mms-automation/authentication/keyfile"
48
50
49
51
automationAgentOptions = " -skipMongoStart -noDaemonize -useLocalMongoDbTools"
50
52
@@ -82,6 +84,9 @@ type MongoDBStatefulSetOwner interface {
82
84
DataVolumeName () string
83
85
// LogsVolumeName returns the name that the data volume should have
84
86
LogsVolumeName () string
87
+
88
+ // GetMongodConfiguration returns the MongoDB configuration for each member.
89
+ GetMongodConfiguration () map [string ]interface {}
85
90
}
86
91
87
92
// BuildMongoDBReplicaSetStatefulSetModificationFunction builds the parts of the replica set that are common between every resource that implements
@@ -122,14 +127,14 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
122
127
singleModeVolumeClaim := func (s * appsv1.StatefulSet ) {}
123
128
if mdb .HasSeparateDataAndLogsVolumes () {
124
129
logVolumeMount := statefulset .CreateVolumeMount (mdb .LogsVolumeName (), automationconfig .DefaultAgentLogPath )
125
- dataVolumeMount := statefulset .CreateVolumeMount (mdb .DataVolumeName (), "/data" )
130
+ dataVolumeMount := statefulset .CreateVolumeMount (mdb .DataVolumeName (), GetDBDataDir ( mdb . GetMongodConfiguration ()) )
126
131
dataVolumeClaim = statefulset .WithVolumeClaim (mdb .DataVolumeName (), dataPvc (mdb .DataVolumeName ()))
127
132
logVolumeClaim = statefulset .WithVolumeClaim (mdb .LogsVolumeName (), logsPvc (mdb .LogsVolumeName ()))
128
133
mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , dataVolumeMount , logVolumeMount )
129
134
mongodVolumeMounts = append (mongodVolumeMounts , dataVolumeMount , logVolumeMount )
130
135
} else {
131
136
mounts := []corev1.VolumeMount {
132
- statefulset .CreateVolumeMount (mdb .DataVolumeName (), "/data" , statefulset .WithSubPath ("data" )),
137
+ statefulset .CreateVolumeMount (mdb .DataVolumeName (), GetDBDataDir ( mdb . GetMongodConfiguration ()) , statefulset .WithSubPath ("data" )),
133
138
statefulset .CreateVolumeMount (mdb .DataVolumeName (), automationconfig .DefaultAgentLogPath , statefulset .WithSubPath ("logs" )),
134
139
}
135
140
mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , mounts ... )
@@ -165,7 +170,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
165
170
podtemplatespec .WithVolume (keyFileVolume ),
166
171
podtemplatespec .WithServiceAccount (mongodbDatabaseServiceAccountName ),
167
172
podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts )),
168
- podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (), mongodVolumeMounts )),
173
+ podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (), mongodVolumeMounts , mdb . GetMongodConfiguration () )),
169
174
podtemplatespec .WithInitContainer (versionUpgradeHookName , versionUpgradeHookInit ([]corev1.VolumeMount {hooksVolumeMount })),
170
175
podtemplatespec .WithInitContainer (ReadinessProbeContainerName , readinessProbeInit ([]corev1.VolumeMount {scriptsVolumeMount })),
171
176
),
@@ -276,7 +281,16 @@ func getMongoDBImage(version string) string {
276
281
return fmt .Sprintf ("%s/%s:%s" , repoUrl , mongoImageName , version )
277
282
}
278
283
279
- func mongodbContainer (version string , volumeMounts []corev1.VolumeMount ) container.Modification {
284
+ // GetDBDataDir returns the db path which should be used.
285
+ func GetDBDataDir (additionalMongoDBConfig objx.Map ) string {
286
+ if additionalMongoDBConfig == nil {
287
+ return defaultDataDir
288
+ }
289
+ return additionalMongoDBConfig .Get ("storage.dbPath" ).Str (defaultDataDir )
290
+ }
291
+
292
+ func mongodbContainer (version string , volumeMounts []corev1.VolumeMount , additionalMongoDBConfig map [string ]interface {}) container.Modification {
293
+ filePath := GetDBDataDir (additionalMongoDBConfig ) + "/" + automationMongodConfFileName
280
294
mongoDbCommand := fmt .Sprintf (`
281
295
#run post-start hook to handle version changes
282
296
/hooks/version-upgrade
@@ -291,7 +305,7 @@ tail -F /var/log/mongodb-mms-automation/mongodb.log > /dev/stdout &
291
305
# start mongod with this configuration
292
306
exec mongod -f %s;
293
307
294
- ` , automationconfFilePath , keyfileFilePath , automationconfFilePath )
308
+ ` , filePath , keyfileFilePath , filePath )
295
309
296
310
containerCommand := []string {
297
311
"/bin/sh" ,
0 commit comments