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..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) } - err = unset(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/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) { 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