diff --git a/api/v1/mongodbcommunity_types.go b/api/v1/mongodbcommunity_types.go index 0f7128713..8c78b8a4e 100644 --- a/api/v1/mongodbcommunity_types.go +++ b/api/v1/mongodbcommunity_types.go @@ -356,10 +356,10 @@ type LogLevel string const ( LogLevelDebug LogLevel = "DEBUG" - LogLevelInfo string = "INFO" - LogLevelWarn string = "WARN" - LogLevelError string = "ERROR" - LogLevelFatal string = "FATAL" + LogLevelInfo LogLevel = "INFO" + LogLevelWarn LogLevel = "WARN" + LogLevelError LogLevel = "ERROR" + LogLevelFatal LogLevel = "FATAL" ) type AgentConfiguration struct { diff --git a/controllers/construct/build_statefulset_test.go b/controllers/construct/build_statefulset_test.go index bb5dceeaa..56e3bcaac 100644 --- a/controllers/construct/build_statefulset_test.go +++ b/controllers/construct/build_statefulset_test.go @@ -177,14 +177,14 @@ func TestMongod_Container(t *testing.T) { } func TestMongoDBAgentCommand(t *testing.T) { - cmd := AutomationAgentCommand(false, "INFO", "testfile", 24) + cmd := AutomationAgentCommand(false, mdbv1.LogLevelInfo, "testfile", 24) baseCmd := MongodbUserCommand + BaseAgentCommand() + " -cluster=" + clusterFilePath + automationAgentOptions assert.Len(t, cmd, 3) assert.Equal(t, cmd[0], "/bin/bash") assert.Equal(t, cmd[1], "-c") assert.Equal(t, cmd[2], baseCmd+" -logFile testfile -logLevel INFO -maxLogFileDurationHrs 24") - cmd = AutomationAgentCommand(false, "INFO", "/dev/stdout", 24) + cmd = AutomationAgentCommand(false, mdbv1.LogLevelInfo, "/dev/stdout", 24) assert.Len(t, cmd, 3) assert.Equal(t, cmd[0], "/bin/bash") assert.Equal(t, cmd[1], "-c") diff --git a/controllers/construct/mongodbstatefulset.go b/controllers/construct/mongodbstatefulset.go index 4f556f231..a6a71ff9b 100644 --- a/controllers/construct/mongodbstatefulset.go +++ b/controllers/construct/mongodbstatefulset.go @@ -207,7 +207,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe agentLogLevel := mdbv1.LogLevelInfo if mdb.GetAgentLogLevel() != "" { - agentLogLevel = string(mdb.GetAgentLogLevel()) + agentLogLevel = mdb.GetAgentLogLevel() } agentLogFile := automationconfig.DefaultAgentLogFile @@ -256,7 +256,7 @@ func BaseAgentCommand() string { // AutomationAgentCommand withAgentAPIKeyExport detects whether we want to deploy this agent with the agent api key exported // it can be used to register the agent with OM. -func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel string, logFile string, maxLogFileDurationHours int) []string { +func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel mdbv1.LogLevel, logFile string, maxLogFileDurationHours int) []string { // This is somewhat undocumented at https://www.mongodb.com/docs/ops-manager/current/reference/mongodb-agent-settings/ // Not setting the -logFile option make the mongodb-agent log to stdout. Setting -logFile /dev/stdout will result in // an error by the agent trying to open /dev/stdout-verbose and still trying to do log rotation. @@ -264,9 +264,9 @@ func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel string, logFile // the default logFile as defined by DefaultAgentLogFile. Setting the logFile explictly to "/dev/stdout" will log to stdout. agentLogOptions := "" if logFile == "/dev/stdout" { - agentLogOptions += " -logLevel " + logLevel + agentLogOptions += " -logLevel " + string(logLevel) } else { - agentLogOptions += " -logFile " + logFile + " -logLevel " + logLevel + " -maxLogFileDurationHrs " + strconv.Itoa(maxLogFileDurationHours) + agentLogOptions += " -logFile " + logFile + " -logLevel " + string(logLevel) + " -maxLogFileDurationHrs " + strconv.Itoa(maxLogFileDurationHours) } if withAgentAPIKeyExport { @@ -275,7 +275,7 @@ func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel string, logFile return []string{"/bin/bash", "-c", MongodbUserCommand + BaseAgentCommand() + " -cluster=" + clusterFilePath + automationAgentOptions + agentLogOptions} } -func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []corev1.VolumeMount, logLevel string, logFile string, maxLogFileDurationHours int, agentImage string) container.Modification { +func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []corev1.VolumeMount, logLevel mdbv1.LogLevel, logFile string, maxLogFileDurationHours int, agentImage string) container.Modification { _, containerSecurityContext := podtemplatespec.WithDefaultSecurityContextsModifications() return container.Apply( container.WithName(AgentName), @@ -284,7 +284,7 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor container.WithReadinessProbe(DefaultReadiness()), container.WithResourceRequirements(resourcerequirements.Defaults()), container.WithVolumeMounts(volumeMounts), - container.WithCommand(AutomationAgentCommand(false, logFile, logLevel, maxLogFileDurationHours)), + container.WithCommand(AutomationAgentCommand(false, logLevel, logFile, maxLogFileDurationHours)), containerSecurityContext, container.WithEnvs( corev1.EnvVar{