Skip to content

Commit d5490a8

Browse files
author
Priya Wadhwa
committed
Move driver validation before driver selection
If a user passes in a driver via --vm-driver or --driver, then we should make sure it matches the preexisting cluster (if one exists) before we try and get information about the driver. This avoids confusing logs where we tell the user we're using the preexisting driver but then error out because they specified a different driver.
1 parent 07e8420 commit d5490a8

File tree

1 file changed

+49
-39
lines changed

1 file changed

+49
-39
lines changed

cmd/minikube/cmd/start.go

+49-39
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func runStart(cmd *cobra.Command, args []string) {
294294
exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err})
295295
}
296296

297+
validateSpecifiedDriver(existing)
297298
ds := selectDriver(existing)
298299
driverName := ds.Name
299300
glog.Infof("selected driver: %s", driverName)
@@ -482,36 +483,20 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState {
482483
return pick
483484
}
484485

485-
// validateDriver validates that the selected driver appears sane, exits if not
486-
func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) {
487-
name := ds.Name
488-
glog.Infof("validating driver %q against %+v", name, existing)
489-
if !driver.Supported(name) {
490-
exit.WithCodeT(exit.Unavailable, "The driver {{.experimental}} '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS})
486+
// validateSpecifiedDriver makes sure that if a user has passed in a driver
487+
// it matches the existing cluster if there is one
488+
func validateSpecifiedDriver(existing *config.ClusterConfig) {
489+
if existing == nil {
490+
return
491491
}
492-
493-
st := ds.State
494-
glog.Infof("status for %s: %+v", name, st)
495-
496-
if st.Error != nil {
497-
out.ErrLn("")
498-
499-
out.WarningT("'{{.driver}}' driver reported an issue: {{.error}}", out.V{"driver": name, "error": st.Error})
500-
out.ErrT(out.Tip, "Suggestion: {{.fix}}", out.V{"fix": translate.T(st.Fix)})
501-
if st.Doc != "" {
502-
out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": st.Doc})
503-
}
504-
out.ErrLn("")
505-
506-
if !st.Installed && !viper.GetBool(force) {
507-
if existing != nil && name == existing.Driver {
508-
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})
509-
}
510-
exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed", out.V{"driver": name})
511-
}
492+
old := existing.Driver
493+
var requested string
494+
if d := viper.GetString("driver"); d != "" {
495+
requested = d
496+
} else if d := viper.GetString("vm-driver"); d != "" {
497+
requested = d
512498
}
513-
514-
if existing == nil {
499+
if old == requested {
515500
return
516501
}
517502

@@ -525,33 +510,58 @@ func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) {
525510
if err != nil {
526511
exit.WithError("Error getting primary cp", err)
527512
}
528-
529513
machineName := driver.MachineName(*existing, cp)
530514
h, err := api.Load(machineName)
531515
if err != nil {
532516
glog.Warningf("selectDriver api.Load: %v", err)
533517
return
534518
}
535519

536-
if h.Driver.DriverName() == name {
537-
return
538-
}
539-
540-
out.ErrT(out.Conflict, `The existing "{{.profile_name}}" VM that was created using the "{{.old_driver}}" driver, and is incompatible with the "{{.driver}}" driver.`,
541-
out.V{"profile_name": machineName, "driver": name, "old_driver": h.Driver.DriverName()})
520+
out.ErrT(out.Conflict, `The existing "{{.profile_name}}" VM was created using the "{{.old_driver}}" driver, and is incompatible with the "{{.driver}}" driver.`,
521+
out.V{"profile_name": machineName, "driver": requested, "old_driver": h.Driver.DriverName()})
542522

543523
out.ErrT(out.Workaround, `To proceed, either:
544524
545-
1) Delete the existing "{{.profile_name}}" cluster using: '{{.command}} delete'
525+
1) Delete the existing "{{.profile_name}}" cluster using: '{{.command}} delete'
546526
547-
* or *
527+
* or *
548528
549-
2) Start the existing "{{.profile_name}}" cluster using: '{{.command}} start --driver={{.old_driver}}'
550-
`, out.V{"command": minikubeCmd(), "old_driver": h.Driver.DriverName(), "profile_name": machineName})
529+
2) Start the existing "{{.profile_name}}" cluster using: '{{.command}} start --driver={{.old_driver}}'
530+
`, out.V{"command": minikubeCmd(), "old_driver": h.Driver.DriverName(), "profile_name": machineName})
551531

552532
exit.WithCodeT(exit.Config, "Exiting.")
553533
}
554534

535+
// validateDriver validates that the selected driver appears sane, exits if not
536+
func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) {
537+
name := ds.Name
538+
glog.Infof("validating driver %q against %+v", name, existing)
539+
if !driver.Supported(name) {
540+
exit.WithCodeT(exit.Unavailable, "The driver {{.experimental}} '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS})
541+
}
542+
543+
st := ds.State
544+
glog.Infof("status for %s: %+v", name, st)
545+
546+
if st.Error != nil {
547+
out.ErrLn("")
548+
549+
out.WarningT("'{{.driver}}' driver reported an issue: {{.error}}", out.V{"driver": name, "error": st.Error})
550+
out.ErrT(out.Tip, "Suggestion: {{.fix}}", out.V{"fix": translate.T(st.Fix)})
551+
if st.Doc != "" {
552+
out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": st.Doc})
553+
}
554+
out.ErrLn("")
555+
556+
if !st.Installed && !viper.GetBool(force) {
557+
if existing != nil && name == existing.Driver {
558+
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})
559+
}
560+
exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed", out.V{"driver": name})
561+
}
562+
}
563+
}
564+
555565
func selectImageRepository(mirrorCountry string, v semver.Version) (bool, string, error) {
556566
var tryCountries []string
557567
var fallback string

0 commit comments

Comments
 (0)