Remove debug field from AirshipCTLSettings

As part of config refactoring process, we should remove debug field
from AirshipCTLSettings structure since debug variable is stored in
log module.

Change-Id: I02f3c7160ed0301605de32e0d0267be8524ccc12
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
Relates-To: #327
This commit is contained in:
Ruslan Aliev 2020-08-25 18:06:26 -05:00
parent f1b606f8bf
commit 4c0d2c0b57
10 changed files with 22 additions and 30 deletions

View File

@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
"opendev.org/airship/airshipctl/pkg/remote"
)
@ -41,7 +40,9 @@ func NewBaremetalCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Co
Use: "baremetal",
Short: "Perform actions on baremetal hosts",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(rootSettings.Debug, cmd.OutOrStderr())
if parentPreRun := cmd.Root().PersistentPreRun; parentPreRun != nil {
parentPreRun(cmd.Root(), args)
}
// Load or Initialize airship Config
rootSettings.InitConfig()

View File

@ -19,7 +19,6 @@ import (
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/k8s/client"
"opendev.org/airship/airshipctl/pkg/log"
)
const (
@ -37,7 +36,9 @@ func NewClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comm
Short: "Manage Kubernetes clusters",
Long: clusterLong[1:],
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(rootSettings.Debug, cmd.OutOrStderr())
if parentPreRun := cmd.Root().PersistentPreRun; parentPreRun != nil {
parentPreRun(cmd.Root(), args)
}
// Load or Initialize airship Config
rootSettings.InitConfig()

View File

@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
)
// NewConfigCommand creates a command for interacting with the airshipctl configuration.
@ -28,7 +27,10 @@ func NewConfigCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comma
DisableFlagsInUseLine: true,
Short: "Manage the airshipctl config file",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(rootSettings.Debug, cmd.OutOrStderr())
if parentPreRun := cmd.Root().PersistentPreRun; parentPreRun != nil {
parentPreRun(cmd.Root(), args)
}
if cmd.Use == "init" {
rootSettings.Create = true
}

View File

@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
)
// NewDocumentCommand creates a new command for managing airshipctl documents
@ -26,11 +25,6 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com
documentRootCmd := &cobra.Command{
Use: "document",
Short: "Manage deployment documents",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Note: config is not loaded here; the kustomize plugin command doesn't
// require it, and multiple use cases fail if we assume the file is there.
log.Init(rootSettings.Debug, cmd.OutOrStderr())
},
}
documentRootCmd.AddCommand(NewPullCommand(rootSettings))

View File

@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
)
// NewImageCommand creates a new command for managing ISO images using airshipctl.
@ -27,7 +26,9 @@ func NewImageCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comman
Use: "image",
Short: "Manage ISO image creation",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(rootSettings.Debug, cmd.OutOrStderr())
if parentPreRun := cmd.Root().PersistentPreRun; parentPreRun != nil {
parentPreRun(cmd.Root(), args)
}
// Load or Initialize airship Config
rootSettings.InitConfig()

View File

@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
)
const (
@ -35,7 +34,9 @@ func NewPhaseCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comman
Short: "Manage phases",
Long: clusterLong[1:],
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(rootSettings.Debug, cmd.OutOrStderr())
if parentPreRun := cmd.Root().PersistentPreRun; parentPreRun != nil {
parentPreRun(cmd.Root(), args)
}
// Load or Initialize airship Config
rootSettings.InitConfig()
},

View File

@ -31,6 +31,7 @@ import (
"opendev.org/airship/airshipctl/cmd/phase"
"opendev.org/airship/airshipctl/cmd/secret"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
)
// NewAirshipCTLCommand creates a root `airshipctl` command with the default commands attached
@ -42,13 +43,18 @@ func NewAirshipCTLCommand(out io.Writer) *cobra.Command {
// NewRootCommand creates the root `airshipctl` command. All other commands are
// subcommands branching from this one
func NewRootCommand(out io.Writer) (*cobra.Command, *environment.AirshipCTLSettings) {
var debug bool
rootCmd := &cobra.Command{
Use: "airshipctl",
Short: "A unified entrypoint to various airship components",
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(debug, cmd.OutOrStdout())
},
}
rootCmd.SetOut(out)
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable verbose output")
return rootCmd, makeRootSettings(rootCmd)
}

View File

@ -234,7 +234,6 @@ func TestVerifyInputs(t *testing.T) {
func TestGenerateBootstrapIso(t *testing.T) {
t.Run("EnsureCompleteError", func(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: false,
AirshipConfigPath: "testdata/config/config",
KubeConfigPath: "testdata/config/kubeconfig",
Config: &config.Config{},
@ -248,7 +247,6 @@ func TestGenerateBootstrapIso(t *testing.T) {
t.Run("ContextEntryPointError", func(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: false,
AirshipConfigPath: "testdata/config/config",
KubeConfigPath: "testdata/config/kubeconfig",
Config: &config.Config{},
@ -262,7 +260,6 @@ func TestGenerateBootstrapIso(t *testing.T) {
t.Run("NewBundleByPathError", func(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: false,
AirshipConfigPath: "testdata/config/config",
KubeConfigPath: "testdata/config/kubeconfig",
Config: &config.Config{},
@ -276,7 +273,6 @@ func TestGenerateBootstrapIso(t *testing.T) {
t.Run("SelectOneError", func(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: false,
AirshipConfigPath: "testdata/config/config",
KubeConfigPath: "testdata/config/kubeconfig",
Config: &config.Config{},
@ -291,7 +287,6 @@ func TestGenerateBootstrapIso(t *testing.T) {
t.Run("ToObjectError", func(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: false,
AirshipConfigPath: "testdata/config/config",
KubeConfigPath: "testdata/config/kubeconfig",
Config: &config.Config{},
@ -305,7 +300,6 @@ func TestGenerateBootstrapIso(t *testing.T) {
t.Run("verifyInputsError", func(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: false,
AirshipConfigPath: "testdata/config/config",
KubeConfigPath: "testdata/config/kubeconfig",
Config: &config.Config{},

View File

@ -29,8 +29,6 @@ import (
// AirshipCTLSettings is a container for all of the settings needed by airshipctl
type AirshipCTLSettings struct {
// Debug is used for verbose output
Debug bool
AirshipConfigPath string
KubeConfigPath string
Create bool
@ -40,11 +38,6 @@ type AirshipCTLSettings struct {
// InitFlags adds the default settings flags to cmd
func (a *AirshipCTLSettings) InitFlags(cmd *cobra.Command) {
flags := cmd.PersistentFlags()
flags.BoolVar(
&a.Debug,
"debug",
false,
"enable verbose output")
defaultAirshipConfigDir := filepath.Join(HomeEnvVar, config.AirshipConfigDir)

View File

@ -31,7 +31,6 @@ import (
func TestNewStatusPoller(t *testing.T) {
settings := &environment.AirshipCTLSettings{
Debug: true,
Config: config.NewConfig(),
KubeConfigPath: "testdata/kubeconfig.yaml",
}