Skip to content

Commit

Permalink
Merge pull request #11355 from afbjorklund/driver-order
Browse files Browse the repository at this point in the history
Sort rejected drivers by their preference order
  • Loading branch information
medyagh authored May 18, 2021
2 parents cd73e83 + 610883b commit e05cad7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
10 changes: 10 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"os/user"
"regexp"
"runtime"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -589,7 +590,16 @@ 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:")
sort.Slice(rejects, func(i, j int) bool {
if rejects[i].Priority == rejects[j].Priority {
return rejects[i].Preference > rejects[j].Preference
}
return rejects[i].Priority > rejects[j].Priority
})
for _, r := range rejects {
if !r.Default {
continue
}
out.Infof("{{ .name }}: {{ .rejection }}", out.V{"name": r.Name, "rejection": r.Rejection})
if r.Suggestion != "" {
out.Infof("{{ .name }}: Suggestion: {{ .suggestion}}", out.V{"name": r.Name, "suggestion": r.Suggestion})
Expand Down
17 changes: 12 additions & 5 deletions pkg/minikube/registry/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ var (

// DriverState is metadata relating to a driver and status
type DriverState struct {
Name string
Default bool
// Name is the name of the driver used internally
Name string
// Default drivers are selected automatically
Default bool
// Preference is the original priority from driver
Preference Priority
// Priority is the effective priority with health
Priority Priority
State State
// State is the state of driver and dependencies
State State
// Rejection is why we chose not to use this driver
Rejection string
// Suggestion is how the user could improve health
Expand Down Expand Up @@ -112,17 +118,18 @@ func Available(vm bool) []DriverState {
s := d.Status()
klog.Infof("%s default: %v priority: %d, state: %+v", d.Name, d.Default, d.Priority, s)

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

if vm {
if IsVM(d.Name) {
sts = append(sts, DriverState{Name: d.Name, Default: d.Default, Priority: priority, State: s})
sts = append(sts, DriverState{Name: d.Name, Default: d.Default, Preference: preference, Priority: priority, State: s})
}
} else {
sts = append(sts, DriverState{Name: d.Name, Default: d.Default, Priority: priority, State: s})
sts = append(sts, DriverState{Name: d.Name, Default: d.Default, Preference: preference, Priority: priority, State: s})
}
}

Expand Down
18 changes: 10 additions & 8 deletions pkg/minikube/registry/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ func TestGlobalAvailable(t *testing.T) {

expected := []DriverState{
{
Name: "healthy-bar",
Default: true,
Priority: Default,
State: State{Healthy: true},
Name: "healthy-bar",
Default: true,
Preference: Default,
Priority: Default,
State: State{Healthy: true},
},
{
Name: "unhealthy-foo",
Default: true,
Priority: Unhealthy,
State: State{Healthy: false},
Name: "unhealthy-foo",
Default: true,
Preference: Default,
Priority: Unhealthy,
State: State{Healthy: false},
},
}

Expand Down

0 comments on commit e05cad7

Please sign in to comment.