Skip to content

Commit

Permalink
Use envconfig for all SUBMARINER_ variables
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
skitt committed Oct 24, 2023
1 parent d4193c3 commit ed6dd54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions pkg/agent/controller/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 11 additions & 13 deletions pkg/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down

0 comments on commit ed6dd54

Please sign in to comment.