Skip to content

Commit

Permalink
Extract magic strings into command.* constants
Browse files Browse the repository at this point in the history
  • Loading branch information
juliogreff committed Jan 16, 2023
1 parent a6ad999 commit c548704
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions cmd/cluster-agent/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions cmd/cluster-agent/subcommands/check/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
})

Expand Down
4 changes: 2 additions & 2 deletions cmd/cluster-agent/subcommands/compliance/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// +build !windows,kubeapiserver

// Package compliance implements 'cluster-agent compliance'.
package version
package compliance

import (
"github.com/spf13/cobra"
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions cmd/cluster-agent/subcommands/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster-agent/subcommands/flare/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster-agent/subcommands/health/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
})

Expand Down
4 changes: 1 addition & 3 deletions cmd/cluster-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
)
Expand Down

0 comments on commit c548704

Please sign in to comment.