Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorts the outputs and also prints out alternative driver info when no driver is picked. #10394

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = fmt.Sprintf("Not selected: %s must be specified explicitly using --driver", ds.Name)
} else {
ds.Rejection = fmt.Sprintf("%s is preferred", pick.Name)
}
alternates = append(alternates, ds)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/minikube/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestSuggest(t *testing.T) {
{
def: registry.DriverDef{
Name: "unhealthy",
Priority: registry.Default,
Priority: registry.Deprecated,
Status: func() registry.State { return registry.State{Installed: true, Healthy: false} },
},
choices: []string{"unhealthy"},
Expand All @@ -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{"default", "unhealthy", "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", "default", "unhealthy", "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
8 changes: 4 additions & 4 deletions pkg/minikube/registry/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestGlobalAvailable(t *testing.T) {

bar := DriverDef{
Name: "healthy-bar",
Priority: Default,
Priority: Preferred,
Status: func() State { return State{Healthy: true} },
}
if err := Register(bar); err != nil {
Expand All @@ -82,7 +82,7 @@ func TestGlobalAvailable(t *testing.T) {

foo := DriverDef{
Name: "unhealthy-foo",
Priority: Default,
Priority: Fallback,
Status: func() State { return State{Healthy: false} },
}
if err := Register(foo); err != nil {
Expand All @@ -92,12 +92,12 @@ func TestGlobalAvailable(t *testing.T) {
expected := []DriverState{
{
Name: "healthy-bar",
Priority: Default,
Priority: Preferred,
State: State{Healthy: true},
},
{
Name: "unhealthy-foo",
Priority: Unhealthy,
Priority: Fallback,
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