diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index 204ed14b97..7e3e1836b0 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -320,14 +320,45 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command. } // startHost starts a new minikube host using a VM or None -func startHost(api libmachine.API, mc config.ClusterConfig, n config.Node) (*host.Host, bool) { - host, exists, err := machine.StartHost(api, mc, n) - if err != nil { - exit.WithError("Unable to start VM. Please investigate and run 'minikube delete' if possible", err) +func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.Host, bool) { + host, exists, err := machine.StartHost(api, cc, n) + if err == nil { + return host, exists } + out.T(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err}) + + // NOTE: People get very cranky if you delete their prexisting VM. Only delete new ones. + if !exists { + err := machine.DeleteHost(api, driver.MachineName(cc, n)) + if err != nil { + glog.Warningf("delete host: %v", err) + } + } + + // Try again, but just once to avoid copious error messages + time.Sleep(5 * time.Second) + + host, exists, err = machine.StartHost(api, cc, n) + if err == nil { + return host, exists + } + + out.T(out.FailureType, "StartHost failed again: {{.error}}", out.V{"error": err}) + out.T(out.Workaround, `Run: "{{.cmd}} delete", then "{{.cmd}} start --alsologtostderr -v=1" to try again with more logs`, + out.V{"cmd": minikubeCmd()}) + + exit.WithError("Unable to start VM after repeated tries. Please try {{'minikube delete' if possible", err) return host, exists } +// Return a minikube command containing the current profile name +func minikubeCmd() string { + if viper.GetString(config.ProfileName) != constants.DefaultClusterName { + return fmt.Sprintf("minikube -p %s", config.ProfileName) + } + return "minikube" +} + // validateNetwork tries to catch network problems as soon as possible func validateNetwork(h *host.Host, r command.Runner) string { ip, err := h.Driver.GetIP()