Skip to content

Commit

Permalink
Correct argument order for AutomationAgentCommand call (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
nammn authored Jun 27, 2024
1 parent 270ae2a commit efc91be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions api/v1/mongodbcommunity_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions controllers/construct/build_statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions controllers/construct/mongodbstatefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe

agentLogLevel := mdbv1.LogLevelInfo
if mdb.GetAgentLogLevel() != "" {
agentLogLevel = string(mdb.GetAgentLogLevel())
agentLogLevel = mdb.GetAgentLogLevel()
}

agentLogFile := automationconfig.DefaultAgentLogFile
Expand Down Expand Up @@ -256,17 +256,17 @@ 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.
// To keep consistent with old behavior not setting the logFile in the config does not log to stdout but keeps
// 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 {
Expand All @@ -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),
Expand All @@ -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{
Expand Down

0 comments on commit efc91be

Please sign in to comment.