@@ -2,11 +2,12 @@ package construct
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/envvar"
6
5
"os"
7
6
"strconv"
8
7
"strings"
9
8
9
+ "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/envvar"
10
+
10
11
"github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
11
12
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/container"
12
13
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/persistentvolumeclaim"
@@ -53,13 +54,14 @@ const (
53
54
VersionUpgradeHookImageEnv = "VERSION_UPGRADE_HOOK_IMAGE"
54
55
ReadinessProbeImageEnv = "READINESS_PROBE_IMAGE"
55
56
agentLogLevelEnv = "AGENT_LOG_LEVEL"
57
+ agentLogFileEnv = "AGENT_LOG_FILE"
56
58
agentMaxLogFileDurationHoursEnv = "AGENT_MAX_LOG_FILE_DURATION_HOURS"
57
59
58
60
automationMongodConfFileName = "automation-mongod.conf"
59
61
keyfileFilePath = "/var/lib/mongodb-mms-automation/authentication/keyfile"
60
62
61
63
automationAgentOptions = " -skipMongoStart -noDaemonize -useLocalMongoDbTools"
62
- automationAgentLogOptions = " -logFile /var/log/mongodb-mms-automation/automation-agent.log -maxLogFileDurationHrs ${AGENT_MAX_LOG_FILE_DURATION_HOURS} -logLevel ${AGENT_LOG_LEVEL}"
64
+ automationAgentLogOptions = " -logFile ${AGENT_LOG_FILE} -maxLogFileDurationHrs ${AGENT_MAX_LOG_FILE_DURATION_HOURS} -logLevel ${AGENT_LOG_LEVEL}"
63
65
64
66
MongodbUserCommand = `current_uid=$(id -u)
65
67
AGENT_API_KEY="$(cat /mongodb-automation/agent-api-key/agentApiKey)"
@@ -98,6 +100,8 @@ type MongoDBStatefulSetOwner interface {
98
100
LogsVolumeName () string
99
101
// GetAgentLogLevel returns the log level for the MongoDB automation agent.
100
102
GetAgentLogLevel () mdbv1.LogLevel
103
+ // GetAgentLogFile returns the log file for the MongoDB automation agent.
104
+ GetAgentLogFile () string
101
105
// GetAgentMaxLogFileDurationHours returns the number of hours after which the log file should be rolled.
102
106
GetAgentMaxLogFileDurationHours () int
103
107
@@ -177,6 +181,11 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
177
181
agentLogLevel = string (mdb .GetAgentLogLevel ())
178
182
}
179
183
184
+ agentLogFile := automationconfig .DefaultAgentLogFile
185
+ if mdb .GetAgentLogFile () != "" {
186
+ agentLogFile = mdb .GetAgentLogFile ()
187
+ }
188
+
180
189
agentMaxLogFileDurationHours := automationconfig .DefaultAgentMaxLogFileDurationHours
181
190
if mdb .GetAgentMaxLogFileDurationHours () != 0 {
182
191
agentMaxLogFileDurationHours = mdb .GetAgentMaxLogFileDurationHours ()
@@ -204,7 +213,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
204
213
podtemplatespec .WithVolume (tmpVolume ),
205
214
podtemplatespec .WithVolume (keyFileVolume ),
206
215
podtemplatespec .WithServiceAccount (mongodbDatabaseServiceAccountName ),
207
- podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts , agentLogLevel , agentMaxLogFileDurationHours )),
216
+ podtemplatespec .WithContainer (AgentName , mongodbAgentContainer (mdb .AutomationConfigSecretName (), mongodbAgentVolumeMounts , agentLogLevel , agentLogFile , agentMaxLogFileDurationHours )),
208
217
podtemplatespec .WithContainer (MongodbName , mongodbContainer (mdb .GetMongoDBVersion (), mongodVolumeMounts , mdb .GetMongodConfiguration ())),
209
218
podtemplatespec .WithInitContainer (versionUpgradeHookName , versionUpgradeHookInit ([]corev1.VolumeMount {hooksVolumeMount })),
210
219
podtemplatespec .WithInitContainer (ReadinessProbeContainerName , readinessProbeInit ([]corev1.VolumeMount {scriptsVolumeMount })),
@@ -220,7 +229,7 @@ func AutomationAgentCommand() []string {
220
229
return []string {"/bin/bash" , "-c" , MongodbUserCommand + BaseAgentCommand () + " -cluster=" + clusterFilePath + automationAgentOptions + automationAgentLogOptions }
221
230
}
222
231
223
- func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount , logLevel string , maxLogFileDurationHours int ) container.Modification {
232
+ func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount , logLevel string , logFile string , maxLogFileDurationHours int ) container.Modification {
224
233
_ , containerSecurityContext := podtemplatespec .WithDefaultSecurityContextsModifications ()
225
234
return container .Apply (
226
235
container .WithName (AgentName ),
@@ -257,6 +266,10 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor
257
266
Name : agentLogLevelEnv ,
258
267
Value : logLevel ,
259
268
},
269
+ corev1.EnvVar {
270
+ Name : agentLogFileEnv ,
271
+ Value : logFile ,
272
+ },
260
273
corev1.EnvVar {
261
274
Name : agentMaxLogFileDurationHoursEnv ,
262
275
Value : strconv .Itoa (maxLogFileDurationHours ),
0 commit comments