@@ -122,6 +122,8 @@ func appDbPodSpec(initContainerImage string, om om.MongoDBOpsManager) podtemplat
122122 construct .AgentName ,
123123 container .WithResourceRequirements (buildRequirementsFromPodSpec (* appdbPodSpec )),
124124 )
125+ scriptsVolumeMount := statefulset .CreateVolumeMount ("agent-scripts" , "/opt/scripts" , statefulset .WithReadOnly (false ))
126+ hooksVolumeMount := statefulset .CreateVolumeMount ("hooks" , "/hooks" , statefulset .WithReadOnly (false ))
125127
126128 initUpdateFunc := podtemplatespec .NOOP ()
127129 if ! architectures .IsRunningStaticArchitecture (om .Annotations ) {
@@ -130,8 +132,6 @@ func appDbPodSpec(initContainerImage string, om om.MongoDBOpsManager) podtemplat
130132 // volumes of different containers.
131133 initUpdateFunc = func (templateSpec * corev1.PodTemplateSpec ) {
132134 templateSpec .Spec .InitContainers = []corev1.Container {}
133- scriptsVolumeMount := statefulset .CreateVolumeMount ("agent-scripts" , "/opt/scripts" , statefulset .WithReadOnly (false ))
134- hooksVolumeMount := statefulset .CreateVolumeMount ("hooks" , "/hooks" , statefulset .WithReadOnly (false ))
135135 podtemplatespec .WithInitContainer (InitAppDbContainerName , buildAppDBInitContainer (initContainerImage , []corev1.VolumeMount {scriptsVolumeMount , hooksVolumeMount }))(templateSpec )
136136 }
137137 }
@@ -233,6 +233,12 @@ func CAConfigMapName(appDb om.AppDBSpec, log *zap.SugaredLogger) string {
233233// and volumemounts for TLS.
234234func tlsVolumes (appDb om.AppDBSpec , podVars * env.PodEnvVars , log * zap.SugaredLogger ) podtemplatespec.Modification {
235235 volumesToAdd , volumeMounts := getTLSVolumesAndVolumeMounts (appDb , podVars , log )
236+
237+ // Add agent API key volume mount if not using vault and monitoring is enabled
238+ if ! vault .IsVaultSecretBackend () && ShouldEnableMonitoring (podVars ) {
239+ volumeMounts = append (volumeMounts , statefulset .CreateVolumeMount (AgentAPIKeyVolumeName , AgentAPIKeySecretPath ))
240+ }
241+
236242 volumesFunc := func (spec * corev1.PodTemplateSpec ) {
237243 for _ , v := range volumesToAdd {
238244 podtemplatespec .WithVolume (v )(spec )
@@ -380,7 +386,7 @@ func AppDbStatefulSet(opsManager om.MongoDBOpsManager, podVars *env.PodEnvVars,
380386 externalDomain := appDb .GetExternalDomainForMemberCluster (scaler .MemberClusterName ())
381387
382388 if ShouldEnableMonitoring (podVars ) {
383- monitoringModification = addMonitoringContainer (* appDb , * podVars , opts , externalDomain , log )
389+ monitoringModification = addMonitoringContainer (* appDb , * podVars , opts , externalDomain , architectures . IsRunningStaticArchitecture ( opsManager . Annotations ), log )
384390 } else {
385391 // Otherwise, let's remove for now every podTemplateSpec related to monitoring
386392 // We will apply them when enabling monitoring
@@ -390,7 +396,7 @@ func AppDbStatefulSet(opsManager om.MongoDBOpsManager, podVars *env.PodEnvVars,
390396 }
391397
392398 // We copy the Automation Agent command from community and add the agent startup parameters
393- automationAgentCommand := construct .AutomationAgentCommand (true , opsManager .Spec .AppDB .GetAgentLogLevel (), opsManager .Spec .AppDB .GetAgentLogFile (), opsManager .Spec .AppDB .GetAgentMaxLogFileDurationHours ())
399+ automationAgentCommand := construct .AutomationAgentCommand (architectures . IsRunningStaticArchitecture ( opsManager . Annotations ), true , opsManager .Spec .AppDB .GetAgentLogLevel (), opsManager .Spec .AppDB .GetAgentLogFile (), opsManager .Spec .AppDB .GetAgentMaxLogFileDurationHours ())
394400 idx := len (automationAgentCommand ) - 1
395401 automationAgentCommand [idx ] += appDb .AutomationAgent .StartupParameters .ToCommandLineArgs ()
396402
@@ -403,13 +409,10 @@ func AppDbStatefulSet(opsManager om.MongoDBOpsManager, podVars *env.PodEnvVars,
403409 MountPath : "/var/lib/automation/config/acVersion" ,
404410 }
405411
406- // Here we ask to craete init containers which also creates required volumens .
412+ // Here we ask to create init containers which also creates required volumes .
407413 // Note that we provide empty images for init containers. They are not important
408- // at this stage beucase later we will define our own init containers for non-static architecture.
409- mod := construct .BuildMongoDBReplicaSetStatefulSetModificationFunction (& opsManager .Spec .AppDB , scaler , opts .MongodbImage , opts .AgentImage , "" , "" , true )
410- if architectures .IsRunningStaticArchitecture (opsManager .Annotations ) {
411- mod = construct .BuildMongoDBReplicaSetStatefulSetModificationFunction (& opsManager .Spec .AppDB , scaler , opts .MongodbImage , opts .AgentImage , "" , "" , false )
412- }
414+ // at this stage because later we will define our own init containers for non-static architecture.
415+ mod := construct .BuildMongoDBReplicaSetStatefulSetModificationFunction (& opsManager .Spec .AppDB , scaler , opts .MongodbImage , opts .AgentImage , "" , "" , ! architectures .IsRunningStaticArchitecture (opsManager .Annotations ), opts .InitAppDBImage )
413416
414417 sts := statefulset .New (
415418 mod ,
@@ -493,7 +496,7 @@ func getVolumeMountIndexByName(mounts []corev1.VolumeMount, name string) int {
493496// addMonitoringContainer returns a podtemplatespec modification that adds the monitoring container to the AppDB Statefulset.
494497// Note that this replicates some code from the functions that do this for the base AppDB Statefulset. After many iterations
495498// this was deemed to be an acceptable compromise to make code clearer and more maintainable.
496- func addMonitoringContainer (appDB om.AppDBSpec , podVars env.PodEnvVars , opts AppDBStatefulSetOptions , externalDomain * string , log * zap.SugaredLogger ) podtemplatespec.Modification {
499+ func addMonitoringContainer (appDB om.AppDBSpec , podVars env.PodEnvVars , opts AppDBStatefulSetOptions , externalDomain * string , isStatic bool , log * zap.SugaredLogger ) podtemplatespec.Modification {
497500 var monitoringAcVolume corev1.Volume
498501 var monitoringACFunc podtemplatespec.Modification
499502
@@ -516,7 +519,7 @@ func addMonitoringContainer(appDB om.AppDBSpec, podVars env.PodEnvVars, opts App
516519 }
517520 // Construct the command by concatenating:
518521 // 1. The base command - from community
519- command := construct .MongodbUserCommandWithAPIKeyExport
522+ command := construct .GetMongodbUserCommandWithAPIKeyExport ( isStatic )
520523 command += "agent/mongodb-agent"
521524 command += " -healthCheckFilePath=" + monitoringAgentHealthStatusFilePathValue
522525 command += " -serveStatusPort=5001"
0 commit comments