Skip to content

Commit

Permalink
Merge pull request #10554 from afbjorklund/drivers-default
Browse files Browse the repository at this point in the history
Don't select Discouraged or Obsolete by default
  • Loading branch information
priyawadhwa authored Feb 24, 2021
2 parents 2ef49ae + 4e4a599 commit 57d33de
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ func runStart(cmd *cobra.Command, args []string) {
success := false
// Walk down the rest of the options
for _, alt := range alts {
// Skip non-default drivers
if !ds.Default {
continue
}
out.WarningT("Startup with {{.old_driver}} driver failed, trying with alternate driver {{.new_driver}}: {{.error}}", out.V{"old_driver": ds.Name, "new_driver": alt.Name, "error": err})
ds = alt
// Delete the existing cluster and try again with the next driver on the list
Expand Down
6 changes: 6 additions & 0 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ func Suggest(options []registry.DriverState) (registry.DriverState, []registry.D
continue
}

if !ds.Default {
klog.Infof("not recommending %q due to default: %v", ds.Name, ds.Default)
continue
}

if ds.Priority <= registry.Discouraged {
klog.Infof("not recommending %q due to priority: %d", ds.Name, ds.Priority)
continue
Expand Down Expand Up @@ -296,6 +301,7 @@ func Status(name string) registry.DriverState {
d := registry.Driver(name)
return registry.DriverState{
Name: d.Name,
Default: d.Default,
Priority: d.Priority,
State: registry.Status(name),
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestSuggest(t *testing.T) {
{
def: registry.DriverDef{
Name: "unhealthy",
Default: true,
Priority: registry.Default,
Status: func() registry.State { return registry.State{Installed: true, Healthy: false} },
},
Expand All @@ -130,6 +131,7 @@ func TestSuggest(t *testing.T) {
{
def: registry.DriverDef{
Name: "discouraged",
Default: false,
Priority: registry.Discouraged,
Status: func() registry.State { return registry.State{Installed: true, Healthy: true} },
},
Expand All @@ -141,6 +143,7 @@ func TestSuggest(t *testing.T) {
{
def: registry.DriverDef{
Name: "default",
Default: true,
Priority: registry.Default,
Status: func() registry.State { return registry.State{Installed: true, Healthy: true} },
},
Expand All @@ -152,6 +155,7 @@ func TestSuggest(t *testing.T) {
{
def: registry.DriverDef{
Name: "preferred",
Default: true,
Priority: registry.Preferred,
Status: func() registry.State { return registry.State{Installed: true, Healthy: true} },
},
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func init() {
Config: configure,
Init: func() drivers.Driver { return kic.NewDriver(kic.Config{OCIBinary: oci.Docker}) },
Status: status,
Default: true,
Priority: registry.HighlyPreferred,
}); err != nil {
panic(fmt.Sprintf("register failed: %v", err))
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/hyperkit/hyperkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func init() {
Name: driver.HyperKit,
Config: configure,
Status: status,
Default: true,
Priority: registry.Preferred,
}); err != nil {
panic(fmt.Sprintf("register: %v", err))
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func init() {
Init: func() drivers.Driver { return hyperv.NewDriver("", "") },
Config: configure,
Status: status,
Default: true,
Priority: registry.Preferred,
}); err != nil {
panic(fmt.Sprintf("register: %v", err))
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/kvm2/kvm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func init() {
Alias: []string{driver.AliasKVM},
Config: configure,
Status: status,
Default: true,
Priority: registry.Preferred,
}); err != nil {
panic(fmt.Sprintf("register failed: %v", err))
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/registry/drvs/none/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func init() {
Config: configure,
Init: func() drivers.Driver { return none.NewDriver(none.Config{}) },
Status: status,
Priority: registry.Discouraged, // requires root
Default: false, // no isolation
Priority: registry.Discouraged,
}); err != nil {
panic(fmt.Sprintf("register failed: %v", err))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/parallels/parallels.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
Name: driver.Parallels,
Config: configure,
Status: status,
Default: true,
Priority: registry.Default,
Init: func() drivers.Driver { return parallels.NewDriver("", "") },
})
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func init() {
Config: configure,
Init: func() drivers.Driver { return kic.NewDriver(kic.Config{OCIBinary: oci.Podman}) },
Status: status,
Default: true,
Priority: priority,
}); err != nil {
panic(fmt.Sprintf("register failed: %v", err))
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/registry/drvs/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func init() {
Alias: []string{driver.AliasSSH},
Config: configure,
Status: status,
Priority: registry.Discouraged, // requires external VM
Default: false, // requires external VM
Priority: registry.Discouraged,
Init: func() drivers.Driver { return ssh.NewDriver(ssh.Config{}) },
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func init() {
Name: driver.VirtualBox,
Config: configure,
Status: status,
Default: true,
Priority: registry.Fallback,
Init: func() drivers.Driver { return virtualbox.NewDriver("", "") },
})
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/vmware/vmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
err := registry.Register(registry.DriverDef{
Name: driver.VMware,
Config: configure,
Default: true,
Priority: registry.Default,
Status: status,
})
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/vmwarefusion/vmwarefusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
if err := registry.Register(registry.DriverDef{
Name: driver.VMwareFusion,
Status: status,
Default: false, // see driver.VMware instead
Priority: registry.Obsolete,
}); err != nil {
panic(fmt.Sprintf("register: %v", err))
Expand Down
7 changes: 4 additions & 3 deletions pkg/minikube/registry/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
// DriverState is metadata relating to a driver and status
type DriverState struct {
Name string
Default bool
Priority Priority
State State
// Rejection is why we chose not to use this driver
Expand Down Expand Up @@ -107,7 +108,7 @@ func Available(vm bool) []DriverState {
continue
}
s := d.Status()
klog.Infof("%s priority: %d, state: %+v", d.Name, d.Priority, s)
klog.Infof("%s default: %v priority: %d, state: %+v", d.Name, d.Default, d.Priority, s)

priority := d.Priority
if !s.Healthy {
Expand All @@ -116,10 +117,10 @@ func Available(vm bool) []DriverState {

if vm {
if IsVM(d.Name) {
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
sts = append(sts, DriverState{Name: d.Name, Default: d.Default, Priority: priority, State: s})
}
} else {
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
sts = append(sts, DriverState{Name: d.Name, Default: d.Default, Priority: priority, State: s})
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/registry/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestGlobalAvailable(t *testing.T) {

bar := DriverDef{
Name: "healthy-bar",
Default: true,
Priority: Default,
Status: func() State { return State{Healthy: true} },
}
Expand All @@ -82,6 +83,7 @@ func TestGlobalAvailable(t *testing.T) {

foo := DriverDef{
Name: "unhealthy-foo",
Default: true,
Priority: Default,
Status: func() State { return State{Healthy: false} },
}
Expand All @@ -92,11 +94,13 @@ func TestGlobalAvailable(t *testing.T) {
expected := []DriverState{
{
Name: "healthy-bar",
Default: true,
Priority: Default,
State: State{Healthy: true},
},
{
Name: "unhealthy-foo",
Default: true,
Priority: Unhealthy,
State: State{Healthy: false},
},
Expand All @@ -117,6 +121,7 @@ func TestGlobalStatus(t *testing.T) {
expected := State{Installed: true, Healthy: true}
bar := DriverDef{
Name: "bar",
Default: true,
Priority: Default,
Status: func() State { return expected },
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/minikube/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ type DriverDef struct {
// Status returns the installation status of the driver
Status StatusChecker

// Default is whether this driver is selected by default or not (opt-in).
Default bool

// Priority returns the prioritization for selecting a driver by default.
Priority Priority
}
Expand Down

0 comments on commit 57d33de

Please sign in to comment.