From c548704d686a1e4553d31a31894ee1a855a0286b Mon Sep 17 00:00:00 2001 From: Julio Greff Date: Thu, 12 Jan 2023 08:59:42 +0100 Subject: [PATCH] Extract magic strings into command.* constants --- cmd/cluster-agent/command/command.go | 5 +++++ cmd/cluster-agent/subcommands/check/command.go | 4 +--- cmd/cluster-agent/subcommands/compliance/command.go | 4 ++-- cmd/cluster-agent/subcommands/config/command.go | 4 +--- cmd/cluster-agent/subcommands/flare/command.go | 2 +- cmd/cluster-agent/subcommands/health/command.go | 2 +- cmd/cluster-agent/subcommands/start/command.go | 4 +--- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cmd/cluster-agent/command/command.go b/cmd/cluster-agent/command/command.go index dd2c43b3e7b37..af41b57ec2bf8 100644 --- a/cmd/cluster-agent/command/command.go +++ b/cmd/cluster-agent/command/command.go @@ -17,6 +17,11 @@ import ( "github.com/spf13/cobra" ) +const ( + LoggerName = "CLUSTER" + DefaultLogLevel = "off" +) + // GlobalParams contains the values of agent-global Cobra flags. // // A pointer to this type is passed to SubcommandFactory's, but its contents diff --git a/cmd/cluster-agent/subcommands/check/command.go b/cmd/cluster-agent/subcommands/check/command.go index d7a7ad75aed84..f3e6e7892bf41 100644 --- a/cmd/cluster-agent/subcommands/check/command.go +++ b/cmd/cluster-agent/subcommands/check/command.go @@ -16,15 +16,13 @@ import ( "github.com/spf13/cobra" ) -const loggerName = "CLUSTER" - // Commands returns a slice of subcommands for the 'cluster-agent' command. func Commands(globalParams *command.GlobalParams) []*cobra.Command { cmd := check.MakeCommand(func() check.GlobalParams { return check.GlobalParams{ ConfFilePath: globalParams.ConfFilePath, ConfigName: "datadog-cluster", - LoggerName: loggerName, + LoggerName: command.LoggerName, } }) diff --git a/cmd/cluster-agent/subcommands/compliance/command.go b/cmd/cluster-agent/subcommands/compliance/command.go index 20cf603f82dfa..589c68d82f986 100644 --- a/cmd/cluster-agent/subcommands/compliance/command.go +++ b/cmd/cluster-agent/subcommands/compliance/command.go @@ -7,7 +7,7 @@ // +build !windows,kubeapiserver // Package compliance implements 'cluster-agent compliance'. -package version +package compliance import ( "github.com/spf13/cobra" @@ -28,7 +28,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { bundleParams := core.BundleParams{ ConfigParams: config.NewClusterAgentParams(""), - LogParams: log.LogForOneShot("CLUSTER", "off", true), + LogParams: log.LogForOneShot(command.LoggerName, command.DefaultLogLevel, true), } // TODO: The SecAgent Check package should be a component diff --git a/cmd/cluster-agent/subcommands/config/command.go b/cmd/cluster-agent/subcommands/config/command.go index cf877493cc8da..895cb48c71fb4 100644 --- a/cmd/cluster-agent/subcommands/config/command.go +++ b/cmd/cluster-agent/subcommands/config/command.go @@ -22,15 +22,13 @@ import ( "github.com/spf13/cobra" ) -const loggerName = "CLUSTER" - // Commands returns a slice of subcommands for the 'cluster-agent' command. func Commands(globalParams *command.GlobalParams) []*cobra.Command { cmd := config.MakeCommand(func() config.GlobalParams { return config.GlobalParams{ ConfFilePath: globalParams.ConfFilePath, ConfigName: "datadog-cluster", - LoggerName: loggerName, + LoggerName: command.LoggerName, SettingsClient: newSettingsClient, } }) diff --git a/cmd/cluster-agent/subcommands/flare/command.go b/cmd/cluster-agent/subcommands/flare/command.go index 634c386b8fd79..1ff2c2346bc0f 100644 --- a/cmd/cluster-agent/subcommands/flare/command.go +++ b/cmd/cluster-agent/subcommands/flare/command.go @@ -60,7 +60,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath, config.WithConfigLoadSecrets(true)), - LogParams: log.LogForOneShot("CLUSTER", "off", true), + LogParams: log.LogForOneShot(command.LoggerName, command.DefaultLogLevel, true), }), core.Bundle, ) diff --git a/cmd/cluster-agent/subcommands/health/command.go b/cmd/cluster-agent/subcommands/health/command.go index 676f23f798006..2d928ceb03ea4 100644 --- a/cmd/cluster-agent/subcommands/health/command.go +++ b/cmd/cluster-agent/subcommands/health/command.go @@ -22,7 +22,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { return health.GlobalParams{ ConfFilePath: globalParams.ConfFilePath, ConfigName: "datadog-cluster", - LoggerName: "CLUSTER", + LoggerName: command.LoggerName, } }) diff --git a/cmd/cluster-agent/subcommands/start/command.go b/cmd/cluster-agent/subcommands/start/command.go index 20da0bfcd0fe0..5e2b557c6268c 100644 --- a/cmd/cluster-agent/subcommands/start/command.go +++ b/cmd/cluster-agent/subcommands/start/command.go @@ -64,8 +64,6 @@ import ( "k8s.io/client-go/tools/record" ) -const loggerName = "CLUSTER" - // Commands returns a slice of subcommands for the 'cluster-agent' command. func Commands(globalParams *command.GlobalParams) []*cobra.Command { startCmd := &cobra.Command{ @@ -80,7 +78,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(globalParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath, config.WithConfigLoadSecrets(true)), - LogParams: log.LogForDaemon(loggerName, "log_file", common.DefaultDCALogFile), + LogParams: log.LogForDaemon(command.LoggerName, "log_file", common.DefaultDCALogFile), }), core.Bundle, )