@@ -50,13 +50,23 @@ const (
50
50
51
51
// MongoDBStatefulSetOwner is an interface which any resource which generates a MongoDB StatefulSet should implement.
52
52
type MongoDBStatefulSetOwner interface {
53
+ // ServiceName returns the name of the K8S service the operator will create.
53
54
ServiceName () string
55
+ // GetName returns the name of the resource.
54
56
GetName () string
57
+ // GetNamespace returns the namespace the resource is defined in.
55
58
GetNamespace () string
59
+ // GetMongoDBVersion returns the version of MongoDB to be used for this resource
56
60
GetMongoDBVersion () string
61
+ // AutomationConfigSecretName returns the name of the secret which will contain the automation config.
57
62
AutomationConfigSecretName () string
63
+ // GetUpdateStrategyType returns the UpdateStrategyType of the statefulset.
58
64
GetUpdateStrategyType () appsv1.StatefulSetUpdateStrategyType
65
+ // Persistent returns whether or not the statefulset should have persistent volumes added.
59
66
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.
60
70
GetAgentKeyfileSecretNamespacedName () types.NamespacedName
61
71
}
62
72
@@ -86,23 +96,34 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
86
96
automationConfigVolume := statefulset .CreateVolumeFromSecret ("automation-config" , mdb .AutomationConfigSecretName ())
87
97
automationConfigVolumeMount := statefulset .CreateVolumeMount (automationConfigVolume .Name , "/var/lib/automation/config" , statefulset .WithReadOnly (true ))
88
98
89
- logVolumeMount := statefulset .CreateVolumeMount (logVolumeName , automationconfig .DefaultAgentLogPath )
90
-
91
99
keyFileNsName := mdb .GetAgentKeyfileSecretNamespacedName ()
92
100
keyFileVolume := statefulset .CreateVolumeFromEmptyDir (keyFileNsName .Name )
93
101
keyFileVolumeVolumeMount := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
94
102
keyFileVolumeVolumeMountMongod := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
95
103
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 ) {}
99
109
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
+ }
104
126
}
105
-
106
127
return statefulset .Apply (
107
128
statefulset .WithName (mdb .GetName ()),
108
129
statefulset .WithNamespace (mdb .GetNamespace ()),
@@ -112,7 +133,8 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
112
133
statefulset .WithReplicas (scale .ReplicasThisReconciliation (scaler )),
113
134
statefulset .WithUpdateStrategyType (mdb .GetUpdateStrategyType ()),
114
135
dataVolumeClaim ,
115
- statefulset .WithVolumeClaim (logVolumeName , logsPvc ()),
136
+ logVolumeClaim ,
137
+ singleModeVolumeClaim ,
116
138
statefulset .WithPodSpecTemplate (
117
139
podtemplatespec .Apply (
118
140
podtemplatespec .WithSecurityContext (podtemplatespec .DefaultPodSecurityContext ()),
0 commit comments