From 45a329fb6c0dc292fc730d13351808eb9c5ce35b Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Tue, 30 Jul 2019 12:44:50 -0300 Subject: [PATCH 1/2] Unset profile when it is deleted --- cmd/minikube/cmd/config/unset.go | 5 +++-- cmd/minikube/cmd/config/unset_test.go | 2 +- cmd/minikube/cmd/delete.go | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/minikube/cmd/config/unset.go b/cmd/minikube/cmd/config/unset.go index 61fa7c7cbb23..39b90b0a996c 100644 --- a/cmd/minikube/cmd/config/unset.go +++ b/cmd/minikube/cmd/config/unset.go @@ -30,7 +30,7 @@ var configUnsetCmd = &cobra.Command{ if len(args) != 1 { exit.UsageT("usage: minikube config unset PROPERTY_NAME") } - err := unset(args[0]) + err := Unset(args[0]) if err != nil { exit.WithError("unset failed", err) } @@ -41,7 +41,8 @@ func init() { ConfigCmd.AddCommand(configUnsetCmd) } -func unset(name string) error { +// Unset unsets a property +func Unset(name string) error { m, err := pkgConfig.ReadConfig() if err != nil { return err diff --git a/cmd/minikube/cmd/config/unset_test.go b/cmd/minikube/cmd/config/unset_test.go index 07f3aebbbf5f..0039c4b1ec12 100644 --- a/cmd/minikube/cmd/config/unset_test.go +++ b/cmd/minikube/cmd/config/unset_test.go @@ -25,7 +25,7 @@ func TestUnsetConfig(t *testing.T) { if err != nil { t.Errorf("Failed to set the property %q", propName) } - err = unset(propName) + err = Unset(propName) if err != nil { t.Errorf("Failed to unset property %q", err) } diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index 95cf4c656a35..d94a6c3a3b44 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -92,6 +92,10 @@ func runDelete(cmd *cobra.Command, args []string) { if err := pkgutil.DeleteKubeConfigContext(constants.KubeconfigPath, machineName); err != nil { exit.WithError("update config", err) } + + if err := cmdcfg.Unset(pkg_config.MachineProfile); err != nil { + exit.WithError("unset minikube profile", err) + } } func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsName string) { From 483fe644eb7db452754219ea7a6b2b8de620768f Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Tue, 30 Jul 2019 14:16:51 -0300 Subject: [PATCH 2/2] Improve UnsetTest --- cmd/minikube/cmd/config/unset_test.go | 21 ++++++++++++++++++++- pkg/minikube/config/config.go | 7 ++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/config/unset_test.go b/cmd/minikube/cmd/config/unset_test.go index 0039c4b1ec12..c26a05028f03 100644 --- a/cmd/minikube/cmd/config/unset_test.go +++ b/cmd/minikube/cmd/config/unset_test.go @@ -16,7 +16,11 @@ limitations under the License. package config -import "testing" +import ( + "testing" + + "k8s.io/minikube/pkg/minikube/config" +) func TestUnsetConfig(t *testing.T) { propName := "cpus" @@ -25,8 +29,23 @@ func TestUnsetConfig(t *testing.T) { if err != nil { t.Errorf("Failed to set the property %q", propName) } + + cpus, err := config.Get("cpus") + if err != nil { + t.Errorf("Failed to read config %q", err) + } + + if cpus != propValue { + t.Errorf("Expected cpus to be %s but got %s", propValue, cpus) + } + err = Unset(propName) if err != nil { t.Errorf("Failed to unset property %q", err) } + + _, err = config.Get("cpus") + if err != config.ErrKeyNotFound { + t.Errorf("Expected error %q but got %q", config.ErrKeyNotFound, err) + } } diff --git a/pkg/minikube/config/config.go b/pkg/minikube/config/config.go index 82690069d8d0..9b531b8a6053 100644 --- a/pkg/minikube/config/config.go +++ b/pkg/minikube/config/config.go @@ -50,6 +50,11 @@ const ( ShowBootstrapperDeprecationNotification = "ShowBootstrapperDeprecationNotification" ) +var ( + // ErrKeyNotFound is the error returned when a key doesn't exist in the config file + ErrKeyNotFound = errors.New("specified key could not be found in config") +) + // MinikubeConfig represents minikube config type MinikubeConfig map[string]interface{} @@ -66,7 +71,7 @@ func get(name string, config MinikubeConfig) (string, error) { if val, ok := config[name]; ok { return fmt.Sprintf("%v", val), nil } - return "", errors.New("specified key could not be found in config") + return "", ErrKeyNotFound } // ReadConfig reads in the JSON minikube config