Skip to content

Commit 1976bbb

Browse files
committed
Issue #966 Remove driver option from start
CRC only support the native hypervisor for each platform and doesn't provide any different driver to connect a non-native hypervisor. This PR will remove unused `driver` option from start command. Fix #966
1 parent cae2ed9 commit 1976bbb

File tree

8 files changed

+4
-49
lines changed

8 files changed

+4
-49
lines changed

cmd/crc/cmd/config/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import (
66

77
cfg "github.com/code-ready/crc/pkg/crc/config"
88
"github.com/code-ready/crc/pkg/crc/constants"
9-
"github.com/code-ready/crc/pkg/crc/machine"
109
"github.com/spf13/cobra"
1110
)
1211

1312
var (
1413
// Start command settings in config
15-
VMDriver = cfg.AddSetting("vm-driver", machine.DefaultDriver.Driver, []cfg.ValidationFnType{cfg.ValidateDriver}, []cfg.SetFn{cfg.SuccessfullyApplied})
1614
Bundle = cfg.AddSetting("bundle", nil, []cfg.ValidationFnType{cfg.ValidateBundle}, []cfg.SetFn{cfg.SuccessfullyApplied})
1715
CPUs = cfg.AddSetting("cpus", constants.DefaultCPUs, []cfg.ValidationFnType{cfg.ValidateCPUs}, []cfg.SetFn{cfg.RequiresRestartMsg})
1816
Memory = cfg.AddSetting("memory", constants.DefaultMemory, []cfg.ValidationFnType{cfg.ValidateMemory}, []cfg.SetFn{cfg.RequiresRestartMsg})

cmd/crc/cmd/start.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func runStart(arguments []string) {
5252
startConfig := machine.StartConfig{
5353
Name: constants.DefaultName,
5454
BundlePath: crcConfig.GetString(config.Bundle.Name),
55-
VMDriver: crcConfig.GetString(config.VMDriver.Name),
5655
Memory: crcConfig.GetInt(config.Memory.Name),
5756
CPUs: crcConfig.GetInt(config.CPUs.Name),
5857
NameServer: crcConfig.GetString(config.NameServer.Name),
@@ -76,7 +75,6 @@ func runStart(arguments []string) {
7675
func initStartCmdFlagSet() *pflag.FlagSet {
7776
flagSet := pflag.NewFlagSet("start", pflag.ExitOnError)
7877
flagSet.StringP(config.Bundle.Name, "b", constants.DefaultBundlePath, "The system bundle used for deployment of the OpenShift cluster")
79-
flagSet.StringP(config.VMDriver.Name, "d", machine.DefaultDriver.Driver, fmt.Sprintf("The driver to use for the OpenShift cluster. Possible values: %v", machine.SupportedDriverValues()))
8078
flagSet.StringP(config.PullSecretFile.Name, "p", "", fmt.Sprintf("File path of image pull secret (download from %s)", constants.CrcLandingPageURL))
8179
flagSet.IntP(config.CPUs.Name, "c", constants.DefaultCPUs, "Number of CPU cores to allocate to the OpenShift cluster")
8280
flagSet.IntP(config.Memory.Name, "m", constants.DefaultMemory, "MiB of memory to allocate to the OpenShift cluster")
@@ -91,9 +89,6 @@ func isDebugLog() bool {
9189
}
9290

9391
func validateStartFlags() error {
94-
if err := validation.ValidateDriver(crcConfig.GetString(config.VMDriver.Name)); err != nil {
95-
return err
96-
}
9792
if err := validation.ValidateMemory(crcConfig.GetInt(config.Memory.Name)); err != nil {
9893
return err
9994
}

pkg/crc/api/handlers.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func startHandler(_ ArgsType) string {
3232
startConfig := machine.StartConfig{
3333
Name: constants.DefaultName,
3434
BundlePath: crcConfig.GetString(config.Bundle.Name),
35-
VMDriver: crcConfig.GetString(config.VMDriver.Name),
3635
Memory: crcConfig.GetInt(config.Memory.Name),
3736
CPUs: crcConfig.GetInt(config.CPUs.Name),
3837
NameServer: crcConfig.GetString(config.NameServer.Name),

pkg/crc/config/validations.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ func ValidateBool(value interface{}) (bool, string) {
2222
return false, "must be true or false"
2323
}
2424

25-
// ValidateDriver checks if driver is valid in the config
26-
func ValidateDriver(value interface{}) (bool, string) {
27-
if err := validation.ValidateDriver(value.(string)); err != nil {
28-
return false, err.Error()
29-
}
30-
return true, ""
31-
}
32-
3325
// ValidateCPUs checks if provided cpus count is valid in the config
3426
func ValidateCPUs(value interface{}) (bool, string) {
3527
v, err := strconv.Atoi(value.(string))

pkg/crc/machine/driver.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package machine
22

33
import (
4-
"github.com/code-ready/crc/pkg/crc/errors"
5-
64
crcos "github.com/code-ready/crc/pkg/os"
75
)
86

@@ -25,12 +23,3 @@ func SupportedDriverValues() []string {
2523
}
2624
return supportedDrivers
2725
}
28-
29-
func getDriverInfo(driver string) (*MachineDriver, error) {
30-
for _, d := range SupportedDrivers {
31-
if driver == d.Driver {
32-
return &d, nil
33-
}
34-
}
35-
return nil, errors.Newf("No info about unknown driver: %s", driver)
36-
}

pkg/crc/machine/machine.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ func Start(startConfig StartConfig) (StartResult, error) {
113113
// Pre-VM start
114114
var privateKeyPath string
115115
var pullSecret string
116-
driverInfo, _ := getDriverInfo(startConfig.VMDriver)
116+
driverInfo := DefaultDriver
117117
exists, err := MachineExists(startConfig.Name)
118118
if !exists {
119119
machineConfig := config.MachineConfig{
120120
Name: startConfig.Name,
121121
BundleName: filepath.Base(startConfig.BundlePath),
122-
VMDriver: startConfig.VMDriver,
122+
VMDriver: driverInfo.Driver,
123123
CPUs: startConfig.CPUs,
124124
Memory: startConfig.Memory,
125125
}
@@ -182,12 +182,6 @@ func Start(startConfig StartConfig) (StartResult, error) {
182182
logging.Fatalf("Bundle '%s' was requested, but the existing VM is using '%s'",
183183
filepath.Base(startConfig.BundlePath), bundleName)
184184
}
185-
if host.Driver.DriverName() != startConfig.VMDriver {
186-
err := errors.Newf("VM driver '%s' was requested, but the existing VM is using '%s' instead",
187-
startConfig.VMDriver, host.Driver.DriverName())
188-
result.Error = err.Error()
189-
return *result, err
190-
}
191185
vmState, err := host.Driver.GetState()
192186
if err != nil {
193187
result.Error = err.Error()

pkg/crc/machine/types.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ type StartConfig struct {
1414
BundlePath string
1515

1616
// Hypervisor
17-
VMDriver string
18-
Memory int
19-
CPUs int
17+
Memory int
18+
CPUs int
2019

2120
// Nameserver
2221
NameServer string

pkg/crc/validation/validation.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,8 @@ import (
1111

1212
"github.com/code-ready/crc/pkg/crc/constants"
1313
"github.com/code-ready/crc/pkg/crc/errors"
14-
"github.com/code-ready/crc/pkg/crc/machine"
1514
)
1615

17-
// Validate the given driver is supported or not
18-
func ValidateDriver(driver string) error {
19-
for _, d := range machine.SupportedDriverValues() {
20-
if driver == d {
21-
return nil
22-
}
23-
}
24-
return errors.Newf("Unsupported driver: %s, use '--vm-driver' option to provide a supported driver %s\n", driver, machine.SupportedDriverValues())
25-
}
26-
2716
// ValidateCPUs checks if provided cpus count is valid
2817
func ValidateCPUs(value int) error {
2918
if value < constants.DefaultCPUs {

0 commit comments

Comments
 (0)