@@ -96,7 +96,7 @@ type MongoDBStatefulSetOwner interface {
9696 // GetNamespace returns the namespace the resource is defined in.
9797 GetNamespace () string
9898 // GetMongoDBVersion returns the version of MongoDB to be used for this resource.
99- GetMongoDBVersion () string
99+ GetMongoDBVersion (annotations map [ string ] string ) string
100100 // AutomationConfigSecretName returns the name of the secret which will contain the automation config.
101101 AutomationConfigSecretName () string
102102 // GetUpdateStrategyType returns the UpdateStrategyType of the statefulset.
@@ -126,7 +126,7 @@ type MongoDBStatefulSetOwner interface {
126126// BuildMongoDBReplicaSetStatefulSetModificationFunction builds the parts of the replica set that are common between every resource that implements
127127// MongoDBStatefulSetOwner.
128128// 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 {
130130 labels := map [string ]string {
131131 "app" : mdb .ServiceName (),
132132 }
@@ -138,13 +138,10 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
138138 agentHealthStatusVolumeMount := statefulset .CreateVolumeMount (healthStatusVolume .Name , "/var/log/mongodb-mms-automation/healthstatus" )
139139 mongodHealthStatusVolumeMount := statefulset .CreateVolumeMount (healthStatusVolume .Name , "/healthstatus" )
140140
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 ()
148145
149146 // tmp volume is required by the mongodb-agent and mongod
150147 tmpVolume := statefulset .CreateVolumeFromEmptyDir ("tmp" )
@@ -155,7 +152,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
155152 keyFileVolumeVolumeMount := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
156153 keyFileVolumeVolumeMountMongod := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
157154
158- mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , scriptsVolumeMount , keyFileVolumeVolumeMount , tmpVolumeMount }
155+ mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , keyFileVolumeVolumeMount , tmpVolumeMount }
159156
160157 automationConfigVolumeFunc := podtemplatespec .NOOP ()
161158 if mdb .NeedsAutomationConfigVolume () {
@@ -164,7 +161,31 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
164161 automationConfigVolumeMount := statefulset .CreateVolumeMount (automationConfigVolume .Name , "/var/lib/automation/config" , statefulset .WithReadOnly (true ))
165162 mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , automationConfigVolumeMount )
166163 }
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+
168189 dataVolumeClaim := statefulset .NOOP ()
169190 logVolumeClaim := statefulset .NOOP ()
170191 singleModeVolumeClaim := func (s * appsv1.StatefulSet ) {}
@@ -218,16 +239,16 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
218239 podSecurityContext ,
219240 podtemplatespec .WithPodLabels (labels ),
220241 podtemplatespec .WithVolume (healthStatusVolume ),
221- podtemplatespec .WithVolume (hooksVolume ),
222242 automationConfigVolumeFunc ,
223- podtemplatespec .WithVolume (scriptsVolume ),
243+ hooksVolumeMod ,
244+ scriptsVolumeMod ,
224245 podtemplatespec .WithVolume (tmpVolume ),
225246 podtemplatespec .WithVolume (keyFileVolume ),
226247 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 ,
231252 ),
232253 ))
233254}
@@ -245,11 +266,11 @@ func AutomationAgentCommand(withAgentAPIKeyExport bool) []string {
245266 return []string {"/bin/bash" , "-c" , MongodbUserCommand + BaseAgentCommand () + " -cluster=" + clusterFilePath + automationAgentOptions + automationAgentLogOptions }
246267}
247268
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 {
249270 _ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
250271 return container .Apply (
251272 container .WithName (AgentName ),
252- container .WithImage (os . Getenv ( AgentImageEnv ) ),
273+ container .WithImage (agentImage ),
253274 container .WithImagePullPolicy (corev1 .PullAlways ),
254275 container .WithReadinessProbe (DefaultReadiness ()),
255276 container .WithResourceRequirements (resourcerequirements .Defaults ()),
0 commit comments