Keep original preference, for identical priority

Unhealthy drivers have their priority lowered
pull/11355/head
Anders F Björklund 2021-05-16 09:31:37 +02:00
parent dedfdfbfcf
commit 6d0763648e
3 changed files with 24 additions and 15 deletions

View File

@ -590,7 +590,12 @@ 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 { return rejects[i].Priority > rejects[j].Priority })
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

View File

@ -66,10 +66,11 @@ var (
// DriverState is metadata relating to a driver and status
type DriverState struct {
Name string
Default bool
Priority Priority
State State
Name string
Default bool
Preference Priority
Priority Priority
State State
// Rejection is why we chose not to use this driver
Rejection string
// Suggestion is how the user could improve health
@ -112,6 +113,7 @@ 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
@ -119,10 +121,10 @@ func Available(vm bool) []DriverState {
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})
}
}

View File

@ -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},
},
}