提交 de6c1052 编写于 作者: M Medya Gh

move cacheDaemoninfo to oci package

上级 dbfd16f2
......@@ -70,7 +70,6 @@ var (
insecureRegistry []string
apiServerNames []string
apiServerIPs []net.IP
kicSysInfo *oci.SysInfo
)
func init() {
......@@ -753,7 +752,7 @@ func memoryLimits(drvName string) (int, int, error) {
containerLimit := 0
if driver.IsKIC(drvName) {
s, err := cachedKicSystemInfo(drvName)
s, err := oci.CachedDaemonInfo(drvName)
if err != nil {
return -1, -1, err
}
......@@ -854,7 +853,7 @@ func validateCPUCount(drvName string) {
}
if driver.IsKIC((drvName)) {
si, err := cachedKicSystemInfo(drvName)
si, err := oci.CachedDaemonInfo(drvName)
if err != nil {
out.WarningT("Failed to verify '{{.driver_name}} info', ensure your {{.driver_name}} is running healthy.", out.V{"driver_namee": drvName})
}
......@@ -1144,14 +1143,3 @@ func getKubernetesVersion(old *config.ClusterConfig) string {
return version.VersionPrefix + nvs.String()
}
// cachedKicSystemInfo will return docker/podman info. it will call docker/podam info only once per minikube start to avoid perforamce side effects
func cachedKicSystemInfo(ociBin string) (oci.SysInfo, error) {
var err error
if kicSysInfo == nil {
si, err := oci.DaemonInfo(ociBin)
kicSysInfo = &si
return *kicSysInfo, err
}
return *kicSysInfo, err
}
......@@ -32,21 +32,33 @@ type SysInfo struct {
OSType string // container's OsType (windows or linux)
}
var cachedSysInfo *SysInfo
// CachedDaemonInfo will run and return a docker/podman info only once per minikube run time. to avoid perfomance
func CachedDaemonInfo(ociBin string) (SysInfo, error) {
var err error
if cachedSysInfo == nil {
si, err := DaemonInfo(ociBin)
cachedSysInfo = &si
return *cachedSysInfo, err
}
return *cachedSysInfo, err
}
// DaemonInfo returns common docker/podman daemon system info that minikube cares about
func DaemonInfo(ociBin string) (SysInfo, error) {
var info SysInfo
if ociBin == Podman {
p, err := podmanSystemInfo()
info.CPUs = p.Host.Cpus
info.TotalMemory = p.Host.MemTotal
info.OSType = p.Host.Os
return info, err
cachedSysInfo.CPUs = p.Host.Cpus
cachedSysInfo.TotalMemory = p.Host.MemTotal
cachedSysInfo.OSType = p.Host.Os
return *cachedSysInfo, err
}
d, err := dockerSystemInfo()
info.CPUs = d.NCPU
info.TotalMemory = d.MemTotal
info.OSType = d.OSType
return info, err
cachedSysInfo.CPUs = d.NCPU
cachedSysInfo.TotalMemory = d.MemTotal
cachedSysInfo.OSType = d.OSType
return *cachedSysInfo, err
}
// dockerSysInfo represents the output of docker system info --format '{{json .}}'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册