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

Added flags to purge configuration with minikube delete #5548

Merged
merged 6 commits into from
Oct 21, 2019
Merged
Changes from 2 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
45 changes: 42 additions & 3 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ limitations under the License.
package cmd

import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/docker/machine/libmachine"
"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"
"github.com/spf13/cobra"
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
Expand All @@ -42,6 +43,11 @@ import (
"k8s.io/minikube/pkg/minikube/out"
)

const (
purge = "purge"
noPrompt = "no-prompt"
)

// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Expand All @@ -51,6 +57,15 @@ associated files.`,
Run: runDelete,
}

func init() {
deleteCmd.Flags().Bool(purge, false, "Set this flag to delete the '.minikube' folder from your user directory. This will prompt for confirmation.")
deleteCmd.Flags().Bool(noPrompt, false, "Set this flag so that there are no prompts.")
blueelvis marked this conversation as resolved.
Show resolved Hide resolved

if err := viper.BindPFlags(deleteCmd.Flags()); err != nil {
exit.WithError("unable to bind flags", err)
}
}

// runDelete handles the executes the flow of "minikube delete"
func runDelete(cmd *cobra.Command, args []string) {
if len(args) > 0 {
Expand Down Expand Up @@ -107,6 +122,30 @@ func runDelete(cmd *cobra.Command, args []string) {
if err := cmdcfg.Unset(pkg_config.MachineProfile); err != nil {
exit.WithError("unset minikube profile", err)
}

// Delete the .minikube folder if the flags are set
if viper.GetBool(purge) {
blueelvis marked this conversation as resolved.
Show resolved Hide resolved
glog.Infof("Purging the '.minikube' directory located at %s", localpath.MiniPath())

if viper.GetBool(noPrompt) {
glog.Infof("Will not prompt for deletion.")
blueelvis marked this conversation as resolved.
Show resolved Hide resolved
} else {
out.T(out.Check, "Are you sure you want to delete the directory located at {{.minikubePath}}? This will delete all your configuration data related to minikube. (Y/N)", out.V{"minikubePath": localpath.MiniPath()})
blueelvis marked this conversation as resolved.
Show resolved Hide resolved
userInput := bufio.NewScanner(os.Stdin)
userInput.Scan()
var choice = userInput.Text()
if strings.ToLower(choice) != "y" {
out.T(out.Meh, "Not deleting minikube directory located at {{.minikubePath}}", out.V{"minikubePath": localpath.MiniPath()})
return
}
}
if err := os.RemoveAll(localpath.MiniPath()); err != nil {
exit.WithError("unable to delete minikube config folder", err)
}
out.T(out.Crushed, "Deleted the {{.minikubePath}} folder successfully!", out.V{"minikubePath": localpath.MiniPath()})
} else {
out.T(out.Meh, "Not deleting minikube directory located at {{.minikubePath}}", out.V{"minikubePath": localpath.MiniPath()})
}
}

func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsName string) {
Expand Down