瀏覽代碼

Fix golint warning on pkg/sysinfo

Signed-off-by: Hu Keping <hukeping@huawei.com>
Hu Keping 10 年之前
父節點
當前提交
7390cc5300

+ 2 - 2
daemon/daemon_unix.go

@@ -166,12 +166,12 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
 			return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
 			return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
 		}
 		}
 	}
 	}
-	if hostConfig.CPUPeriod > 0 && !daemon.SystemConfig().CpuCfsPeriod {
+	if hostConfig.CPUPeriod > 0 && !daemon.SystemConfig().CPUCfsPeriod {
 		warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")
 		warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")
 		logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.")
 		logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.")
 		hostConfig.CPUPeriod = 0
 		hostConfig.CPUPeriod = 0
 	}
 	}
-	if hostConfig.CPUQuota > 0 && !daemon.SystemConfig().CpuCfsQuota {
+	if hostConfig.CPUQuota > 0 && !daemon.SystemConfig().CPUCfsQuota {
 		warnings = append(warnings, "Your kernel does not support CPU cfs quota. Quota discarded.")
 		warnings = append(warnings, "Your kernel does not support CPU cfs quota. Quota discarded.")
 		logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.")
 		logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.")
 		hostConfig.CPUQuota = 0
 		hostConfig.CPUQuota = 0

+ 3 - 3
daemon/info.go

@@ -64,7 +64,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
 		DriverStatus:       daemon.GraphDriver().Status(),
 		DriverStatus:       daemon.GraphDriver().Status(),
 		IPv4Forwarding:     !daemon.SystemConfig().IPv4ForwardingDisabled,
 		IPv4Forwarding:     !daemon.SystemConfig().IPv4ForwardingDisabled,
 		BridgeNfIptables:   !daemon.SystemConfig().BridgeNfCallIptablesDisabled,
 		BridgeNfIptables:   !daemon.SystemConfig().BridgeNfCallIptablesDisabled,
-		BridgeNfIp6tables:  !daemon.SystemConfig().BridgeNfCallIp6tablesDisabled,
+		BridgeNfIp6tables:  !daemon.SystemConfig().BridgeNfCallIP6tablesDisabled,
 		Debug:              os.Getenv("DEBUG") != "",
 		Debug:              os.Getenv("DEBUG") != "",
 		NFd:                fileutils.GetTotalUsedFds(),
 		NFd:                fileutils.GetTotalUsedFds(),
 		NGoroutines:        runtime.NumGoroutine(),
 		NGoroutines:        runtime.NumGoroutine(),
@@ -93,8 +93,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
 		v.MemoryLimit = daemon.SystemConfig().MemoryLimit
 		v.MemoryLimit = daemon.SystemConfig().MemoryLimit
 		v.SwapLimit = daemon.SystemConfig().SwapLimit
 		v.SwapLimit = daemon.SystemConfig().SwapLimit
 		v.OomKillDisable = daemon.SystemConfig().OomKillDisable
 		v.OomKillDisable = daemon.SystemConfig().OomKillDisable
-		v.CpuCfsPeriod = daemon.SystemConfig().CpuCfsPeriod
-		v.CpuCfsQuota = daemon.SystemConfig().CpuCfsQuota
+		v.CpuCfsPeriod = daemon.SystemConfig().CPUCfsPeriod
+		v.CpuCfsQuota = daemon.SystemConfig().CPUCfsQuota
 	}
 	}
 
 
 	if httpProxy := os.Getenv("http_proxy"); httpProxy != "" {
 	if httpProxy := os.Getenv("http_proxy"); httpProxy != "" {

+ 1 - 0
hack/make/validate-lint

@@ -65,6 +65,7 @@ packages=(
 	pkg/streamformatter
 	pkg/streamformatter
 	pkg/stringid
 	pkg/stringid
 	pkg/stringutils
 	pkg/stringutils
+	pkg/sysinfo
 	pkg/systemd
 	pkg/systemd
 	pkg/symlink
 	pkg/symlink
 	pkg/tailfile
 	pkg/tailfile

+ 31 - 11
pkg/sysinfo/sysinfo.go

@@ -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
-	IPv4ForwardingDisabled        bool
-	BridgeNfCallIptablesDisabled  bool
-	BridgeNfCallIp6tablesDisabled bool
-	CgroupDevicesEnabled          bool
+	*cgroupCPUInfo
+
+	// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
+	IPv4ForwardingDisabled 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
-	SwapLimit        bool
-	OomKillDisable   bool
+	// Whether memory limit is supported or not
+	MemoryLimit 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 {
-	CpuCfsPeriod bool
-	CpuCfsQuota  bool
+type cgroupCPUInfo struct {
+	// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
+	CPUCfsPeriod bool
+
+	// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
+	CPUCfsQuota bool
 }
 }

+ 1 - 1
pkg/sysinfo/sysinfo_freebsd.go

@@ -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

+ 8 - 8
pkg/sysinfo/sysinfo_linux.go

@@ -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 {
-	info := &cgroupCpuInfo{}
+func checkCgroupCPU(quiet bool) *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")
-	if !quiet && !info.CpuCfsPeriod {
+	info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
+	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")
-	if !quiet && !info.CpuCfsQuota {
+	info.CPUCfsQuota = cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
+	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 - 1
pkg/sysinfo/sysinfo_windows.go

@@ -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