diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 9fc519595016..7357530ff36f 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -294,6 +294,7 @@ func runStart(cmd *cobra.Command, args []string) { exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err}) } + validateSpecifiedDriver(existing) ds := selectDriver(existing) driverName := ds.Name glog.Infof("selected driver: %s", driverName) @@ -482,36 +483,20 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState { return pick } -// validateDriver validates that the selected driver appears sane, exits if not -func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) { - name := ds.Name - glog.Infof("validating driver %q against %+v", name, existing) - if !driver.Supported(name) { - exit.WithCodeT(exit.Unavailable, "The driver {{.experimental}} '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS}) +// validateSpecifiedDriver makes sure that if a user has passed in a driver +// it matches the existing cluster if there is one +func validateSpecifiedDriver(existing *config.ClusterConfig) { + if existing == nil { + return } - - st := ds.State - glog.Infof("status for %s: %+v", name, st) - - if st.Error != nil { - out.ErrLn("") - - out.WarningT("'{{.driver}}' driver reported an issue: {{.error}}", out.V{"driver": name, "error": st.Error}) - out.ErrT(out.Tip, "Suggestion: {{.fix}}", out.V{"fix": translate.T(st.Fix)}) - if st.Doc != "" { - out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": st.Doc}) - } - out.ErrLn("") - - if !st.Installed && !viper.GetBool(force) { - if existing != nil && name == existing.Driver { - exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed, but is specified by an existing profile. Please run 'minikube delete' or install {{.driver}}", out.V{"driver": name}) - } - exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed", out.V{"driver": name}) - } + old := existing.Driver + var requested string + if d := viper.GetString("driver"); d != "" { + requested = d + } else if d := viper.GetString("vm-driver"); d != "" { + requested = d } - - if existing == nil { + if old == requested { return } @@ -525,7 +510,6 @@ func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) { if err != nil { exit.WithError("Error getting primary cp", err) } - machineName := driver.MachineName(*existing, cp) h, err := api.Load(machineName) if err != nil { @@ -533,25 +517,51 @@ func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) { return } - if h.Driver.DriverName() == name { - return - } - - out.ErrT(out.Conflict, `The existing "{{.profile_name}}" VM that was created using the "{{.old_driver}}" driver, and is incompatible with the "{{.driver}}" driver.`, - out.V{"profile_name": machineName, "driver": name, "old_driver": h.Driver.DriverName()}) + out.ErrT(out.Conflict, `The existing "{{.profile_name}}" VM was created using the "{{.old_driver}}" driver, and is incompatible with the "{{.driver}}" driver.`, + out.V{"profile_name": machineName, "driver": requested, "old_driver": h.Driver.DriverName()}) out.ErrT(out.Workaround, `To proceed, either: - 1) Delete the existing "{{.profile_name}}" cluster using: '{{.command}} delete' +1) Delete the existing "{{.profile_name}}" cluster using: '{{.command}} delete' - * or * +* or * - 2) Start the existing "{{.profile_name}}" cluster using: '{{.command}} start --driver={{.old_driver}}' - `, out.V{"command": minikubeCmd(), "old_driver": h.Driver.DriverName(), "profile_name": machineName}) +2) Start the existing "{{.profile_name}}" cluster using: '{{.command}} start --driver={{.old_driver}}' +`, out.V{"command": minikubeCmd(), "old_driver": h.Driver.DriverName(), "profile_name": machineName}) exit.WithCodeT(exit.Config, "Exiting.") } +// validateDriver validates that the selected driver appears sane, exits if not +func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) { + name := ds.Name + glog.Infof("validating driver %q against %+v", name, existing) + if !driver.Supported(name) { + exit.WithCodeT(exit.Unavailable, "The driver {{.experimental}} '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS}) + } + + st := ds.State + glog.Infof("status for %s: %+v", name, st) + + if st.Error != nil { + out.ErrLn("") + + out.WarningT("'{{.driver}}' driver reported an issue: {{.error}}", out.V{"driver": name, "error": st.Error}) + out.ErrT(out.Tip, "Suggestion: {{.fix}}", out.V{"fix": translate.T(st.Fix)}) + if st.Doc != "" { + out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": st.Doc}) + } + out.ErrLn("") + + if !st.Installed && !viper.GetBool(force) { + if existing != nil && name == existing.Driver { + exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed, but is specified by an existing profile. Please run 'minikube delete' or install {{.driver}}", out.V{"driver": name}) + } + exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed", out.V{"driver": name}) + } + } +} + func selectImageRepository(mirrorCountry string, v semver.Version) (bool, string, error) { var tryCountries []string var fallback string