@@ -12,7 +12,6 @@ import (
12
12
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/probes"
13
13
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/resourcerequirements"
14
14
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/statefulset"
15
- "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/envvar"
16
15
"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/scale"
17
16
appsv1 "k8s.io/api/apps/v1"
18
17
"k8s.io/apimachinery/pkg/types"
@@ -42,7 +41,6 @@ const (
42
41
MongodbImageEnv = "MONGODB_IMAGE"
43
42
VersionUpgradeHookImageEnv = "VERSION_UPGRADE_HOOK_IMAGE"
44
43
ReadinessProbeImageEnv = "READINESS_PROBE_IMAGE"
45
- ManagedSecurityContextEnv = "MANAGED_SECURITY_CONTEXT"
46
44
47
45
automationMongodConfFileName = "automation-mongod.conf"
48
46
keyfileFilePath = "/var/lib/mongodb-mms-automation/authentication/keyfile"
@@ -115,12 +113,16 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
115
113
scriptsVolume := statefulset .CreateVolumeFromEmptyDir ("agent-scripts" )
116
114
scriptsVolumeMount := statefulset .CreateVolumeMount (scriptsVolume .Name , "/opt/scripts" , statefulset .WithReadOnly (false ))
117
115
116
+ // tmp volume is required by the mongodb-agent and mongod
117
+ tmpVolume := statefulset .CreateVolumeFromEmptyDir ("tmp" )
118
+ tmpVolumeMount := statefulset .CreateVolumeMount (tmpVolume .Name , "/tmp" , statefulset .WithReadOnly (false ))
119
+
118
120
keyFileNsName := mdb .GetAgentKeyfileSecretNamespacedName ()
119
121
keyFileVolume := statefulset .CreateVolumeFromEmptyDir (keyFileNsName .Name )
120
122
keyFileVolumeVolumeMount := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
121
123
keyFileVolumeVolumeMountMongod := statefulset .CreateVolumeMount (keyFileVolume .Name , "/var/lib/mongodb-mms-automation/authentication" , statefulset .WithReadOnly (false ))
122
124
123
- mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , scriptsVolumeMount , keyFileVolumeVolumeMount }
125
+ mongodbAgentVolumeMounts := []corev1.VolumeMount {agentHealthStatusVolumeMount , scriptsVolumeMount , keyFileVolumeVolumeMount , tmpVolumeMount }
124
126
125
127
automationConfigVolumeFunc := podtemplatespec .NOOP ()
126
128
if mdb .NeedsAutomationConfigVolume () {
@@ -129,7 +131,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
129
131
automationConfigVolumeMount := statefulset .CreateVolumeMount (automationConfigVolume .Name , "/var/lib/automation/config" , statefulset .WithReadOnly (true ))
130
132
mongodbAgentVolumeMounts = append (mongodbAgentVolumeMounts , automationConfigVolumeMount )
131
133
}
132
- mongodVolumeMounts := []corev1.VolumeMount {mongodHealthStatusVolumeMount , hooksVolumeMount , keyFileVolumeVolumeMountMongod }
134
+ mongodVolumeMounts := []corev1.VolumeMount {mongodHealthStatusVolumeMount , hooksVolumeMount , keyFileVolumeVolumeMountMongod , tmpVolumeMount }
133
135
dataVolumeClaim := statefulset .NOOP ()
134
136
logVolumeClaim := statefulset .NOOP ()
135
137
singleModeVolumeClaim := func (s * appsv1.StatefulSet ) {}
@@ -150,11 +152,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
150
152
singleModeVolumeClaim = statefulset .WithVolumeClaim (mdb .DataVolumeName (), dataPvc (mdb .DataVolumeName ()))
151
153
}
152
154
153
- podSecurityContext := podtemplatespec .NOOP ()
154
- managedSecurityContext := envvar .ReadBool (ManagedSecurityContextEnv )
155
- if ! managedSecurityContext {
156
- podSecurityContext = podtemplatespec .WithSecurityContext (podtemplatespec .DefaultPodSecurityContext ())
157
- }
155
+ podSecurityContext , _ := podtemplatespec .WithDefaultSecurityContextsModifications ()
158
156
159
157
return statefulset .Apply (
160
158
statefulset .WithName (mdb .GetName ()),
@@ -175,6 +173,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
175
173
podtemplatespec .WithVolume (hooksVolume ),
176
174
automationConfigVolumeFunc ,
177
175
podtemplatespec .WithVolume (scriptsVolume ),
176
+ podtemplatespec .WithVolume (tmpVolume ),
178
177
podtemplatespec .WithVolume (keyFileVolume ),
179
178
podtemplatespec .WithServiceAccount (mongodbDatabaseServiceAccountName ),
180
179
podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts )),
@@ -194,6 +193,7 @@ func AutomationAgentCommand() []string {
194
193
}
195
194
196
195
func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount ) container.Modification {
196
+ _ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
197
197
return container .Apply (
198
198
container .WithName (AgentName ),
199
199
container .WithImage (os .Getenv (AgentImageEnv )),
@@ -202,6 +202,7 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor
202
202
container .WithResourceRequirements (resourcerequirements .Defaults ()),
203
203
container .WithVolumeMounts (volumeMounts ),
204
204
container .WithCommand (AutomationAgentCommand ()),
205
+ containerSecurityContext ,
205
206
container .WithEnvs (
206
207
corev1.EnvVar {
207
208
Name : headlessAgentEnv ,
@@ -229,12 +230,14 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor
229
230
}
230
231
231
232
func versionUpgradeHookInit (volumeMount []corev1.VolumeMount ) container.Modification {
233
+ _ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
232
234
return container .Apply (
233
235
container .WithName (versionUpgradeHookName ),
234
236
container .WithCommand ([]string {"cp" , "version-upgrade-hook" , "/hooks/version-upgrade" }),
235
237
container .WithImage (os .Getenv (VersionUpgradeHookImageEnv )),
236
238
container .WithImagePullPolicy (corev1 .PullAlways ),
237
239
container .WithVolumeMounts (volumeMount ),
240
+ containerSecurityContext ,
238
241
)
239
242
}
240
243
@@ -265,12 +268,14 @@ func logsPvc(logsVolumeName string) persistentvolumeclaim.Modification {
265
268
// readinessProbeInit returns a modification function which will add the readiness probe container.
266
269
// this container will copy the readiness probe binary into the /opt/scripts directory.
267
270
func readinessProbeInit (volumeMount []corev1.VolumeMount ) container.Modification {
271
+ _ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
268
272
return container .Apply (
269
273
container .WithName (ReadinessProbeContainerName ),
270
274
container .WithCommand ([]string {"cp" , "/probes/readinessprobe" , "/opt/scripts/readinessprobe" }),
271
275
container .WithImage (os .Getenv (ReadinessProbeImageEnv )),
272
276
container .WithImagePullPolicy (corev1 .PullAlways ),
273
277
container .WithVolumeMounts (volumeMount ),
278
+ containerSecurityContext ,
274
279
)
275
280
}
276
281
@@ -303,11 +308,14 @@ exec mongod -f %s;
303
308
mongoDbCommand ,
304
309
}
305
310
311
+ _ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
312
+
306
313
return container .Apply (
307
314
container .WithName (MongodbName ),
308
315
container .WithImage (getMongoDBImage (version )),
309
316
container .WithResourceRequirements (resourcerequirements .Defaults ()),
310
317
container .WithCommand (containerCommand ),
318
+ containerSecurityContext ,
311
319
container .WithEnvs (
312
320
corev1.EnvVar {
313
321
Name : agentHealthStatusFilePathEnv ,
0 commit comments