Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unset profile when it is deleted #4922

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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