@@ -3,6 +3,7 @@ package construct
3
3
import (
4
4
"fmt"
5
5
"os"
6
+ "strconv"
6
7
"strings"
7
8
8
9
"github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
@@ -34,20 +35,21 @@ const (
34
35
35
36
MongodbRepoUrl = "MONGODB_REPO_URL"
36
37
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"
44
47
45
48
automationMongodConfFileName = "automation-mongod.conf"
46
49
keyfileFilePath = "/var/lib/mongodb-mms-automation/authentication/keyfile"
47
50
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}"
51
53
52
54
MongodbUserCommand = `current_uid=$(id -u)
53
55
AGENT_API_KEY="$(cat /mongodb-automation/agent-api-key/agentApiKey)"
@@ -70,7 +72,7 @@ type MongoDBStatefulSetOwner interface {
70
72
GetName () string
71
73
// GetNamespace returns the namespace the resource is defined in.
72
74
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.
74
76
GetMongoDBVersion () string
75
77
// AutomationConfigSecretName returns the name of the secret which will contain the automation config.
76
78
AutomationConfigSecretName () string
@@ -80,10 +82,14 @@ type MongoDBStatefulSetOwner interface {
80
82
HasSeparateDataAndLogsVolumes () bool
81
83
// GetAgentKeyfileSecretNamespacedName returns the NamespacedName of the secret which stores the keyfile for the agent.
82
84
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.
84
86
DataVolumeName () string
85
- // LogsVolumeName returns the name that the data volume should have
87
+ // LogsVolumeName returns the name that the data volume should have.
86
88
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
87
93
88
94
// GetMongodConfiguration returns the MongoDB configuration for each member.
89
95
GetMongodConfiguration () mdbv1.MongodConfiguration
@@ -156,6 +162,16 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
156
162
157
163
podSecurityContext , _ := podtemplatespec .WithDefaultSecurityContextsModifications ()
158
164
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
+
159
175
return statefulset .Apply (
160
176
statefulset .WithName (mdb .GetName ()),
161
177
statefulset .WithNamespace (mdb .GetNamespace ()),
@@ -178,7 +194,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
178
194
podtemplatespec .WithVolume (tmpVolume ),
179
195
podtemplatespec .WithVolume (keyFileVolume ),
180
196
podtemplatespec .WithServiceAccount (mongodbDatabaseServiceAccountName ),
181
- podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts )),
197
+ podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts , agentLogLevel , agentMaxLogFileDurationHours )),
182
198
podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (), mongodVolumeMounts , mdb .GetMongodConfiguration ())),
183
199
podtemplatespec .WithInitContainer (versionUpgradeHookName , versionUpgradeHookInit ([]corev1.VolumeMount {hooksVolumeMount })),
184
200
podtemplatespec .WithInitContainer (ReadinessProbeContainerName , readinessProbeInit ([]corev1.VolumeMount {scriptsVolumeMount })),
@@ -194,7 +210,7 @@ func AutomationAgentCommand() []string {
194
210
return []string {"/bin/bash" , "-c" , MongodbUserCommand + BaseAgentCommand () + " -cluster=" + clusterFilePath + automationAgentOptions + automationAgentLogOptions }
195
211
}
196
212
197
- func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount ) container.Modification {
213
+ func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount , logLevel string , maxLogFileDurationHours int ) container.Modification {
198
214
_ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
199
215
return container .Apply (
200
216
container .WithName (AgentName ),
@@ -227,6 +243,14 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor
227
243
Name : agentHealthStatusFilePathEnv ,
228
244
Value : agentHealthStatusFilePathValue ,
229
245
},
246
+ corev1.EnvVar {
247
+ Name : agentLogLevelEnv ,
248
+ Value : logLevel ,
249
+ },
250
+ corev1.EnvVar {
251
+ Name : agentMaxLogFileDurationHoursEnv ,
252
+ Value : strconv .Itoa (maxLogFileDurationHours ),
253
+ },
230
254
),
231
255
)
232
256
}
0 commit comments