Skip to content

Commit

Permalink
Sorts the outputs and prints out alternative driver info when no driv…
Browse files Browse the repository at this point in the history
…er is picked.
  • Loading branch information
lxzhang000 committed Feb 7, 2021
1 parent bdd1e6d commit 8620ab6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
7 changes: 6 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/user"
"regexp"
"runtime"
"sort"
"strings"

"github.com/blang/semver"
Expand Down Expand Up @@ -593,7 +594,11 @@ func selectDriver(existing *config.ClusterConfig) (registry.DriverState, []regis
pick, alts, rejects := driver.Suggest(choices)
if pick.Name == "" {
out.Step(style.ThumbsDown, "Unable to pick a default driver. Here is what was considered, in preference order:")
for _, r := range rejects {
altsAndRejects := append(alts, rejects...)
sort.Slice(altsAndRejects, func(i, j int) bool {
return altsAndRejects[i].Priority > altsAndRejects[j].Priority
})
for _, r := range altsAndRejects {
out.Infof("{{ .name }}: {{ .rejection }}", out.V{"name": r.Name, "rejection": r.Rejection})
}
exit.Message(reason.DrvNotDetected, "No possible driver was detected. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/")
Expand Down
6 changes: 5 additions & 1 deletion pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ func Suggest(options []registry.DriverState) (registry.DriverState, []registry.D
continue
}

ds.Rejection = fmt.Sprintf("%s is preferred", pick.Name)
if pick.Name == "" {
ds.Rejection = "Rejected due to low priority"
} else {
ds.Rejection = fmt.Sprintf("%s is preferred", pick.Name)
}
alternates = append(alternates, ds)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/minikube/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestSuggest(t *testing.T) {
Priority: registry.Discouraged,
Status: func() registry.State { return registry.State{Installed: true, Healthy: true} },
},
choices: []string{"discouraged", "unhealthy"},
choices: []string{"unhealthy", "discouraged"},
pick: "",
alts: []string{"discouraged"},
rejects: []string{"unhealthy"},
Expand All @@ -144,7 +144,7 @@ func TestSuggest(t *testing.T) {
Priority: registry.Default,
Status: func() registry.State { return registry.State{Installed: true, Healthy: true} },
},
choices: []string{"default", "discouraged", "unhealthy"},
choices: []string{"unhealthy", "default", "discouraged"},
pick: "default",
alts: []string{"discouraged"},
rejects: []string{"unhealthy"},
Expand All @@ -155,7 +155,7 @@ func TestSuggest(t *testing.T) {
Priority: registry.Preferred,
Status: func() registry.State { return registry.State{Installed: true, Healthy: true} },
},
choices: []string{"preferred", "default", "discouraged", "unhealthy"},
choices: []string{"preferred", "unhealthy", "default", "discouraged"},
pick: "preferred",
alts: []string{"default", "discouraged"},
rejects: []string{"unhealthy"},
Expand Down
4 changes: 0 additions & 4 deletions pkg/minikube/registry/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func Available(vm bool) []DriverState {
klog.Infof("%s priority: %d, state: %+v", d.Name, d.Priority, s)

priority := d.Priority
if !s.Healthy {
priority = Unhealthy
}

if vm {
if IsVM(d.Name) {
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/registry/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestGlobalAvailable(t *testing.T) {
},
{
Name: "unhealthy-foo",
Priority: Unhealthy,
Priority: Default,
State: State{Healthy: false},
},
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/minikube/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const (
Unknown Priority = iota
// Obsolete is when a driver has been removed
Obsolete
// Unhealthy is when a driver does not pass health checks
Unhealthy
// Experimental is when a driver is not officially supported because it's still experimental
Experimental
// Discouraged is when a driver has caveats that preclude it's recommendation
Expand Down

0 comments on commit 8620ab6

Please sign in to comment.