diff --git a/cmd/config/set_cluster.go b/cmd/config/set_cluster.go index c730b5346..c974a35ca 100644 --- a/cmd/config/set_cluster.go +++ b/cmd/config/set_cluster.go @@ -24,7 +24,6 @@ import ( "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/environment" - conferrors "opendev.org/airship/airshipctl/pkg/errors" "opendev.org/airship/airshipctl/pkg/log" ) @@ -119,7 +118,7 @@ func runSetCluster(o *config.ClusterOptions, rootSettings *environment.AirshipCT airconfig := rootSettings.Config() cluster, err := airconfig.GetCluster(o.Name, o.ClusterType) if err != nil { - var cerr conferrors.ErrMissingConfig + var cerr config.ErrMissingConfig if !errors.As(err, &cerr) { // An error occurred, but it wasn't a "missing" config error. return clusterWasModified, err diff --git a/cmd/config/set_context.go b/cmd/config/set_context.go index d4f3c8661..38eab3161 100644 --- a/cmd/config/set_context.go +++ b/cmd/config/set_context.go @@ -24,7 +24,6 @@ import ( "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/environment" - conferrors "opendev.org/airship/airshipctl/pkg/errors" ) var ( @@ -106,14 +105,14 @@ func runSetContext(o *config.ContextOptions, airconfig *config.Config) (bool, er contextIWant := o.Name context, err := airconfig.GetContext(contextIWant) if err != nil { - var cerr conferrors.ErrMissingConfig + var cerr config.ErrMissingConfig if !errors.As(err, &cerr) { // An error occurred, but it wasn't a "missing" config error. return contextWasModified, err } if o.CurrentContext { - return contextWasModified, conferrors.ErrMissingConfig{} + return contextWasModified, config.ErrMissingConfig{} } // context didn't exist, create it // ignoring the returned added context @@ -132,7 +131,7 @@ func runSetContext(o *config.ContextOptions, airconfig *config.Config) (bool, er // Update configuration file just in time persistence approach if err := airconfig.PersistConfig(); err != nil { // Error that it didnt persist the changes - return contextWasModified, conferrors.ErrConfigFailed{} + return contextWasModified, config.ErrConfigFailed{} } return contextWasModified, nil diff --git a/pkg/bootstrap/isogen/command.go b/pkg/bootstrap/isogen/command.go index 34b8032fa..e651cc8e5 100644 --- a/pkg/bootstrap/isogen/command.go +++ b/pkg/bootstrap/isogen/command.go @@ -12,7 +12,6 @@ import ( "opendev.org/airship/airshipctl/pkg/container" "opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/environment" - "opendev.org/airship/airshipctl/pkg/errors" "opendev.org/airship/airshipctl/pkg/log" "opendev.org/airship/airshipctl/pkg/util" @@ -45,7 +44,7 @@ func GenerateBootstrapIso(settings *environment.AirshipCTLSettings, args []strin // TODO (dukov) This check should be implemented as part of the config module if manifest == nil { - return errors.ErrMissingConfig{What: "manifest for currnet context not found"} + return config.ErrMissingConfig{What: "manifest for currnet context not found"} } if err = verifyInputs(cfg); err != nil { @@ -78,12 +77,12 @@ func GenerateBootstrapIso(settings *environment.AirshipCTLSettings, args []strin func verifyInputs(cfg *config.Bootstrap) error { if cfg.Container.Volume == "" { log.Print("Specify volume bind for ISO builder container") - return errors.ErrWrongConfig{} + return config.ErrWrongConfig{} } if (cfg.Builder.UserDataFileName == "") || (cfg.Builder.NetworkConfigFileName == "") { log.Print("UserDataFileName or NetworkConfigFileName are not specified in ISO builder config") - return errors.ErrWrongConfig{} + return config.ErrWrongConfig{} } vols := strings.Split(cfg.Container.Volume, ":") @@ -92,7 +91,7 @@ func verifyInputs(cfg *config.Bootstrap) error { cfg.Container.Volume = fmt.Sprintf("%s:%s", vols[0], vols[0]) case len(vols) > 2: log.Print("Bad container volume format. Use hostPath:contPath") - return errors.ErrWrongConfig{} + return config.ErrWrongConfig{} } return nil } diff --git a/pkg/bootstrap/isogen/command_test.go b/pkg/bootstrap/isogen/command_test.go index 983522af4..15cdaf6da 100644 --- a/pkg/bootstrap/isogen/command_test.go +++ b/pkg/bootstrap/isogen/command_test.go @@ -12,7 +12,6 @@ import ( "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/document" - "opendev.org/airship/airshipctl/pkg/errors" "opendev.org/airship/airshipctl/pkg/log" "opendev.org/airship/airshipctl/testutil" ) @@ -133,7 +132,7 @@ func TestVerifyInputs(t *testing.T) { cfg: &config.Bootstrap{ Container: &config.Container{}, }, - expectedErr: errors.ErrWrongConfig{}, + expectedErr: config.ErrWrongConfig{}, }, { cfg: &config.Bootstrap{ @@ -142,7 +141,7 @@ func TestVerifyInputs(t *testing.T) { }, Builder: &config.Builder{}, }, - expectedErr: errors.ErrWrongConfig{}, + expectedErr: config.ErrWrongConfig{}, }, { cfg: &config.Bootstrap{ @@ -166,7 +165,7 @@ func TestVerifyInputs(t *testing.T) { NetworkConfigFileName: "net-conf", }, }, - expectedErr: errors.ErrWrongConfig{}, + expectedErr: config.ErrWrongConfig{}, }, } diff --git a/pkg/config/config.go b/pkg/config/config.go index 52d62f918..7e0afa824 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -32,7 +32,6 @@ import ( kubeconfig "k8s.io/client-go/tools/clientcmd/api" - conferrors "opendev.org/airship/airshipctl/pkg/errors" "opendev.org/airship/airshipctl/pkg/util" ) @@ -391,12 +390,12 @@ func (c *Config) ContextNames() []string { func (c *Config) GetCluster(cName, cType string) (*Cluster, error) { _, exists := c.Clusters[cName] if !exists { - return nil, conferrors.ErrMissingConfig{What: fmt.Sprintf("Cluster with name '%s' of type '%s'", cName, cType)} + return nil, ErrMissingConfig{What: fmt.Sprintf("Cluster with name '%s' of type '%s'", cName, cType)} } // Alternative to this would be enhance Cluster.String() to embedd the appropriate kubeconfig cluster information cluster, exists := c.Clusters[cName].ClusterTypes[cType] if !exists { - return nil, conferrors.ErrMissingConfig{What: fmt.Sprintf("Cluster with name '%s' of type '%s'", cName, cType)} + return nil, ErrMissingConfig{What: fmt.Sprintf("Cluster with name '%s' of type '%s'", cName, cType)} } return cluster, nil } @@ -490,7 +489,7 @@ func (c *Config) GetClusters() ([]*Cluster, error) { func (c *Config) GetContext(cName string) (*Context, error) { context, exists := c.Contexts[cName] if !exists { - return nil, conferrors.ErrMissingConfig{What: fmt.Sprintf("Context with name '%s'", cName)} + return nil, ErrMissingConfig{What: fmt.Sprintf("Context with name '%s'", cName)} } return context, nil } diff --git a/pkg/config/errors.go b/pkg/config/errors.go index 74e83c512..d5815183d 100644 --- a/pkg/config/errors.go +++ b/pkg/config/errors.go @@ -13,3 +13,28 @@ type ErrBootstrapInfoNotFound struct { func (e ErrBootstrapInfoNotFound) Error() string { return fmt.Sprintf("Bootstrap info %s not found", e.Name) } + +// ErrWrongConfig returned in case of incorrect configuration +type ErrWrongConfig struct { +} + +func (e ErrWrongConfig) Error() string { + return "Wrong configuration" +} + +// ErrMissingConfig returned in case of missing configuration +type ErrMissingConfig struct { + What string +} + +func (e ErrMissingConfig) Error() string { + return "Missing configuration: " + e.What +} + +// ErrConfigFailed returned in case of failure during configuration +type ErrConfigFailed struct { +} + +func (e ErrConfigFailed) Error() string { + return "Configuration failed to complete." +} diff --git a/pkg/errors/common.go b/pkg/errors/common.go index b1a725092..b2f64ab09 100644 --- a/pkg/errors/common.go +++ b/pkg/errors/common.go @@ -20,28 +20,3 @@ type ErrNotImplemented struct { func (e ErrNotImplemented) Error() string { return "Not implemented" } - -// ErrWrongConfig returned in case of incorrect configuration -type ErrWrongConfig struct { -} - -func (e ErrWrongConfig) Error() string { - return "Wrong configuration" -} - -// ErrMissingConfig returned in case of missing configuration -type ErrMissingConfig struct { - What string -} - -func (e ErrMissingConfig) Error() string { - return "Missing configuration: " + e.What -} - -// ErrConfigFailed returned in case of failure during configuration -type ErrConfigFailed struct { -} - -func (e ErrConfigFailed) Error() string { - return "Configuration failed to complete." -}