diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index a0b14ec63f33..5d2f4f9bb00b 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -25,7 +25,7 @@ import ( "github.com/docker/machine/libmachine/mcnerror" "github.com/golang/glog" - ps "github.com/mitchellh/go-ps" + "github.com/mitchellh/go-ps" "github.com/pkg/errors" "github.com/docker/machine/libmachine" @@ -43,6 +43,7 @@ import ( ) var deleteAll bool +var purge bool // deleteCmd represents the delete command var deleteCmd = &cobra.Command{ @@ -70,6 +71,16 @@ func (error DeletionError) Error() string { return error.Err.Error() } +func init() { + deleteCmd.Flags().BoolVar(&deleteAll, "all", false, "Set flag to delete all profiles") + deleteCmd.Flags().BoolVar(&purge, "purge", false, "Set this flag to delete the '.minikube' folder from your user directory.") + + if err := viper.BindPFlags(deleteCmd.Flags()); err != nil { + exit.WithError("unable to bind flags", err) + } + RootCmd.AddCommand(deleteCmd) +} + // runDelete handles the executes the flow of "minikube delete" func runDelete(cmd *cobra.Command, args []string) { if len(args) > 0 { @@ -80,14 +91,23 @@ func runDelete(cmd *cobra.Command, args []string) { exit.WithError("Could not get profile flag", err) } + validProfiles, invalidProfiles, err := pkg_config.ListProfiles() + profilesToDelete := append(validProfiles, invalidProfiles...) + + // If the purge flag is set, go ahead and delete the .minikube directory. + if purge && len(profilesToDelete) > 1 && !deleteAll { + out.ErrT(out.Notice, "Multiple minikube profiles were found - ") + for _, p := range profilesToDelete { + out.T(out.Notice, " - {{.profile}}", out.V{"profile": p.Name}) + } + exit.UsageT("Usage: minikube delete --all --purge") + } + if deleteAll { if profileFlag != constants.DefaultMachineName { exit.UsageT("usage: minikube delete --all") } - validProfiles, invalidProfiles, err := pkg_config.ListProfiles() - profilesToDelete := append(validProfiles, invalidProfiles...) - if err != nil { exit.WithError("Error getting profiles to delete", err) } @@ -116,6 +136,15 @@ func runDelete(cmd *cobra.Command, args []string) { out.T(out.DeletingHost, "Successfully deleted profile \"{{.name}}\"", out.V{"name": profileName}) } } + + // If the purge flag is set, go ahead and delete the .minikube directory. + if purge { + glog.Infof("Purging the '.minikube' directory located at %s", localpath.MiniPath()) + if err := os.RemoveAll(localpath.MiniPath()); err != nil { + exit.WithError("unable to delete minikube config folder", err) + } + out.T(out.Crushed, "Successfully purged minikube directory located at - [{{.minikubeDirectory}}]", out.V{"minikubeDirectory": localpath.MiniPath()}) + } } // Deletes one or more profiles @@ -346,8 +375,3 @@ func killMountProcess() error { } return nil } - -func init() { - deleteCmd.Flags().BoolVar(&deleteAll, "all", false, "Set flag to delete all profiles") - RootCmd.AddCommand(deleteCmd) -} diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 7526daf324f3..c1835357a0ae 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -270,16 +270,16 @@ func StopHost(api libmachine.API) error { // DeleteHost deletes the host VM. func DeleteHost(api libmachine.API) error { - name := cfg.GetMachineName() - host, err := api.Load(name) + host, err := api.Load(cfg.GetMachineName()) if err != nil { return errors.Wrap(err, "load") } + // Get the status of the host. Ensure that it exists before proceeding ahead. status, err := GetHostStatus(api) if err != nil { // Warn, but proceed - out.WarningT("Unable to get the status of the {{.name}} cluster.", out.V{"name": name}) + out.WarningT("Unable to get the status of the {{.name}} cluster.", out.V{"name": cfg.GetMachineName()}) } if status == state.None.String() { @@ -291,6 +291,7 @@ func DeleteHost(api libmachine.API) error { if err := trySSHPowerOff(host); err != nil { glog.Infof("Unable to power off minikube because the host was not found.") } + out.T(out.DeletingHost, "Successfully powered off Hyper-V. minikube driver -- {{.driver}}", out.V{"driver": host.Driver.DriverName()}) } out.T(out.DeletingHost, `Deleting "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": cfg.GetMachineName(), "driver_name": host.DriverName}) diff --git a/pkg/minikube/drivers/hyperv/driver.go b/pkg/minikube/drivers/hyperv/driver.go index 00b754335135..8070737a3c16 100644 --- a/pkg/minikube/drivers/hyperv/driver.go +++ b/pkg/minikube/drivers/hyperv/driver.go @@ -28,7 +28,7 @@ import ( ) func init() { - registry.Register(registry.DriverDef{ + _ = registry.Register(registry.DriverDef{ Name: constants.DriverHyperv, Builtin: true, ConfigCreator: createHypervHost, @@ -45,7 +45,7 @@ func createHypervHost(config cfg.MachineConfig) interface{} { d.VSwitch = config.HypervVirtualSwitch d.MemSize = config.Memory d.CPU = config.CPUs - d.DiskSize = int(config.DiskSize) + d.DiskSize = config.DiskSize d.SSHUser = "docker" d.DisableDynamicMemory = true // default to disable dynamic memory as minikube is unlikely to work properly with dynamic memory diff --git a/pkg/minikube/tunnel/route_windows.go b/pkg/minikube/tunnel/route_windows.go index 757074f190d3..0d561b3c1cd9 100644 --- a/pkg/minikube/tunnel/route_windows.go +++ b/pkg/minikube/tunnel/route_windows.go @@ -93,7 +93,7 @@ func (router *osRouter) parseTable(table []byte) routingTable { }, line: line, } - glog.V(4).Infof("adding line %s", tableLine) + glog.V(4).Infof("adding line %v", tableLine) t = append(t, tableLine) } } diff --git a/site/content/en/docs/Reference/Commands/delete.md b/site/content/en/docs/Reference/Commands/delete.md index db3e2f71252b..eabf82953af3 100644 --- a/site/content/en/docs/Reference/Commands/delete.md +++ b/site/content/en/docs/Reference/Commands/delete.md @@ -18,6 +18,30 @@ associated files. minikube delete [flags] ``` +##### Delete all profiles +``` +minikube delete --all +``` + +##### Delete profile & `.minikube` directory +Do note that the following command only works if you have only 1 profile. If there are multiple profiles, the command will error out. +``` +minikube delete --purge +``` + +##### Delete all profiles & `.minikube` directory +This will delete all the profiles and `.minikube` directory. +``` +minikube delete --purge --all +``` + +### Flags + +``` + --all: Set flag to delete all profiles + --purge: Set this flag to delete the '.minikube' folder from your user directory. +``` + ### Options inherited from parent commands ```