Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip driver autodetection if driver is already set #6503

Merged
merged 3 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/cluster/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions pkg/minikube/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/registry/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package registry

import (
"fmt"
"os"
"sort"

Expand All @@ -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
}

Expand Down