Merge "Exclude kubeconfig from use-context update"

This commit is contained in:
Zuul 2020-08-20 05:00:23 +00:00 committed by Gerrit Code Review
commit f396702824
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",
Long: initLong[1:],
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
}
if err = rootSettings.Config.PersistConfig(); err != nil {
if err = rootSettings.Config.PersistConfig(true); err != nil {
return err
}

View File

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

View File

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

View File

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

View File

@ -5,6 +5,7 @@ Switch to a different context
### Synopsis
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
```

View File

@ -183,7 +183,7 @@ func (c *Config) reconcileConfig() error {
// Specially useful if the config is loaded during a get operation
// If it was a Set this would have happened eventually any way
if persistIt {
return c.PersistConfig()
return c.PersistConfig(true)
}
return nil
}
@ -419,7 +419,7 @@ func (c *Config) EnsureComplete() error {
// the current Config and KubeConfig objects.
// If either file did not previously exist, the file will be created.
// Otherwise, the file will be overwritten
func (c *Config) PersistConfig() error {
func (c *Config) PersistConfig(persistKubeConfig bool) error {
airshipConfigYaml, err := c.ToYaml()
if err != nil {
return err
@ -450,9 +450,11 @@ func (c *Config) PersistConfig() error {
return err
}
// Persist the kubeconfig file referenced
if err := clientcmd.WriteToFile(*c.kubeConfig, c.kubeConfigPath); err != nil {
return err
if persistKubeConfig {
// Persist the kubeconfig file referenced
if err := clientcmd.WriteToFile(*c.kubeConfig, c.kubeConfigPath); err != nil {
return err
}
}
return nil
@ -878,7 +880,7 @@ func (c *Config) ImportFromKubeConfig(kubeConfigPath string) error {
c.importClusters(kubeConfig)
c.importContexts(kubeConfig)
c.importAuthInfos(kubeConfig)
return c.PersistConfig()
return c.PersistConfig(true)
}
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
if writeToStorage {
if err := airconfig.PersistConfig(); err != nil {
if err := airconfig.PersistConfig(true); err != nil {
// Error that it didnt persist the changes
return modified, ErrConfigFailed{}
}
@ -89,7 +89,7 @@ func RunSetCluster(o *ClusterOptions, airconfig *Config, writeToStorage bool) (b
// Update configuration file
// Just in time persistence approach
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
// Or should we float this up
// 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
if writeToStorage {
if err := airconfig.PersistConfig(); err != nil {
if err := airconfig.PersistConfig(true); err != nil {
// Error that it didnt persist the changes
return modified, ErrConfigFailed{}
}
@ -159,7 +159,7 @@ func RunUseContext(desiredContext string, airconfig *Config) error {
if airconfig.CurrentContext != desiredContext {
airconfig.CurrentContext = desiredContext
if err := airconfig.PersistConfig(); err != nil {
if err := airconfig.PersistConfig(false); err != nil {
return err
}
}
@ -189,7 +189,7 @@ func RunSetManifest(o *ManifestOptions, airconfig *Config, writeToStorage bool)
}
// Update configuration file just in time persistence approach
if writeToStorage {
if err := airconfig.PersistConfig(); err != nil {
if err := airconfig.PersistConfig(true); err != nil {
// Error that it didnt persist the changes
return modified, ErrConfigFailed{}
}

View File

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