@@ -96,7 +96,7 @@ type MongoDBStatefulSetOwner interface {
96
96
// GetNamespace returns the namespace the resource is defined in.
97
97
GetNamespace () string
98
98
// GetMongoDBVersion returns the version of MongoDB to be used for this resource.
99
- GetMongoDBVersion () string
99
+ GetMongoDBVersion (annotations map [ string ] string ) string
100
100
// AutomationConfigSecretName returns the name of the secret which will contain the automation config.
101
101
AutomationConfigSecretName () string
102
102
// GetUpdateStrategyType returns the UpdateStrategyType of the statefulset.
@@ -126,7 +126,7 @@ type MongoDBStatefulSetOwner interface {
126
126
// BuildMongoDBReplicaSetStatefulSetModificationFunction builds the parts of the replica set that are common between every resource that implements
127
127
// MongoDBStatefulSetOwner.
128
128
// It doesn't configure TLS or additional containers/env vars that the statefulset might need.
129
- func BuildMongoDBReplicaSetStatefulSetModificationFunction (mdb MongoDBStatefulSetOwner , scaler scale.ReplicaSetScaler ) statefulset.Modification {
129
+ func BuildMongoDBReplicaSetStatefulSetModificationFunction (mdb MongoDBStatefulSetOwner , scaler scale.ReplicaSetScaler , agentImage string , withInitContainers bool ) statefulset.Modification {
130
130
labels := map [string ]string {
131
131
"app" : mdb .ServiceName (),
132
132
}
@@ -138,13 +138,10 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
138
138
agentHealthStatusVolumeMount := statefulset .CreateVolumeMount (healthStatusVolume .Name , "/var/log/mongodb-mms-automation/healthstatus" )
139
139
mongodHealthStatusVolumeMount := statefulset .CreateVolumeMount (healthStatusVolume .Name , "/healthstatus" )
140
140
141
- // hooks volume is only required on the mongod pod.
142
- hooksVolume := statefulset .CreateVolumeFromEmptyDir ("hooks" )
143
- hooksVolumeMount := statefulset .CreateVolumeMount (hooksVolume .Name , "/hooks" , statefulset .WithReadOnly (false ))
144
-
145
- // scripts volume is only required on the mongodb-agent pod.
146
- scriptsVolume := statefulset .CreateVolumeFromEmptyDir ("agent-scripts" )
147
- scriptsVolumeMount := statefulset .CreateVolumeMount (scriptsVolume .Name , "/opt/scripts" , statefulset .WithReadOnly (false ))
141
+ hooksVolume := corev1.Volume {}
142
+ scriptsVolume := corev1.Volume {}
143
+ upgradeInitContainer := podtemplatespec .NOOP ()
144
+ readinessInitContainer := podtemplatespec .NOOP ()
148
145
149
146
// tmp volume is required by the mongodb-agent and mongod
150
147
tmpVolume := statefulset .CreateVolumeFromEmptyDir ("tmp" )
@@ -155,7 +152,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
155
152
keyFileVolumeVolumeMount := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
156
153
keyFileVolumeVolumeMountMongod := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
157
154
158
- mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , scriptsVolumeMount , keyFileVolumeVolumeMount , tmpVolumeMount }
155
+ mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , keyFileVolumeVolumeMount , tmpVolumeMount }
159
156
160
157
automationConfigVolumeFunc := podtemplatespec .NOOP ()
161
158
if mdb .NeedsAutomationConfigVolume () {
@@ -164,7 +161,31 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
164
161
automationConfigVolumeMount := statefulset .CreateVolumeMount (automationConfigVolume .Name , "/var/lib/automation/config" , statefulset .WithReadOnly (true ))
165
162
mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , automationConfigVolumeMount )
166
163
}
167
- mongodVolumeMounts := []corev1.VolumeMount {mongodHealthStatusVolumeMount , hooksVolumeMount , keyFileVolumeVolumeMountMongod , tmpVolumeMount }
164
+ mongodVolumeMounts := []corev1.VolumeMount {mongodHealthStatusVolumeMount , keyFileVolumeVolumeMountMongod , tmpVolumeMount }
165
+
166
+ hooksVolumeMod := podtemplatespec .NOOP ()
167
+ scriptsVolumeMod := podtemplatespec .NOOP ()
168
+
169
+ // This is temporary code;
170
+ // once we make the operator fully deploy static workloads, we will remove those init containers.
171
+ if withInitContainers {
172
+ // hooks volume is only required on the mongod pod.
173
+ hooksVolume = statefulset .CreateVolumeFromEmptyDir ("hooks" )
174
+ hooksVolumeMount := statefulset .CreateVolumeMount (hooksVolume .Name , "/hooks" , statefulset .WithReadOnly (false ))
175
+
176
+ // scripts volume is only required on the mongodb-agent pod.
177
+ scriptsVolume = statefulset .CreateVolumeFromEmptyDir ("agent-scripts" )
178
+ scriptsVolumeMount := statefulset .CreateVolumeMount (scriptsVolume .Name , "/opt/scripts" , statefulset .WithReadOnly (false ))
179
+
180
+ upgradeInitContainer = podtemplatespec .WithInitContainer (versionUpgradeHookName , versionUpgradeHookInit ([]corev1.VolumeMount {hooksVolumeMount }))
181
+ readinessInitContainer = podtemplatespec .WithInitContainer (ReadinessProbeContainerName , readinessProbeInit ([]corev1.VolumeMount {scriptsVolumeMount }))
182
+ scriptsVolumeMod = podtemplatespec .WithVolume (scriptsVolume )
183
+ hooksVolumeMod = podtemplatespec .WithVolume (hooksVolume )
184
+
185
+ mongodVolumeMounts = append (mongodVolumeMounts , hooksVolumeMount )
186
+ mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , scriptsVolumeMount )
187
+ }
188
+
168
189
dataVolumeClaim := statefulset .NOOP ()
169
190
logVolumeClaim := statefulset .NOOP ()
170
191
singleModeVolumeClaim := func (s * appsv1.StatefulSet ) {}
@@ -218,16 +239,16 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
218
239
podSecurityContext ,
219
240
podtemplatespec .WithPodLabels (labels ),
220
241
podtemplatespec .WithVolume (healthStatusVolume ),
221
- podtemplatespec .WithVolume (hooksVolume ),
222
242
automationConfigVolumeFunc ,
223
- podtemplatespec .WithVolume (scriptsVolume ),
243
+ hooksVolumeMod ,
244
+ scriptsVolumeMod ,
224
245
podtemplatespec .WithVolume (tmpVolume ),
225
246
podtemplatespec .WithVolume (keyFileVolume ),
226
247
podtemplatespec .WithServiceAccount (mongodbDatabaseServiceAccountName ),
227
- podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts , agentLogLevel , agentLogFile , agentMaxLogFileDurationHours )),
228
- podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (), mongodVolumeMounts , mdb .GetMongodConfiguration ())),
229
- podtemplatespec . WithInitContainer ( versionUpgradeHookName , versionUpgradeHookInit ([]corev1. VolumeMount { hooksVolumeMount })) ,
230
- podtemplatespec . WithInitContainer ( ReadinessProbeContainerName , readinessProbeInit ([]corev1. VolumeMount { scriptsVolumeMount })) ,
248
+ podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts , agentLogLevel , agentLogFile , agentMaxLogFileDurationHours , agentImage )),
249
+ podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (nil ), mongodVolumeMounts , mdb .GetMongodConfiguration ())),
250
+ upgradeInitContainer ,
251
+ readinessInitContainer ,
231
252
),
232
253
))
233
254
}
@@ -245,11 +266,11 @@ func AutomationAgentCommand(withAgentAPIKeyExport bool) []string {
245
266
return []string {"/bin/bash" , "-c" , MongodbUserCommand + BaseAgentCommand () + " -cluster=" + clusterFilePath + automationAgentOptions + automationAgentLogOptions }
246
267
}
247
268
248
- func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount , logLevel string , logFile string , maxLogFileDurationHours int ) container.Modification {
269
+ func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount , logLevel string , logFile string , maxLogFileDurationHours int , agentImage string ) container.Modification {
249
270
_ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
250
271
return container .Apply (
251
272
container .WithName (AgentName ),
252
- container .WithImage (os . Getenv ( AgentImageEnv ) ),
273
+ container .WithImage (agentImage ),
253
274
container .WithImagePullPolicy (corev1 .PullAlways ),
254
275
container .WithReadinessProbe (DefaultReadiness ()),
255
276
container .WithResourceRequirements (resourcerequirements .Defaults ()),
0 commit comments