Skip to content

Commit

Permalink
ensure nil error is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
medyagh committed Aug 11, 2020
1 parent 25c1177 commit 059891b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/drivers/kic/oci/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ var cachedSysInfoErr *error

// CachedDaemonInfo will run and return a docker/podman info only once per minikube run time. to avoid performance
func CachedDaemonInfo(ociBin string) (SysInfo, error) {
if cachedSysInfo == nil || cachedSysInfoErr != nil { // if cached daemon info has error, try to get a new one
if cachedSysInfo == nil { // if cached daemon info has error, try to get a new one
si, err := DaemonInfo(ociBin)
cachedSysInfo = &si
cachedSysInfoErr = &err
}
if cachedSysInfoErr == nil {
return *cachedSysInfo, nil
}
return *cachedSysInfo, *cachedSysInfoErr
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/minikube/machine/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ var cachedSystemMemoryErr *error

// cachedSysMemLimit will return a cached limit for the system's virtual memory.
func cachedSysMemLimit() (*mem.VirtualMemoryStat, error) {
if cachedSystemMemoryLimit == nil || cachedSystemMemoryErr != nil {
if cachedSystemMemoryLimit == nil {
v, err := mem.VirtualMemory()
cachedSystemMemoryLimit = v
cachedSystemMemoryErr = &err
}
if cachedSystemMemoryErr == nil {
return cachedSystemMemoryLimit, nil
}
return cachedSystemMemoryLimit, *cachedSystemMemoryErr
}

Expand All @@ -124,11 +127,14 @@ var cachedDiskInfoeErr *error

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

Expand All @@ -137,13 +143,13 @@ var cachedCPUErr *error

// cachedCPUInfo will return a cached cpu info
func cachedCPUInfo() ([]cpu.InfoStat, error) {
if cachedCPU == nil || cachedCPUErr != nil {
if cachedCPU == nil {
i, err := cpu.Info()
cachedCPU = &i
cachedCPUErr = &err
if err != nil {
return nil, *cachedCPUErr
}
}
if cachedCPUErr == nil {
return *cachedCPU, nil
}
return *cachedCPU, *cachedCPUErr
}

0 comments on commit 059891b

Please sign in to comment.