From 160117af3adbef8b79d6f9369e3e5f5a6666b53a Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Tue, 25 Aug 2020 16:29:19 -0500 Subject: [PATCH] Use log module to determine current log level As part of config refactoring process, it makes sense to remove Debug field of AirshipCTLSettings and use log module method as source of truth about current log level. Change-Id: I42e3a9fd3b4e2778c71278f98a0d168421dfd2fb Signed-off-by: Ruslan Aliev Relates-To: #327 --- pkg/bootstrap/isogen/command.go | 2 +- pkg/clusterctl/client/executor.go | 2 +- pkg/clusterctl/cmd/command.go | 3 ++- pkg/log/log.go | 5 +++++ pkg/phase/phase.go | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/bootstrap/isogen/command.go b/pkg/bootstrap/isogen/command.go index ee784fc90..a1bbb375e 100644 --- a/pkg/bootstrap/isogen/command.go +++ b/pkg/bootstrap/isogen/command.go @@ -71,7 +71,7 @@ func GenerateBootstrapIso(settings *environment.AirshipCTLSettings) error { return err } - err = generateBootstrapIso(docBundle, builder, cfg, settings.Debug) + err = generateBootstrapIso(docBundle, builder, cfg, log.DebugEnabled()) if err != nil { return err } diff --git a/pkg/clusterctl/client/executor.go b/pkg/clusterctl/client/executor.go index 695f6e6d5..d50159e47 100644 --- a/pkg/clusterctl/client/executor.go +++ b/pkg/clusterctl/client/executor.go @@ -61,7 +61,7 @@ func NewExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) { if err != nil { return nil, err } - client, err := NewClient(tgtPath, cfg.AirshipSettings.Debug, options) + client, err := NewClient(tgtPath, log.DebugEnabled(), options) if err != nil { return nil, err } diff --git a/pkg/clusterctl/cmd/command.go b/pkg/clusterctl/cmd/command.go index 540bcbe49..5982328d9 100644 --- a/pkg/clusterctl/cmd/command.go +++ b/pkg/clusterctl/cmd/command.go @@ -20,6 +20,7 @@ import ( "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/log" ) // Command adds a layer to clusterctl interface with airshipctl context @@ -48,7 +49,7 @@ func NewCommand(rs *environment.AirshipCTLSettings) (*Command, error) { if err != nil { return nil, err } - client, err := client.NewClient(root, rs.Debug, options) + client, err := client.NewClient(root, log.DebugEnabled(), options) if err != nil { return nil, err } diff --git a/pkg/log/log.go b/pkg/log/log.go index e0322d3cd..7d1e0dced 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -31,6 +31,11 @@ func Init(debugFlag bool, out io.Writer) { airshipLog.SetOutput(out) } +// DebugEnabled returns whether the debug level is set +func DebugEnabled() bool { + return debug +} + // Debug is a wrapper for log.Debug func Debug(v ...interface{}) { if debug { diff --git a/pkg/phase/phase.go b/pkg/phase/phase.go index 571743702..e8d2ad740 100644 --- a/pkg/phase/phase.go +++ b/pkg/phase/phase.go @@ -175,7 +175,7 @@ func (p *Cmd) Exec(name string) error { return } executor.Run(runCh, ifc.RunOptions{ - Debug: p.Debug, + Debug: log.DebugEnabled(), DryRun: p.DryRun, }) }()