Exclude kubeconfig from use-context update

Since kubeconfig was moved to manifest we don't
need to change it during use-context update.

Change-Id: Ib6a0ff19eee89bc86a343e374d50938482e33941
Closes: #294
This commit is contained in:
Vladislav Kuzmin 2020-07-16 18:58:31 +04:00
parent f4f107ac53
commit d12c42d043
9 changed files with 23 additions and 19 deletions

View File

@ -44,7 +44,7 @@ func NewInitCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command
Short: "Generate initial configuration files for airshipctl", Short: "Generate initial configuration files for airshipctl",
Long: initLong[1:], Long: initLong[1:],
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return rootSettings.Config.PersistConfig() return rootSettings.Config.PersistConfig(true)
}, },
} }

View File

@ -88,7 +88,7 @@ func NewSetManagementConfigCommand(rootSettings *environment.AirshipCTLSettings)
return nil return nil
} }
if err = rootSettings.Config.PersistConfig(); err != nil { if err = rootSettings.Config.PersistConfig(true); err != nil {
return err return err
} }

View File

@ -4,7 +4,7 @@ Usage:
Examples: Examples:
# Switch to a context named "exampleContext" # Switch to a context named "exampleContext" in airshipctl config file
airshipctl config use-context exampleContext airshipctl config use-context exampleContext

View File

@ -4,7 +4,7 @@ Usage:
Examples: Examples:
# Switch to a context named "exampleContext" # Switch to a context named "exampleContext" in airshipctl config file
airshipctl config use-context exampleContext airshipctl config use-context exampleContext

View File

@ -28,10 +28,11 @@ import (
const ( const (
useContextLong = ` useContextLong = `
Switch to a different context defined in the airshipctl config file. Switch to a different context defined in the airshipctl config file.
This command doesn't change a context for the kubeconfig file.
` `
useContextExample = ` useContextExample = `
# Switch to a context named "exampleContext" # Switch to a context named "exampleContext" in airshipctl config file
airshipctl config use-context exampleContext airshipctl config use-context exampleContext
` `
) )

View File

@ -5,6 +5,7 @@ Switch to a different context
### Synopsis ### Synopsis
Switch to a different context defined in the airshipctl config file. Switch to a different context defined in the airshipctl config file.
This command doesn't change a context for the kubeconfig file.
``` ```
@ -15,7 +16,7 @@ airshipctl config use-context NAME [flags]
``` ```
# Switch to a context named "exampleContext" # Switch to a context named "exampleContext" in airshipctl config file
airshipctl config use-context exampleContext airshipctl config use-context exampleContext
``` ```

View File

@ -174,7 +174,7 @@ func (c *Config) reconcileConfig() error {
// Specially useful if the config is loaded during a get operation // Specially useful if the config is loaded during a get operation
// If it was a Set this would have happened eventually any way // If it was a Set this would have happened eventually any way
if persistIt { if persistIt {
return c.PersistConfig() return c.PersistConfig(true)
} }
return nil return nil
} }
@ -410,7 +410,7 @@ func (c *Config) EnsureComplete() error {
// the current Config and KubeConfig objects. // the current Config and KubeConfig objects.
// If either file did not previously exist, the file will be created. // If either file did not previously exist, the file will be created.
// Otherwise, the file will be overwritten // Otherwise, the file will be overwritten
func (c *Config) PersistConfig() error { func (c *Config) PersistConfig(persistKubeConfig bool) error {
airshipConfigYaml, err := c.ToYaml() airshipConfigYaml, err := c.ToYaml()
if err != nil { if err != nil {
return err return err
@ -429,9 +429,11 @@ func (c *Config) PersistConfig() error {
return err return err
} }
// Persist the kubeconfig file referenced if persistKubeConfig {
if err := clientcmd.WriteToFile(*c.kubeConfig, c.kubeConfigPath); err != nil { // Persist the kubeconfig file referenced
return err if err := clientcmd.WriteToFile(*c.kubeConfig, c.kubeConfigPath); err != nil {
return err
}
} }
return nil return nil
@ -857,7 +859,7 @@ func (c *Config) ImportFromKubeConfig(kubeConfigPath string) error {
c.importClusters(kubeConfig) c.importClusters(kubeConfig)
c.importContexts(kubeConfig) c.importContexts(kubeConfig)
c.importAuthInfos(kubeConfig) c.importAuthInfos(kubeConfig)
return c.PersistConfig() return c.PersistConfig(true)
} }
func (c *Config) importClusters(importKubeConfig *clientcmdapi.Config) { func (c *Config) importClusters(importKubeConfig *clientcmdapi.Config) {

View File

@ -46,7 +46,7 @@ func RunSetAuthInfo(o *AuthInfoOptions, airconfig *Config, writeToStorage bool)
} }
// Update configuration file just in time persistence approach // Update configuration file just in time persistence approach
if writeToStorage { if writeToStorage {
if err := airconfig.PersistConfig(); err != nil { if err := airconfig.PersistConfig(true); err != nil {
// Error that it didnt persist the changes // Error that it didnt persist the changes
return modified, ErrConfigFailed{} return modified, ErrConfigFailed{}
} }
@ -89,7 +89,7 @@ func RunSetCluster(o *ClusterOptions, airconfig *Config, writeToStorage bool) (b
// Update configuration file // Update configuration file
// Just in time persistence approach // Just in time persistence approach
if writeToStorage { if writeToStorage {
if err := airconfig.PersistConfig(); err != nil { if err := airconfig.PersistConfig(true); err != nil {
// Some warning here , that it didnt persist the changes because of this // Some warning here , that it didnt persist the changes because of this
// Or should we float this up // Or should we float this up
// What would it mean? No value. // What would it mean? No value.
@ -142,7 +142,7 @@ func RunSetContext(o *ContextOptions, airconfig *Config, writeToStorage bool) (b
} }
// Update configuration file just in time persistence approach // Update configuration file just in time persistence approach
if writeToStorage { if writeToStorage {
if err := airconfig.PersistConfig(); err != nil { if err := airconfig.PersistConfig(true); err != nil {
// Error that it didnt persist the changes // Error that it didnt persist the changes
return modified, ErrConfigFailed{} return modified, ErrConfigFailed{}
} }
@ -159,7 +159,7 @@ func RunUseContext(desiredContext string, airconfig *Config) error {
if airconfig.CurrentContext != desiredContext { if airconfig.CurrentContext != desiredContext {
airconfig.CurrentContext = desiredContext airconfig.CurrentContext = desiredContext
if err := airconfig.PersistConfig(); err != nil { if err := airconfig.PersistConfig(false); err != nil {
return err return err
} }
} }
@ -189,7 +189,7 @@ func RunSetManifest(o *ManifestOptions, airconfig *Config, writeToStorage bool)
} }
// Update configuration file just in time persistence approach // Update configuration file just in time persistence approach
if writeToStorage { if writeToStorage {
if err := airconfig.PersistConfig(); err != nil { if err := airconfig.PersistConfig(true); err != nil {
// Error that it didnt persist the changes // Error that it didnt persist the changes
return modified, ErrConfigFailed{} return modified, ErrConfigFailed{}
} }

View File

@ -133,7 +133,7 @@ func TestPersistConfig(t *testing.T) {
conf, cleanup := testutil.InitConfig(t) conf, cleanup := testutil.InitConfig(t)
defer cleanup(t) defer cleanup(t)
err := conf.PersistConfig() err := conf.PersistConfig(true)
require.NoError(t, err) require.NoError(t, err)
// Check that the files were created // Check that the files were created
@ -305,7 +305,7 @@ func TestPurge(t *testing.T) {
defer cleanup(t) defer cleanup(t)
// Store it // Store it
err := conf.PersistConfig() err := conf.PersistConfig(true)
assert.NoErrorf(t, err, "Unable to persist configuration expected at %v", conf.LoadedConfigPath()) assert.NoErrorf(t, err, "Unable to persist configuration expected at %v", conf.LoadedConfigPath())
// Verify that the file is there // Verify that the file is there