Skip to content

Commit

Permalink
Merge pull request #8959 from medyagh/valid_mem_docker
Browse files Browse the repository at this point in the history
improve error handling for validating memory limits
  • Loading branch information
medyagh authored Aug 11, 2020
2 parents 8b6a0eb + 2e13cf5 commit 5ed6c98
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ jobs:
$env:KUBECONFIG="${pwd}\testhome\kubeconfig"
$env:MINIKUBE_HOME="${pwd}\testhome"
$ErrorActionPreference = "SilentlyContinue"
.\e2e-windows-amd64.exe --minikube-start-args="--driver=hyperv" --test.timeout=15m --timeout-multiplier=1.5 --test.v --test.run=TestFunctional --binary=./minikube-windows-amd64.exe | Tee-Object -FilePath ".\report\testout.txt"
.\e2e-windows-amd64.exe --minikube-start-args="--driver=hyperv" --test.timeout=20m --timeout-multiplier=1.5 --test.v --test.run=TestFunctional --binary=./minikube-windows-amd64.exe | Tee-Object -FilePath ".\report\testout.txt"
$END_TIME=(GET-DATE)
echo $END_TIME
$DURATION=(NEW-TIMESPAN -Start $START_TIME -End $END_TIME)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ jobs:
$env:KUBECONFIG="${pwd}\testhome\kubeconfig"
$env:MINIKUBE_HOME="${pwd}\testhome"
$ErrorActionPreference = "SilentlyContinue"
.\e2e-windows-amd64.exe --minikube-start-args="--driver=hyperv" --test.timeout=15m --timeout-multiplier=1.5 --test.v --test.run=TestFunctional --binary=./minikube-windows-amd64.exe | Tee-Object -FilePath ".\report\testout.txt"
.\e2e-windows-amd64.exe --minikube-start-args="--driver=hyperv" --test.timeout=20m --timeout-multiplier=1.5 --test.v --test.run=TestFunctional --binary=./minikube-windows-amd64.exe | Tee-Object -FilePath ".\report\testout.txt"
$END_TIME=(GET-DATE)
echo $END_TIME
$DURATION=(NEW-TIMESPAN -Start $START_TIME -End $END_TIME)
Expand Down
16 changes: 13 additions & 3 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,18 @@ func validateUser(drvName string) {

// memoryLimits returns the amount of memory allocated to the system and hypervisor , the return value is in MB
func memoryLimits(drvName string) (int, int, error) {
info, err := machine.CachedHostInfo()
if err != nil {
return -1, -1, err
info, cpuErr, memErr, diskErr := machine.CachedHostInfo()
if cpuErr != nil {
glog.Warningf("could not get system cpu info while verifying memory limits, which might be okay: %v", cpuErr)
}
if diskErr != nil {
glog.Warningf("could not get system disk info while verifying memory limits, which might be okay: %v", diskErr)
}

if memErr != nil {
return -1, -1, memErr
}

sysLimit := int(info.Memory)
containerLimit := 0

Expand Down Expand Up @@ -827,9 +835,11 @@ func validateMemoryHardLimit(drvName string) {
if err != nil {
glog.Warningf("Unable to query memory limits: %v", err)
out.WarningT("Failed to verify system memory limits.")
return
}
if s < 2200 {
out.WarningT("Your system has only {{.memory_amount}}MB memory. This might not work minimum required is 2000MB.", out.V{"memory_amount": s})
return
}
if driver.IsDockerDesktop(drvName) {
// in Docker Desktop if you allocate 2 GB the docker info shows: Total Memory: 1.945GiB which becomes 1991 when we calculate the MBs
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
glog.Info("no existing cluster config was found, will generate one from the flags ")
sysLimit, containerLimit, err := memoryLimits(drvName)
if err != nil {
glog.Warningf("Unable to query memory limits: %v", err)
glog.Warningf("Unable to query memory limits: %+v", err)
}

mem := suggestMemoryAllocation(sysLimit, containerLimit, viper.GetInt(nodes))
if cmd.Flags().Changed(memory) {
mem, err = pkgutil.CalculateSizeInMB(viper.GetString(memory))
mem, err := pkgutil.CalculateSizeInMB(viper.GetString(memory))
if err != nil {
exit.WithCodeT(exit.Config, "Generate unable to parse memory '{{.memory}}': {{.error}}", out.V{"memory": viper.GetString(memory), "error": err})
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/drivers/kic/oci/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func CachedDaemonInfo(ociBin string) (SysInfo, error) {
cachedSysInfo = &si
cachedSysInfoErr = &err
}
if cachedSysInfoErr == nil {
return *cachedSysInfo, nil
}
return *cachedSysInfo, *cachedSysInfoErr
}

Expand Down
44 changes: 24 additions & 20 deletions pkg/minikube/machine/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@ func megs(bytes uint64) int64 {
}

// CachedHostInfo returns system information such as memory,CPU, DiskSize
func CachedHostInfo() (*HostInfo, error) {
i, err := cachedCPUInfo()
if err != nil {
glog.Warningf("Unable to get CPU info: %v", err)
return nil, err
func CachedHostInfo() (*HostInfo, error, error, error) {
var cpuErr, memErr, diskErr error
i, cpuErr := cachedCPUInfo()
if cpuErr != nil {
glog.Warningf("Unable to get CPU info: %v", cpuErr)
}
v, err := cachedSysMemLimit()
if err != nil {
glog.Warningf("Unable to get mem info: %v", err)
return nil, err
v, memErr := cachedSysMemLimit()
if memErr != nil {
glog.Warningf("Unable to get mem info: %v", memErr)
}

d, err := cachedDiskInfo()
if err != nil {
glog.Warningf("Unable to get disk info: %v", err)
return nil, err
d, diskErr := cachedDiskInfo()
if diskErr != nil {
glog.Warningf("Unable to get disk info: %v", diskErr)
}

var info HostInfo
info.CPUs = len(i)
info.Memory = megs(v.Total)
info.DiskSize = megs(d.Total)
return &info, nil
return &info, cpuErr, memErr, diskErr
}

// showLocalOsRelease shows systemd information about the current linux distribution, on the local host
Expand Down Expand Up @@ -111,20 +109,26 @@ func cachedSysMemLimit() (*mem.VirtualMemoryStat, error) {
cachedSystemMemoryLimit = v
cachedSystemMemoryErr = &err
}
if cachedSystemMemoryErr == nil {
return cachedSystemMemoryLimit, nil
}
return cachedSystemMemoryLimit, *cachedSystemMemoryErr
}

var cachedDisk *disk.UsageStat
var cachedDiskInfoeErr *error
var cachedDiskInfoErr *error

// cachedDiskInfo will return a cached disk usage info
func cachedDiskInfo() (disk.UsageStat, error) {
if cachedDisk == nil {
d, err := disk.Usage("/")
cachedDisk = d
cachedDiskInfoeErr = &err
cachedDiskInfoErr = &err
}
if cachedDiskInfoErr == nil {
return *cachedDisk, nil
}
return *cachedDisk, *cachedDiskInfoeErr
return *cachedDisk, *cachedDiskInfoErr
}

var cachedCPU *[]cpu.InfoStat
Expand All @@ -136,9 +140,9 @@ func cachedCPUInfo() ([]cpu.InfoStat, error) {
i, err := cpu.Info()
cachedCPU = &i
cachedCPUErr = &err
if err != nil {
return nil, *cachedCPUErr
}
}
if cachedCPUErr == nil {
return *cachedCPU, nil
}
return *cachedCPU, *cachedCPUErr
}
4 changes: 2 additions & 2 deletions pkg/minikube/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ func acquireMachinesLock(name string) (mutex.Releaser, error) {
func showHostInfo(cfg config.ClusterConfig) {
machineType := driver.MachineType(cfg.Driver)
if driver.BareMetal(cfg.Driver) {
info, err := CachedHostInfo()
if err == nil {
info, cpuErr, memErr, DiskErr := CachedHostInfo()
if cpuErr == nil && memErr == nil && DiskErr == nil {
register.Reg.SetStep(register.RunningLocalhost)
out.T(out.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize})
}
Expand Down

0 comments on commit 5ed6c98

Please sign in to comment.