diff --git a/pkg/agent/controller/types.go b/pkg/agent/controller/types.go index f3b2ecaad..a491a6351 100644 --- a/pkg/agent/controller/types.go +++ b/pkg/agent/controller/types.go @@ -60,8 +60,10 @@ type Controller struct { type AgentSpecification struct { ClusterID string Namespace string + Verbosity int GlobalnetEnabled bool `split_words:"true"` Uninstall bool + Debug bool } type ServiceImportAggregator struct { diff --git a/pkg/agent/main.go b/pkg/agent/main.go index eda30be03..95ac7a9aa 100644 --- a/pkg/agent/main.go +++ b/pkg/agent/main.go @@ -69,17 +69,19 @@ func exitOnError(err error, reason string) { } func main() { - // Handle environment variables: - // SUBMARINER_VERBOSITY determines the verbosity level (1 by default) - // SUBMARINER_DEBUG, if set to true, sets the verbosity level to 3 - if debug := os.Getenv("SUBMARINER_DEBUG"); debug == "true" { - os.Args = append(os.Args, fmt.Sprintf("-v=%d", log.LIBDEBUG)) - } else if verbosity := os.Getenv("SUBMARINER_VERBOSITY"); verbosity != "" { - os.Args = append(os.Args, fmt.Sprintf("-v=%s", verbosity)) - } else { - os.Args = append(os.Args, fmt.Sprintf("-v=%d", log.DEBUG)) + agentSpec := controller.AgentSpecification{ + Verbosity: log.DEBUG, + } + err := envconfig.Process("submariner", &agentSpec) + exitOnError(err, "Error processing env config for agent spec") + + if agentSpec.Debug { + agentSpec.Verbosity = log.LIBDEBUG } + // Set up verbosity based on environment variables + os.Args = append(os.Args, fmt.Sprintf("-v=%d", agentSpec.Verbosity)) + kzerolog.AddFlags(nil) flag.Parse() @@ -104,10 +106,6 @@ func main() { klogFlags.Parse(os.Args[1:]) logger.Infof("Arguments: %v", os.Args) - - agentSpec := controller.AgentSpecification{} - err := envconfig.Process("submariner", &agentSpec) - exitOnError(err, "Error processing env config for agent spec") logger.Infof("AgentSpec: %#v", agentSpec) err = mcsv1a1.AddToScheme(scheme.Scheme)