From bbae0f8a952758cbf3d2af246754474add0da374 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Tue, 24 Oct 2023 13:33:48 +0200 Subject: [PATCH] Use envconfig for all SUBMARINER_ variables In the Lighthouse agent, logging settings are specified using SUBMARINER_ variables but parsed manually. Since envconfig is used for all other SUBMARINER_ variables, extend it to cover these settings as well. Signed-off-by: Stephen Kitt --- pkg/agent/controller/types.go | 2 ++ pkg/agent/main.go | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/agent/controller/types.go b/pkg/agent/controller/types.go index d9c1765ff..35c3c5863 100644 --- a/pkg/agent/controller/types.go +++ b/pkg/agent/controller/types.go @@ -60,9 +60,11 @@ type Controller struct { type AgentSpecification struct { ClusterID string Namespace string + Verbosity int GlobalnetEnabled bool `split_words:"true"` Uninstall bool HaltOnCertError bool `split_words:"true"` + Debug bool } type ServiceImportAggregator struct { diff --git a/pkg/agent/main.go b/pkg/agent/main.go index 1dea4eab8..b44aac4c9 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) util.AddCertificateErrorHandler(agentSpec.HaltOnCertError)