Fix golint warning on pkg/sysinfo
Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
parent
8cd8bc1365
commit
001fc3cf5f
4 changed files with 41 additions and 21 deletions
|
@ -3,23 +3,43 @@ package sysinfo
|
||||||
// SysInfo stores information about which features a kernel supports.
|
// SysInfo stores information about which features a kernel supports.
|
||||||
// TODO Windows: Factor out platform specific capabilities.
|
// TODO Windows: Factor out platform specific capabilities.
|
||||||
type SysInfo struct {
|
type SysInfo struct {
|
||||||
|
// Whether the kernel supports AppArmor or not
|
||||||
AppArmor bool
|
AppArmor bool
|
||||||
|
|
||||||
*cgroupMemInfo
|
*cgroupMemInfo
|
||||||
*cgroupCpuInfo
|
*cgroupCPUInfo
|
||||||
IPv4ForwardingDisabled bool
|
|
||||||
BridgeNfCallIptablesDisabled bool
|
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
|
||||||
BridgeNfCallIp6tablesDisabled bool
|
IPv4ForwardingDisabled bool
|
||||||
CgroupDevicesEnabled bool
|
|
||||||
|
// Whether bridge-nf-call-iptables is supported or not
|
||||||
|
BridgeNfCallIptablesDisabled bool
|
||||||
|
|
||||||
|
// Whether bridge-nf-call-ip6tables is supported or not
|
||||||
|
BridgeNfCallIP6tablesDisabled bool
|
||||||
|
|
||||||
|
// Whether the cgroup has the mountpoint of "devices" or not
|
||||||
|
CgroupDevicesEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type cgroupMemInfo struct {
|
type cgroupMemInfo struct {
|
||||||
MemoryLimit bool
|
// Whether memory limit is supported or not
|
||||||
SwapLimit bool
|
MemoryLimit bool
|
||||||
OomKillDisable bool
|
|
||||||
|
// Whether swap limit is supported or not
|
||||||
|
SwapLimit bool
|
||||||
|
|
||||||
|
// Whether OOM killer disalbe is supported or not
|
||||||
|
OomKillDisable bool
|
||||||
|
|
||||||
|
// Whether memory swappiness is supported or not
|
||||||
MemorySwappiness bool
|
MemorySwappiness bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type cgroupCpuInfo struct {
|
type cgroupCPUInfo struct {
|
||||||
CpuCfsPeriod bool
|
// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
|
||||||
CpuCfsQuota bool
|
CPUCfsPeriod bool
|
||||||
|
|
||||||
|
// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
|
||||||
|
CPUCfsQuota bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package sysinfo
|
package sysinfo
|
||||||
|
|
||||||
// TODO FreeBSD
|
// New returns an empty SysInfo for freebsd for now.
|
||||||
func New(quiet bool) *SysInfo {
|
func New(quiet bool) *SysInfo {
|
||||||
sysInfo := &SysInfo{}
|
sysInfo := &SysInfo{}
|
||||||
return sysInfo
|
return sysInfo
|
||||||
|
|
|
@ -14,14 +14,14 @@ import (
|
||||||
func New(quiet bool) *SysInfo {
|
func New(quiet bool) *SysInfo {
|
||||||
sysInfo := &SysInfo{}
|
sysInfo := &SysInfo{}
|
||||||
sysInfo.cgroupMemInfo = checkCgroupMem(quiet)
|
sysInfo.cgroupMemInfo = checkCgroupMem(quiet)
|
||||||
sysInfo.cgroupCpuInfo = checkCgroupCpu(quiet)
|
sysInfo.cgroupCPUInfo = checkCgroupCPU(quiet)
|
||||||
|
|
||||||
_, err := cgroups.FindCgroupMountpoint("devices")
|
_, err := cgroups.FindCgroupMountpoint("devices")
|
||||||
sysInfo.CgroupDevicesEnabled = err == nil
|
sysInfo.CgroupDevicesEnabled = err == nil
|
||||||
|
|
||||||
sysInfo.IPv4ForwardingDisabled = !readProcBool("/proc/sys/net/ipv4/ip_forward")
|
sysInfo.IPv4ForwardingDisabled = !readProcBool("/proc/sys/net/ipv4/ip_forward")
|
||||||
sysInfo.BridgeNfCallIptablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-iptables")
|
sysInfo.BridgeNfCallIptablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-iptables")
|
||||||
sysInfo.BridgeNfCallIp6tablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-ip6tables")
|
sysInfo.BridgeNfCallIP6tablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-ip6tables")
|
||||||
|
|
||||||
// Check if AppArmor is supported.
|
// Check if AppArmor is supported.
|
||||||
if _, err := os.Stat("/sys/kernel/security/apparmor"); !os.IsNotExist(err) {
|
if _, err := os.Stat("/sys/kernel/security/apparmor"); !os.IsNotExist(err) {
|
||||||
|
@ -58,8 +58,8 @@ func checkCgroupMem(quiet bool) *cgroupMemInfo {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCgroupCpu(quiet bool) *cgroupCpuInfo {
|
func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
|
||||||
info := &cgroupCpuInfo{}
|
info := &cgroupCPUInfo{}
|
||||||
mountPoint, err := cgroups.FindCgroupMountpoint("cpu")
|
mountPoint, err := cgroups.FindCgroupMountpoint("cpu")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !quiet {
|
if !quiet {
|
||||||
|
@ -68,13 +68,13 @@ func checkCgroupCpu(quiet bool) *cgroupCpuInfo {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
info.CpuCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
|
info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
|
||||||
if !quiet && !info.CpuCfsPeriod {
|
if !quiet && !info.CPUCfsPeriod {
|
||||||
logrus.Warn("Your kernel does not support cgroup cfs period")
|
logrus.Warn("Your kernel does not support cgroup cfs period")
|
||||||
}
|
}
|
||||||
|
|
||||||
info.CpuCfsQuota = cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
|
info.CPUCfsQuota = cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
|
||||||
if !quiet && !info.CpuCfsQuota {
|
if !quiet && !info.CPUCfsQuota {
|
||||||
logrus.Warn("Your kernel does not support cgroup cfs quotas")
|
logrus.Warn("Your kernel does not support cgroup cfs quotas")
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package sysinfo
|
package sysinfo
|
||||||
|
|
||||||
// TODO Windows
|
// New returns an empty SysInfo for windows for now.
|
||||||
func New(quiet bool) *SysInfo {
|
func New(quiet bool) *SysInfo {
|
||||||
sysInfo := &SysInfo{}
|
sysInfo := &SysInfo{}
|
||||||
return sysInfo
|
return sysInfo
|
||||||
|
|
Loading…
Reference in a new issue