From c83910e138441bf0dad9fce55f5f976a4235e1fc Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Mon, 10 Aug 2020 17:03:32 -0700 Subject: [PATCH] ensure nil error is returned --- pkg/drivers/kic/oci/info.go | 5 ++++- pkg/minikube/machine/info.go | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/drivers/kic/oci/info.go b/pkg/drivers/kic/oci/info.go index f5a37435fd34..cafacb4346e6 100644 --- a/pkg/drivers/kic/oci/info.go +++ b/pkg/drivers/kic/oci/info.go @@ -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 } diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 18dd145e78fa..834aaa48609c 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -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 } @@ -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 } @@ -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 }