Merge pull request #7068 from vikkyomkar/issue-7067
Add --vm flag for users who want to autoselect only VM'spull/7235/head^2
commit
5a316b3bf9
|
@ -200,6 +200,7 @@ func initDriverFlags() {
|
|||
startCmd.Flags().String("driver", "", fmt.Sprintf("Driver is one of: %v (defaults to auto-detect)", driver.DisplaySupportedDrivers()))
|
||||
startCmd.Flags().String("vm-driver", "", "DEPRECATED, use `driver` instead.")
|
||||
startCmd.Flags().Bool(disableDriverMounts, false, "Disables the filesystem mounts provided by the hypervisors")
|
||||
startCmd.Flags().Bool("vm", false, "Filter to use only VM Drivers")
|
||||
|
||||
// kvm2
|
||||
startCmd.Flags().String(kvmNetwork, "default", "The KVM network name. (kvm2 driver only)")
|
||||
|
@ -507,7 +508,7 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState {
|
|||
return ds
|
||||
}
|
||||
|
||||
pick, alts := driver.Suggest(driver.Choices())
|
||||
pick, alts := driver.Suggest(driver.Choices(viper.GetBool("vm")))
|
||||
if pick.Name == "" {
|
||||
exit.WithCodeT(exit.Config, "Unable to determine a default driver to use. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/")
|
||||
}
|
||||
|
|
|
@ -164,8 +164,8 @@ func FlagDefaults(name string) FlagHints {
|
|||
}
|
||||
|
||||
// Choices returns a list of drivers which are possible on this system
|
||||
func Choices() []registry.DriverState {
|
||||
options := registry.Available()
|
||||
func Choices(vm bool) []registry.DriverState {
|
||||
options := registry.Available(vm)
|
||||
|
||||
// Descending priority for predictability and appearance
|
||||
sort.Slice(options, func(i, j int) bool {
|
||||
|
|
|
@ -162,7 +162,7 @@ func TestSuggest(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
got := Choices()
|
||||
got := Choices(false)
|
||||
gotNames := []string{}
|
||||
for _, c := range got {
|
||||
gotNames = append(gotNames, c.Name)
|
||||
|
|
|
@ -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