updated as per suggestion
parent
37b23cfd6d
commit
6ee7e6fa67
|
|
@ -165,22 +165,13 @@ func FlagDefaults(name string) FlagHints {
|
|||
|
||||
// Choices returns a list of drivers which are possible on this system
|
||||
func Choices(vm bool) []registry.DriverState {
|
||||
var drivers []registry.DriverState
|
||||
options := registry.Available()
|
||||
if vm {
|
||||
for _, ds := range options {
|
||||
if IsVM(ds.Name) {
|
||||
drivers = append(drivers, ds)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
drivers = options
|
||||
}
|
||||
options := registry.Available(vm)
|
||||
|
||||
// Descending priority for predictability and appearance
|
||||
sort.Slice(options, func(i, j int) bool {
|
||||
return options[i].Priority > options[j].Priority
|
||||
})
|
||||
return drivers
|
||||
return options
|
||||
}
|
||||
|
||||
// Suggest returns a suggested driver from a set of options
|
||||
|
|
|
|||
|
|
@ -24,6 +24,40 @@ import (
|
|||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
const (
|
||||
// Podman is Kubernetes in container using podman driver
|
||||
Podman = "podman"
|
||||
// Docker is Kubernetes in container using docker driver
|
||||
Docker = "docker"
|
||||
// Mock driver
|
||||
Mock = "mock"
|
||||
// None driver
|
||||
None = "none"
|
||||
)
|
||||
|
||||
// IsKIC checks if the driver is a kubernetes in container
|
||||
func IsKIC(name string) bool {
|
||||
return name == Docker || name == Podman
|
||||
}
|
||||
|
||||
// IsMock checks if the driver is a mock
|
||||
func IsMock(name string) bool {
|
||||
return name == Mock
|
||||
}
|
||||
|
||||
// IsVM checks if the driver is a VM
|
||||
func IsVM(name string) bool {
|
||||
if IsKIC(name) || IsMock(name) || BareMetal(name) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// BareMetal returns if this driver is unisolated
|
||||
func BareMetal(name string) bool {
|
||||
return name == None || name == Mock
|
||||
}
|
||||
|
||||
var (
|
||||
// globalRegistry is a globally accessible driver registry
|
||||
globalRegistry = newRegistry()
|
||||
|
|
@ -59,7 +93,7 @@ func Driver(name string) DriverDef {
|
|||
}
|
||||
|
||||
// Available returns a list of available drivers in the global registry
|
||||
func Available() []DriverState {
|
||||
func Available(vm bool) []DriverState {
|
||||
sts := []DriverState{}
|
||||
glog.Infof("Querying for installed drivers using PATH=%s", os.Getenv("PATH"))
|
||||
|
||||
|
|
@ -76,7 +110,13 @@ func Available() []DriverState {
|
|||
priority = Unhealthy
|
||||
}
|
||||
|
||||
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
|
||||
if vm {
|
||||
if IsVM(d.Name) {
|
||||
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
|
||||
}
|
||||
} else {
|
||||
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
|
||||
}
|
||||
}
|
||||
|
||||
// Descending priority for predictability
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ func TestGlobalAvailable(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(Available(), expected); diff != "" {
|
||||
if diff := cmp.Diff(Available(false), expected); diff != "" {
|
||||
t.Errorf("available mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue