diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index a3ff003985..3380a2ab18 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -313,11 +313,7 @@ func runStart(cmd *cobra.Command, args []string) { exit.WithError("Failed to generate config", err) } - if !driver.BareMetal(driverName) && !driver.IsKIC(driverName) { - if err := cluster.CacheISO(config); err != nil { - exit.WithError("Failed to cache ISO", err) - } - } + cacheISO(&config, driverName) if viper.GetBool(nativeSSH) { ssh.SetDefaultClient(ssh.Native) @@ -389,6 +385,14 @@ func updateDriver(driverName string) { } } +func cacheISO(config *cfg.MachineConfig, driverName string) { + if !driver.BareMetal(driverName) && !driver.IsKIC(driverName) { + if err := cluster.CacheISO(*config); err != nil { + exit.WithError("Failed to cache ISO", err) + } + } +} + func enableAddons() { for _, a := range addonList { err := cmdcfg.Set(a, "true") @@ -704,7 +708,7 @@ func minikubeCmd() string { return "minikube" } -// validerUser validates minikube is run by the recommended user (privileged or regular) +// validateUser validates minikube is run by the recommended user (privileged or regular) func validateUser(drvName string) { u, err := user.Current() if err != nil { @@ -738,13 +742,16 @@ func validateUser(drvName string) { } } -// validateFlags validates the supplied flags against known bad combinations -func validateFlags(cmd *cobra.Command, drvName string) { +// validateDiskSize validates the disk size matches the minimum recommended +func validateDiskSize() { diskSizeMB := pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize)) if diskSizeMB < pkgutil.CalculateSizeInMB(minimumDiskSize) && !viper.GetBool(force) { exit.WithCodeT(exit.Config, "Requested disk size {{.requested_size}} is less than minimum of {{.minimum_size}}", out.V{"requested_size": diskSizeMB, "minimum_size": pkgutil.CalculateSizeInMB(minimumDiskSize)}) } +} +// validateMemorySize validates the memory size matches the minimum recommended +func validateMemorySize() { memorySizeMB := pkgutil.CalculateSizeInMB(viper.GetString(memory)) if memorySizeMB < pkgutil.CalculateSizeInMB(minimumMemorySize) && !viper.GetBool(force) { exit.UsageT("Requested memory allocation {{.requested_size}} is less than the minimum allowed of {{.minimum_size}}", out.V{"requested_size": memorySizeMB, "minimum_size": pkgutil.CalculateSizeInMB(minimumMemorySize)}) @@ -753,8 +760,32 @@ func validateFlags(cmd *cobra.Command, drvName string) { out.T(out.Notice, "Requested memory allocation ({{.memory}}MB) is less than the default memory allocation of {{.default_memorysize}}MB. Beware that minikube might not work correctly or crash unexpectedly.", out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(defaultMemorySize)}) } +} +// validateCPUCount validates the cpu count matches the minimum recommended +func validateCPUCount(local bool) { var cpuCount int + if local { + // Uses the gopsutil cpu package to count the number of physical cpu cores + ci, err := cpu.Counts(false) + if err != nil { + glog.Warningf("Unable to get CPU info: %v", err) + } else { + cpuCount = ci + } + } else { + cpuCount = viper.GetInt(cpus) + } + if cpuCount < minimumCPUS && !viper.GetBool(force) { + exit.UsageT("Requested cpu count {{.requested_cpus}} is less than the minimum allowed of {{.minimum_cpus}}", out.V{"requested_cpus": cpuCount, "minimum_cpus": minimumCPUS}) + } +} + +// validateFlags validates the supplied flags against known bad combinations +func validateFlags(cmd *cobra.Command, drvName string) { + validateDiskSize() + validateMemorySize() + if driver.BareMetal(drvName) { if viper.GetString(cfg.MachineProfile) != constants.DefaultMachineName { exit.WithCodeT(exit.Config, "The 'none' driver does not support multiple profiles: https://minikube.sigs.k8s.io/docs/reference/drivers/none/") @@ -771,20 +802,9 @@ func validateFlags(cmd *cobra.Command, drvName string) { if runtime != "docker" { out.WarningT("Using the '{{.runtime}}' runtime with the 'none' driver is an untested configuration!", out.V{"runtime": runtime}) } + } - // Uses the gopsutil cpu package to count the number of physical cpu cores - ci, err := cpu.Counts(false) - if err != nil { - glog.Warningf("Unable to get CPU info: %v", err) - } else { - cpuCount = ci - } - } else { - cpuCount = viper.GetInt(cpus) - } - if cpuCount < minimumCPUS && !viper.GetBool(force) { - exit.UsageT("Requested cpu count {{.requested_cpus}} is less than the minimum allowed of {{.minimum_cpus}}", out.V{"requested_cpus": cpuCount, "minimum_cpus": minimumCPUS}) - } + validateCPUCount(driver.BareMetal(drvName)) // check that kubeadm extra args contain only whitelisted parameters for param := range extraOptions.AsMap().Get(bsutil.Kubeadm) { diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index e116e2d503..e295fe170c 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -419,13 +419,8 @@ func showRemoteOsRelease(driver drivers.Driver) { glog.Infof("Provisioned with %s", osReleaseInfo.PrettyName) } -func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) { - if config.VMDriver == driver.VMwareFusion && viper.GetBool(cfg.ShowDriverDeprecationNotification) { - out.WarningT(`The vmwarefusion driver is deprecated and support for it will be removed in a future release. - Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver. - See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information. - To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`) - } +// showHostInfo shows host information +func showHostInfo(config cfg.MachineConfig) { if driver.BareMetal(config.VMDriver) { info, err := getHostInfo() if err == nil { @@ -439,6 +434,16 @@ func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error } else { out.T(out.StartingVM, "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"driver_name": config.VMDriver, "number_of_cpus": config.CPUs, "memory_size": config.Memory, "disk_size": config.DiskSize}) } +} + +func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) { + if config.VMDriver == driver.VMwareFusion && viper.GetBool(cfg.ShowDriverDeprecationNotification) { + out.WarningT(`The vmwarefusion driver is deprecated and support for it will be removed in a future release. + Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver. + See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information. + To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`) + } + showHostInfo(config) def := registry.Driver(config.VMDriver) if def.Empty() { return nil, fmt.Errorf("unsupported/missing driver: %s", config.VMDriver) diff --git a/pkg/minikube/localpath/localpath.go b/pkg/minikube/localpath/localpath.go index b5a00092c8..eb61a0d2f1 100644 --- a/pkg/minikube/localpath/localpath.go +++ b/pkg/minikube/localpath/localpath.go @@ -61,8 +61,7 @@ func MachinePath(machine string, miniHome ...string) string { return filepath.Join(miniPath, "machines", machine) } -// SanitizeCacheDir -// # ParseReference cannot have a : in the directory path +// SanitizeCacheDir returns a path without special characters func SanitizeCacheDir(image string) string { if runtime.GOOS == "windows" && hasWindowsDriveLetter(image) { // not sanitize Windows drive letter. @@ -70,6 +69,7 @@ func SanitizeCacheDir(image string) string { glog.Infof("windows sanitize: %s -> %s", image, s) return s } + // ParseReference cannot have a : in the directory path return strings.Replace(image, ":", "_", -1) }