Skip to content

Commit efc91be

Browse files
authored
Correct argument order for AutomationAgentCommand call (#1573)
1 parent 270ae2a commit efc91be

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

api/v1/mongodbcommunity_types.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ type LogLevel string
356356

357357
const (
358358
LogLevelDebug LogLevel = "DEBUG"
359-
LogLevelInfo string = "INFO"
360-
LogLevelWarn string = "WARN"
361-
LogLevelError string = "ERROR"
362-
LogLevelFatal string = "FATAL"
359+
LogLevelInfo LogLevel = "INFO"
360+
LogLevelWarn LogLevel = "WARN"
361+
LogLevelError LogLevel = "ERROR"
362+
LogLevelFatal LogLevel = "FATAL"
363363
)
364364

365365
type AgentConfiguration struct {

controllers/construct/build_statefulset_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ func TestMongod_Container(t *testing.T) {
177177
}
178178

179179
func TestMongoDBAgentCommand(t *testing.T) {
180-
cmd := AutomationAgentCommand(false, "INFO", "testfile", 24)
180+
cmd := AutomationAgentCommand(false, mdbv1.LogLevelInfo, "testfile", 24)
181181
baseCmd := MongodbUserCommand + BaseAgentCommand() + " -cluster=" + clusterFilePath + automationAgentOptions
182182
assert.Len(t, cmd, 3)
183183
assert.Equal(t, cmd[0], "/bin/bash")
184184
assert.Equal(t, cmd[1], "-c")
185185
assert.Equal(t, cmd[2], baseCmd+" -logFile testfile -logLevel INFO -maxLogFileDurationHrs 24")
186186

187-
cmd = AutomationAgentCommand(false, "INFO", "/dev/stdout", 24)
187+
cmd = AutomationAgentCommand(false, mdbv1.LogLevelInfo, "/dev/stdout", 24)
188188
assert.Len(t, cmd, 3)
189189
assert.Equal(t, cmd[0], "/bin/bash")
190190
assert.Equal(t, cmd[1], "-c")

controllers/construct/mongodbstatefulset.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
207207

208208
agentLogLevel := mdbv1.LogLevelInfo
209209
if mdb.GetAgentLogLevel() != "" {
210-
agentLogLevel = string(mdb.GetAgentLogLevel())
210+
agentLogLevel = mdb.GetAgentLogLevel()
211211
}
212212

213213
agentLogFile := automationconfig.DefaultAgentLogFile
@@ -256,17 +256,17 @@ func BaseAgentCommand() string {
256256

257257
// AutomationAgentCommand withAgentAPIKeyExport detects whether we want to deploy this agent with the agent api key exported
258258
// it can be used to register the agent with OM.
259-
func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel string, logFile string, maxLogFileDurationHours int) []string {
259+
func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel mdbv1.LogLevel, logFile string, maxLogFileDurationHours int) []string {
260260
// This is somewhat undocumented at https://www.mongodb.com/docs/ops-manager/current/reference/mongodb-agent-settings/
261261
// Not setting the -logFile option make the mongodb-agent log to stdout. Setting -logFile /dev/stdout will result in
262262
// an error by the agent trying to open /dev/stdout-verbose and still trying to do log rotation.
263263
// To keep consistent with old behavior not setting the logFile in the config does not log to stdout but keeps
264264
// the default logFile as defined by DefaultAgentLogFile. Setting the logFile explictly to "/dev/stdout" will log to stdout.
265265
agentLogOptions := ""
266266
if logFile == "/dev/stdout" {
267-
agentLogOptions += " -logLevel " + logLevel
267+
agentLogOptions += " -logLevel " + string(logLevel)
268268
} else {
269-
agentLogOptions += " -logFile " + logFile + " -logLevel " + logLevel + " -maxLogFileDurationHrs " + strconv.Itoa(maxLogFileDurationHours)
269+
agentLogOptions += " -logFile " + logFile + " -logLevel " + string(logLevel) + " -maxLogFileDurationHrs " + strconv.Itoa(maxLogFileDurationHours)
270270
}
271271

272272
if withAgentAPIKeyExport {
@@ -275,7 +275,7 @@ func AutomationAgentCommand(withAgentAPIKeyExport bool, logLevel string, logFile
275275
return []string{"/bin/bash", "-c", MongodbUserCommand + BaseAgentCommand() + " -cluster=" + clusterFilePath + automationAgentOptions + agentLogOptions}
276276
}
277277

278-
func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []corev1.VolumeMount, logLevel string, logFile string, maxLogFileDurationHours int, agentImage string) container.Modification {
278+
func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []corev1.VolumeMount, logLevel mdbv1.LogLevel, logFile string, maxLogFileDurationHours int, agentImage string) container.Modification {
279279
_, containerSecurityContext := podtemplatespec.WithDefaultSecurityContextsModifications()
280280
return container.Apply(
281281
container.WithName(AgentName),
@@ -284,7 +284,7 @@ func mongodbAgentContainer(automationConfigSecretName string, volumeMounts []cor
284284
container.WithReadinessProbe(DefaultReadiness()),
285285
container.WithResourceRequirements(resourcerequirements.Defaults()),
286286
container.WithVolumeMounts(volumeMounts),
287-
container.WithCommand(AutomationAgentCommand(false, logFile, logLevel, maxLogFileDurationHours)),
287+
container.WithCommand(AutomationAgentCommand(false, logLevel, logFile, maxLogFileDurationHours)),
288288
containerSecurityContext,
289289
container.WithEnvs(
290290
corev1.EnvVar{

0 commit comments

Comments
 (0)