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 1 commit
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
Next Next commit
Added flags to purge configuration
  • Loading branch information
blueelvis committed Oct 6, 2019
commit 0945ed881bcdbe05f02290f9001c4655a114768c
54 changes: 46 additions & 8 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@ limitations under the License.
package cmd

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

"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"
"io/ioutil"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/cluster"
pkg_config "k8s.io/minikube/pkg/minikube/config"
Expand All @@ -40,6 +36,15 @@ import (
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"os"
"path/filepath"
"strconv"
"strings"
)

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

// deleteCmd represents the delete command
Expand All @@ -51,6 +56,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.")

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 +121,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()})
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