diff --git a/pkg/config/config.go b/pkg/config/config.go index 21b8c3d00..da8c32138 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -113,9 +113,8 @@ func (c *Config) loadFromAirConfig(airshipConfigPath string) error { c.loadedConfigPath = airshipConfigPath // If I can read from the file, load from it - if _, err := os.Stat(airshipConfigPath); os.IsNotExist(err) { - return nil - } else if err != nil { + // throw an error otherwise + if _, err := os.Stat(airshipConfigPath); err != nil { return err } diff --git a/pkg/environment/settings.go b/pkg/environment/settings.go index b50bc94ac..88d9a42f8 100644 --- a/pkg/environment/settings.go +++ b/pkg/environment/settings.go @@ -70,9 +70,9 @@ func (a *AirshipCTLSettings) InitFlags(cmd *cobra.Command) { func (a *AirshipCTLSettings) InitConfig() { a.Config = config.NewConfig() - a.initAirshipConfigPath() - a.initKubeConfigPath() - initPluginPath() + a.InitAirshipConfigPath() + a.InitKubeConfigPath() + InitPluginPath() err := a.Config.LoadConfig(a.AirshipConfigPath, a.KubeConfigPath) if err != nil { @@ -81,7 +81,8 @@ func (a *AirshipCTLSettings) InitConfig() { } } -func (a *AirshipCTLSettings) initAirshipConfigPath() { +// InitAirshipConfigPath - Initializes AirshipConfigPath variable for Config object +func (a *AirshipCTLSettings) InitAirshipConfigPath() { // The airshipConfigPath may already have been received as a command line argument if a.AirshipConfigPath != "" { return @@ -98,7 +99,8 @@ func (a *AirshipCTLSettings) initAirshipConfigPath() { a.AirshipConfigPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipConfig) } -func (a *AirshipCTLSettings) initKubeConfigPath() { +// InitKubeConfigPath - Initializes KubeConfigPath variable for Config object +func (a *AirshipCTLSettings) InitKubeConfigPath() { // NOTE(howell): This function will set the kubeConfigPath to the // default location under the airship directory unless the user // *explicitly* specifies a different location, either by setting the @@ -122,8 +124,8 @@ func (a *AirshipCTLSettings) initKubeConfigPath() { a.KubeConfigPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipKubeConfig) } -// Sets the location to look for kustomize plugins (including airshipctl itself). -func initPluginPath() { +// InitPluginPath - Sets the location to look for kustomize plugins (including airshipctl itself). +func InitPluginPath() { pluginPathLock.Lock() defer pluginPathLock.Unlock() diff --git a/pkg/environment/settings_test.go b/pkg/environment/settings_test.go index c5895fc40..3d6adf342 100644 --- a/pkg/environment/settings_test.go +++ b/pkg/environment/settings_test.go @@ -49,7 +49,9 @@ func TestInitConfig(t *testing.T) { expectedKubeConfig := filepath.Join(testDir, config.AirshipConfigDir, config.AirshipKubeConfig) expectedPluginPath := filepath.Join(testDir, config.AirshipConfigDir, config.AirshipPluginPath) - testSettings.InitConfig() + testSettings.InitAirshipConfigPath() + testSettings.InitKubeConfigPath() + environment.InitPluginPath() assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath) assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath) assert.Equal(t, expectedPluginPath, environment.PluginPath()) @@ -73,7 +75,9 @@ func TestInitConfig(t *testing.T) { defer os.Unsetenv(config.AirshipKubeConfigEnv) defer os.Unsetenv(config.AirshipPluginPathEnv) - testSettings.InitConfig() + testSettings.InitAirshipConfigPath() + testSettings.InitKubeConfigPath() + environment.InitPluginPath() assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath) assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath) assert.Equal(t, expectedPluginPath, environment.PluginPath()) @@ -93,8 +97,8 @@ func TestInitConfig(t *testing.T) { KubeConfigPath: expectedKubeConfig, } - // InitConfig should not change any values - testSettings.InitConfig() + testSettings.InitAirshipConfigPath() + testSettings.InitKubeConfigPath() assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath) assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath) }) @@ -123,7 +127,8 @@ func TestInitConfig(t *testing.T) { KubeConfigPath: expectedKubeConfig, } - testSettings.InitConfig() + testSettings.InitAirshipConfigPath() + testSettings.InitKubeConfigPath() assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath) assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath) })