Skip to content

Commit

Permalink
Merge pull request #4922 from josedonizetti/deletes-unset-profile
Browse files Browse the repository at this point in the history
Unset profile when it is deleted
  • Loading branch information
medyagh authored Jul 30, 2019
2 parents b309750 + 483fe64 commit 3a718d9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cmd/minikube/cmd/config/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
23 changes: 21 additions & 2 deletions cmd/minikube/cmd/config/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
}
4 changes: 4 additions & 0 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/minikube/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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
Expand Down

0 comments on commit 3a718d9

Please sign in to comment.