From e053e4f235a7dfc88b0964372b9bc00b14447496 Mon Sep 17 00:00:00 2001 From: vikkyomkar Date: Tue, 17 Mar 2020 13:21:05 +0530 Subject: [PATCH] Add --vm flag for users who want to autoselect only VM's --- cmd/minikube/cmd/start.go | 3 ++- pkg/minikube/driver/driver.go | 27 ++++++++++++++++++++------- pkg/minikube/driver/driver_test.go | 2 +- pkg/minikube/registry/global.go | 3 --- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 44e3d3210c..fea525383b 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -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/") } diff --git a/pkg/minikube/driver/driver.go b/pkg/minikube/driver/driver.go index 2dce6350cd..e5ea05b00a 100644 --- a/pkg/minikube/driver/driver.go +++ b/pkg/minikube/driver/driver.go @@ -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 diff --git a/pkg/minikube/driver/driver_test.go b/pkg/minikube/driver/driver_test.go index 8f9be829ad..5d0bfd4009 100644 --- a/pkg/minikube/driver/driver_test.go +++ b/pkg/minikube/driver/driver_test.go @@ -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) diff --git a/pkg/minikube/registry/global.go b/pkg/minikube/registry/global.go index 301f61cb9f..d53168b48d 100644 --- a/pkg/minikube/registry/global.go +++ b/pkg/minikube/registry/global.go @@ -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.