Merge pull request #6503 from tstromberg/faster-dryrun
Skip driver autodetection if driver is already setpull/6511/head
commit
2ecc120b2b
|
@ -299,9 +299,10 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err})
|
||||
}
|
||||
|
||||
driverName := selectDriver(existing)
|
||||
ds := selectDriver(existing)
|
||||
driverName := ds.Name
|
||||
glog.Infof("selected driver: %s", driverName)
|
||||
validateDriver(driverName, existing)
|
||||
validateDriver(ds, existing)
|
||||
err = autoSetDriverOptions(cmd, driverName)
|
||||
if err != nil {
|
||||
glog.Errorf("Error autoSetOptions : %v", err)
|
||||
|
@ -567,53 +568,49 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st
|
|||
return nil
|
||||
}
|
||||
|
||||
func selectDriver(existing *config.MachineConfig) string {
|
||||
name := viper.GetString("vm-driver")
|
||||
glog.Infof("selectDriver: flag=%q, old=%v", name, existing)
|
||||
|
||||
func selectDriver(existing *config.MachineConfig) registry.DriverState {
|
||||
// Technically unrelated, but important to perform before detection
|
||||
driver.SetLibvirtURI(viper.GetString(kvmQemuURI))
|
||||
options := driver.Choices()
|
||||
pick, alts := driver.Choose(name, options)
|
||||
exp := ""
|
||||
if pick.Priority == registry.Experimental {
|
||||
exp = "experimental "
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
out.T(out.Sparkle, `Selecting {{.experimental}}'{{.driver}}' driver from user configuration (alternates: {{.alternates}})`, out.V{"experimental": exp, "driver": name, "alternates": alts})
|
||||
return name
|
||||
if viper.GetString("vm-driver") != "" {
|
||||
ds := driver.Status(viper.GetString("vm-driver"))
|
||||
out.T(out.Sparkle, `Using the {{.driver}} driver based on user configuration`, out.V{"driver": ds.String()})
|
||||
return ds
|
||||
}
|
||||
|
||||
// By default, the driver is whatever we used last time
|
||||
if existing != nil {
|
||||
pick, alts := driver.Choose(existing.VMDriver, options)
|
||||
if pick.Priority == registry.Experimental {
|
||||
exp = "experimental "
|
||||
}
|
||||
out.T(out.Sparkle, `Selecting {{.experimental}}'{{.driver}}' driver from existing profile (alternates: {{.alternates}})`, out.V{"experimental": exp, "driver": existing.VMDriver, "alternates": alts})
|
||||
return pick.Name
|
||||
}
|
||||
|
||||
if len(options) > 1 {
|
||||
out.T(out.Sparkle, `Automatically selected the {{.experimental}}'{{.driver}}' driver (alternates: {{.alternates}})`, out.V{"experimental": exp, "driver": pick.Name, "alternates": alts})
|
||||
} else {
|
||||
out.T(out.Sparkle, `Automatically selected the {{.experimental}}'{{.driver}}' driver`, out.V{"experimental": exp, "driver": pick.Name})
|
||||
if existing != nil && existing.VMDriver != "" {
|
||||
ds := driver.Status(existing.VMDriver)
|
||||
out.T(out.Sparkle, `Using the {{.driver}} driver based on existing profile`, out.V{"driver": ds.String()})
|
||||
return ds
|
||||
}
|
||||
|
||||
pick, alts := driver.Suggest(driver.Choices())
|
||||
if pick.Name == "" {
|
||||
exit.WithCodeT(exit.Config, "Unable to determine a default driver to use. Try specifying --vm-driver, or see https://minikube.sigs.k8s.io/docs/start/")
|
||||
}
|
||||
return pick.Name
|
||||
|
||||
if len(alts) > 1 {
|
||||
altNames := []string{}
|
||||
for _, a := range alts {
|
||||
altNames = append(altNames, a.String())
|
||||
}
|
||||
out.T(out.Sparkle, `Automatically selected the {{.driver}} driver. Other choices: {{.alternates}}`, out.V{"driver": pick.Name, "alternates": strings.Join(altNames, ", ")})
|
||||
} else {
|
||||
out.T(out.Sparkle, `Automatically selected the {{.driver}} driver`, out.V{"driver": pick.String()})
|
||||
}
|
||||
return pick
|
||||
}
|
||||
|
||||
// validateDriver validates that the selected driver appears sane, exits if not
|
||||
func validateDriver(name string, existing *config.MachineConfig) {
|
||||
func validateDriver(ds registry.DriverState, existing *config.MachineConfig) {
|
||||
name := ds.Name
|
||||
glog.Infof("validating driver %q against %+v", name, existing)
|
||||
if !driver.Supported(name) {
|
||||
exit.WithCodeT(exit.Unavailable, "The driver {{.experimental}} '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS})
|
||||
}
|
||||
|
||||
st := driver.Status(name)
|
||||
st := ds.State
|
||||
glog.Infof("status for %s: %+v", name, st)
|
||||
|
||||
if st.Error != nil {
|
||||
|
|
|
@ -186,9 +186,9 @@ func commandRunner(h *host.Host) (command.Runner, error) {
|
|||
return &command.FakeCommandRunner{}, nil
|
||||
}
|
||||
|
||||
if driver.BareMetal(h.Driver.DriverName()) {
|
||||
if driver.BareMetal(h.Driver.DriverName()) {
|
||||
glog.Infof("returning ExecRunner for %q driver", d)
|
||||
return command.NewExecRunner(), nil
|
||||
return command.NewExecRunner(), nil
|
||||
}
|
||||
if driver.IsKIC(d) {
|
||||
glog.Infof("Returning KICRunner for %q driver", d)
|
||||
|
|
|
@ -147,17 +147,10 @@ func Choices() []registry.DriverState {
|
|||
return options
|
||||
}
|
||||
|
||||
// Choose returns a suggested driver from a set of options
|
||||
func Choose(requested string, options []registry.DriverState) (registry.DriverState, []registry.DriverState) {
|
||||
glog.Infof("requested: %q", requested)
|
||||
// Suggest returns a suggested driver from a set of options
|
||||
func Suggest(options []registry.DriverState) (registry.DriverState, []registry.DriverState) {
|
||||
pick := registry.DriverState{}
|
||||
for _, ds := range options {
|
||||
if ds.Name == requested {
|
||||
glog.Infof("choosing %q because it was requested", ds.Name)
|
||||
pick = ds
|
||||
continue
|
||||
}
|
||||
|
||||
if !ds.State.Installed {
|
||||
continue
|
||||
}
|
||||
|
@ -192,8 +185,13 @@ func Choose(requested string, options []registry.DriverState) (registry.DriverSt
|
|||
}
|
||||
|
||||
// Status returns the status of a driver
|
||||
func Status(name string) registry.State {
|
||||
return registry.Status(name)
|
||||
func Status(name string) registry.DriverState {
|
||||
d := registry.Driver(name)
|
||||
return registry.DriverState{
|
||||
Name: d.Name,
|
||||
Priority: d.Priority,
|
||||
State: registry.Status(name),
|
||||
}
|
||||
}
|
||||
|
||||
// SetLibvirtURI sets the URI to perform libvirt health checks against
|
||||
|
|
|
@ -80,14 +80,13 @@ func TestFlagDefaults(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestChoices(t *testing.T) {
|
||||
func TestSuggest(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
def registry.DriverDef
|
||||
choices []string
|
||||
pick string
|
||||
alts []string
|
||||
requested string
|
||||
def registry.DriverDef
|
||||
choices []string
|
||||
pick string
|
||||
alts []string
|
||||
}{
|
||||
{
|
||||
def: registry.DriverDef{
|
||||
|
@ -129,12 +128,6 @@ func TestChoices(t *testing.T) {
|
|||
pick: "preferred",
|
||||
alts: []string{"default", "discouraged"},
|
||||
},
|
||||
{
|
||||
requested: "unhealthy",
|
||||
choices: []string{"preferred", "default", "discouraged", "unhealthy"},
|
||||
pick: "unhealthy",
|
||||
alts: []string{"preferred", "default", "discouraged"},
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.def.Name, func(t *testing.T) {
|
||||
|
@ -154,7 +147,7 @@ func TestChoices(t *testing.T) {
|
|||
t.Errorf("choices mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
|
||||
pick, alts := Choose(tc.requested, got)
|
||||
pick, alts := Suggest(got)
|
||||
if pick.Name != tc.pick {
|
||||
t.Errorf("pick = %q, expected %q", pick.Name, tc.pick)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
|
@ -36,6 +37,9 @@ type DriverState struct {
|
|||
}
|
||||
|
||||
func (d DriverState) String() string {
|
||||
if d.Priority == Experimental {
|
||||
return fmt.Sprintf("%s (experimental)", d.Name)
|
||||
}
|
||||
return d.Name
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue