@@ -3,6 +3,7 @@ package construct
33import (
44 "fmt"
55 "os"
6+ "strconv"
67 "strings"
78
89 "github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
@@ -34,20 +35,21 @@ const (
3435
3536 MongodbRepoUrl = "MONGODB_REPO_URL"
3637
37- headlessAgentEnv = "HEADLESS_AGENT"
38- podNamespaceEnv = "POD_NAMESPACE"
39- automationConfigEnv = "AUTOMATION_CONFIG_MAP"
40- AgentImageEnv = "AGENT_IMAGE"
41- MongodbImageEnv = "MONGODB_IMAGE"
42- VersionUpgradeHookImageEnv = "VERSION_UPGRADE_HOOK_IMAGE"
43- ReadinessProbeImageEnv = "READINESS_PROBE_IMAGE"
38+ headlessAgentEnv = "HEADLESS_AGENT"
39+ podNamespaceEnv = "POD_NAMESPACE"
40+ automationConfigEnv = "AUTOMATION_CONFIG_MAP"
41+ AgentImageEnv = "AGENT_IMAGE"
42+ MongodbImageEnv = "MONGODB_IMAGE"
43+ VersionUpgradeHookImageEnv = "VERSION_UPGRADE_HOOK_IMAGE"
44+ ReadinessProbeImageEnv = "READINESS_PROBE_IMAGE"
45+ agentLogLevelEnv = "AGENT_LOG_LEVEL"
46+ agentMaxLogFileDurationHoursEnv = "AGENT_MAX_LOG_FILE_DURATION_HOURS"
4447
4548 automationMongodConfFileName = "automation-mongod.conf"
4649 keyfileFilePath = "/var/lib/mongodb-mms-automation/authentication/keyfile"
4750
48- automationAgentOptions = " -skipMongoStart -noDaemonize -useLocalMongoDbTools"
49-
50- automationAgentLogOptions = " -logFile /var/log/mongodb-mms-automation/automation-agent.log -maxLogFileDurationHrs 24 -logLevel DEBUG"
51+ automationAgentOptions = " -skipMongoStart -noDaemonize -useLocalMongoDbTools"
52+ automationAgentLogOptions = " -logFile /var/log/mongodb-mms-automation/automation-agent.log -maxLogFileDurationHrs ${AGENT_MAX_LOG_FILE_DURATION_HOURS} -logLevel ${AGENT_LOG_LEVEL}"
5153
5254 MongodbUserCommand = `current_uid=$(id -u)
5355AGENT_API_KEY="$(cat /mongodb-automation/agent-api-key/agentApiKey)"
@@ -70,7 +72,7 @@ type MongoDBStatefulSetOwner interface {
7072 GetName () string
7173 // GetNamespace returns the namespace the resource is defined in.
7274 GetNamespace () string
73- // GetMongoDBVersion returns the version of MongoDB to be used for this resource
75+ // GetMongoDBVersion returns the version of MongoDB to be used for this resource.
7476 GetMongoDBVersion () string
7577 // AutomationConfigSecretName returns the name of the secret which will contain the automation config.
7678 AutomationConfigSecretName () string
@@ -80,10 +82,14 @@ type MongoDBStatefulSetOwner interface {
8082 HasSeparateDataAndLogsVolumes () bool
8183 // GetAgentKeyfileSecretNamespacedName returns the NamespacedName of the secret which stores the keyfile for the agent.
8284 GetAgentKeyfileSecretNamespacedName () types.NamespacedName
83- // DataVolumeName returns the name that the data volume should have
85+ // DataVolumeName returns the name that the data volume should have.
8486 DataVolumeName () string
85- // LogsVolumeName returns the name that the data volume should have
87+ // LogsVolumeName returns the name that the data volume should have.
8688 LogsVolumeName () string
89+ // GetAgentLogLevel returns the log level for the MongoDB automation agent.
90+ GetAgentLogLevel () mdbv1.LogLevel
91+ // GetAgentMaxLogFileDurationHours returns the number of hours after which the log file should be rolled.
92+ GetAgentMaxLogFileDurationHours () int
8793
8894 // GetMongodConfiguration returns the MongoDB configuration for each member.
8995 GetMongodConfiguration () mdbv1.MongodConfiguration
@@ -156,6 +162,16 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
156162
157163 podSecurityContext , _ := podtemplatespec .WithDefaultSecurityContextsModifications ()
158164
165+ agentLogLevel := mdbv1 .LogLevelInfo
166+ if mdb .GetAgentLogLevel () != "" {
167+ agentLogLevel = string (mdb .GetAgentLogLevel ())
168+ }
169+
170+ agentMaxLogFileDurationHours := automationconfig .DefaultAgentMaxLogFileDurationHours
171+ if mdb .GetAgentMaxLogFileDurationHours () != 0 {
172+ agentMaxLogFileDurationHours = mdb .GetAgentMaxLogFileDurationHours ()
173+ }
174+
159175 return statefulset .Apply (
160176 statefulset .WithName (mdb .GetName ()),
161177 statefulset .WithNamespace (mdb .GetNamespace ()),
@@ -178,7 +194,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
178194 podtemplatespec .WithVolume (tmpVolume ),
179195 podtemplatespec .WithVolume (keyFileVolume ),
180196 podtemplatespec .WithServiceAccount (mongodbDatabaseServiceAccountName ),
181- podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts )),
197+ podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts , agentLogLevel , agentMaxLogFileDurationHours )),
182198 podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (), mongodVolumeMounts , mdb .GetMongodConfiguration ())),
183199 podtemplatespec .WithInitContainer (versionUpgradeHookName , versionUpgradeHookInit ([]corev1.VolumeMount {hooksVolumeMount })),
184200 podtemplatespec .WithInitContainer (ReadinessProbeContainerName , readinessProbeInit ([]corev1.VolumeMount {scriptsVolumeMount })),
@@ -194,7 +210,7 @@ func AutomationAgentCommand() []string {
194210 return []string {"/bin/bash" , "-c" , MongodbUserCommand + BaseAgentCommand () + " -cluster=" + clusterFilePath + automationAgentOptions + automationAgentLogOptions }
195211}
196212
197- func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount ) container.Modification {
213+ func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount , logLevel string , maxLogFileDurationHours int ) container.Modification {
198214 _ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
199215 return container .Apply (
200216 container .WithName (AgentName ),
@@ -227,6 +243,14 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor
227243 Name : agentHealthStatusFilePathEnv ,
228244 Value : agentHealthStatusFilePathValue ,
229245 },
246+ corev1.EnvVar {
247+ Name : agentLogLevelEnv ,
248+ Value : logLevel ,
249+ },
250+ corev1.EnvVar {
251+ Name : agentMaxLogFileDurationHoursEnv ,
252+ Value : strconv .Itoa (maxLogFileDurationHours ),
253+ },
230254 ),
231255 )
232256}
0 commit comments