@@ -50,13 +50,23 @@ const (
5050
5151// MongoDBStatefulSetOwner is an interface which any resource which generates a MongoDB StatefulSet should implement.
5252type MongoDBStatefulSetOwner interface {
53+ // ServiceName returns the name of the K8S service the operator will create.
5354 ServiceName () string
55+ // GetName returns the name of the resource.
5456 GetName () string
57+ // GetNamespace returns the namespace the resource is defined in.
5558 GetNamespace () string
59+ // GetMongoDBVersion returns the version of MongoDB to be used for this resource
5660 GetMongoDBVersion () string
61+ // AutomationConfigSecretName returns the name of the secret which will contain the automation config.
5762 AutomationConfigSecretName () string
63+ // GetUpdateStrategyType returns the UpdateStrategyType of the statefulset.
5864 GetUpdateStrategyType () appsv1.StatefulSetUpdateStrategyType
65+ // Persistent returns whether or not the statefulset should have persistent volumes added.
5966 Persistent () bool
67+ // HasSeparateDataAndLogsVolumes returns whether or not the volumes for data and logs would need to be different.
68+ HasSeparateDataAndLogsVolumes () bool
69+ // GetAgentScramKeyfileSecretNamespacedName returns the NamespacedName of the secret which stores the keyfile for the agent.
6070 GetAgentKeyfileSecretNamespacedName () types.NamespacedName
6171}
6272
@@ -86,23 +96,34 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
8696 automationConfigVolume := statefulset .CreateVolumeFromSecret ("automation-config" , mdb .AutomationConfigSecretName ())
8797 automationConfigVolumeMount := statefulset .CreateVolumeMount (automationConfigVolume .Name , "/var/lib/automation/config" , statefulset .WithReadOnly (true ))
8898
89- logVolumeMount := statefulset .CreateVolumeMount (logVolumeName , automationconfig .DefaultAgentLogPath )
90-
9199 keyFileNsName := mdb .GetAgentKeyfileSecretNamespacedName ()
92100 keyFileVolume := statefulset .CreateVolumeFromEmptyDir (keyFileNsName .Name )
93101 keyFileVolumeVolumeMount := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
94102 keyFileVolumeVolumeMountMongod := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
95103
96- mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , automationConfigVolumeMount , scriptsVolumeMount , logVolumeMount , keyFileVolumeVolumeMount }
97- mongodVolumeMounts := []corev1.VolumeMount {mongodHealthStatusVolumeMount , hooksVolumeMount , logVolumeMount , keyFileVolumeVolumeMountMongod }
98- dataVolumeClaim := func (s * appsv1.StatefulSet ) {}
104+ mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , automationConfigVolumeMount , scriptsVolumeMount , keyFileVolumeVolumeMount }
105+ mongodVolumeMounts := []corev1.VolumeMount {mongodHealthStatusVolumeMount , hooksVolumeMount , keyFileVolumeVolumeMountMongod }
106+ dataVolumeClaim := statefulset .NOOP ()
107+ logVolumeClaim := statefulset .NOOP ()
108+ singleModeVolumeClaim := func (s * appsv1.StatefulSet ) {}
99109 if mdb .Persistent () {
100- dataVolumeMount := statefulset .CreateVolumeMount (dataVolumeName , "/data" )
101- dataVolumeClaim = statefulset .WithVolumeClaim (dataVolumeName , dataPvc ())
102- mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , dataVolumeMount )
103- mongodVolumeMounts = append (mongodVolumeMounts , dataVolumeMount )
110+ if mdb .HasSeparateDataAndLogsVolumes () {
111+ logVolumeMount := statefulset .CreateVolumeMount (logVolumeName , automationconfig .DefaultAgentLogPath )
112+ dataVolumeMount := statefulset .CreateVolumeMount (dataVolumeName , "/data" )
113+ dataVolumeClaim = statefulset .WithVolumeClaim (dataVolumeName , dataPvc ())
114+ logVolumeClaim = statefulset .WithVolumeClaim (logVolumeName , logsPvc ())
115+ mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , dataVolumeMount , logVolumeMount )
116+ mongodVolumeMounts = append (mongodVolumeMounts , dataVolumeMount , logVolumeMount )
117+ } else {
118+ mounts := []corev1.VolumeMount {
119+ statefulset .CreateVolumeMount (dataVolumeName , "/data" , statefulset .WithSubPath ("data" )),
120+ statefulset .CreateVolumeMount (dataVolumeName , automationconfig .DefaultAgentLogPath , statefulset .WithSubPath ("logs" )),
121+ }
122+ mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , mounts ... )
123+ mongodVolumeMounts = append (mongodVolumeMounts , mounts ... )
124+ singleModeVolumeClaim = statefulset .WithVolumeClaim (dataVolumeName , dataPvc ())
125+ }
104126 }
105-
106127 return statefulset .Apply (
107128 statefulset .WithName (mdb .GetName ()),
108129 statefulset .WithNamespace (mdb .GetNamespace ()),
@@ -112,7 +133,8 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
112133 statefulset .WithReplicas (scale .ReplicasThisReconciliation (scaler )),
113134 statefulset .WithUpdateStrategyType (mdb .GetUpdateStrategyType ()),
114135 dataVolumeClaim ,
115- statefulset .WithVolumeClaim (logVolumeName , logsPvc ()),
136+ logVolumeClaim ,
137+ singleModeVolumeClaim ,
116138 statefulset .WithPodSpecTemplate (
117139 podtemplatespec .Apply (
118140 podtemplatespec .WithSecurityContext (podtemplatespec .DefaultPodSecurityContext ()),
0 commit comments