Add --vm flag for users who want to autoselect only VM's

pull/7068/head
vikkyomkar 2020-03-17 13:21:05 +05:30
parent 82900a7811
commit e053e4f235
4 changed files with 23 additions and 12 deletions

View File

@ -194,6 +194,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)")
@ -465,7 +466,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/")
}

View File

@ -164,14 +164,27 @@ func FlagDefaults(name string) FlagHints {
}
// Choices returns a list of drivers which are possible on this system
func Choices() []registry.DriverState {
func Choices(vm bool) []registry.DriverState {
options := registry.Available()
// Descending priority for predictability and appearance
sort.Slice(options, func(i, j int) bool {
return options[i].Priority > options[j].Priority
})
return options
if vm {
var vmOptions []registry.DriverState
for _, ds := range options {
if IsVM(ds.Name) {
vmOptions = append(vmOptions,ds)
}
}
// Descending priority for predictability and appearance
sort.Slice(vmOptions, func(i, j int) bool {
return vmOptions[i].Priority > vmOptions[j].Priority
})
return vmOptions
}else {
// Descending priority for predictability and appearance
sort.Slice(options, func(i, j int) bool {
return options[i].Priority > options[j].Priority
})
return options
}
}
// Suggest returns a suggested driver from a set of options

View File

@ -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)

View File

@ -1,12 +1,9 @@
/*
Copyright 2018 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.