2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2016-12-16 14:13:23 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-08-24 10:10:50 +00:00
|
|
|
"os"
|
2016-12-16 14:13:23 +00:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
|
|
)
|
|
|
|
|
2022-01-20 12:43:42 +00:00
|
|
|
// SysInfo stores information about which features a kernel supports.
|
|
|
|
var SysInfo *sysinfo.SysInfo
|
2016-12-16 14:13:23 +00:00
|
|
|
|
|
|
|
func cpuCfsPeriod() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUCfsPeriod
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func cpuCfsQuota() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUCfsQuota
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func cpuShare() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUShares
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func oomControl() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.OomKillDisable
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func pidsLimit() bool {
|
|
|
|
return SysInfo.PidsLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
func memoryLimitSupport() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.MemoryLimit
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func memoryReservationSupport() bool {
|
|
|
|
return SysInfo.MemoryReservation
|
|
|
|
}
|
|
|
|
|
|
|
|
func swapMemorySupport() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.SwapLimit
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func memorySwappinessSupport() bool {
|
2018-12-24 12:25:53 +00:00
|
|
|
return testEnv.IsLocalDaemon() && SysInfo.MemorySwappiness
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func blkioWeight() bool {
|
2018-12-24 12:25:53 +00:00
|
|
|
return testEnv.IsLocalDaemon() && SysInfo.BlkioWeight
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func cgroupCpuset() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUSet
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func seccompEnabled() bool {
|
2021-06-09 18:52:10 +00:00
|
|
|
return SysInfo.Seccomp
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func bridgeNfIptables() bool {
|
|
|
|
return !SysInfo.BridgeNFCallIPTablesDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func unprivilegedUsernsClone() bool {
|
2021-08-24 10:10:50 +00:00
|
|
|
content, err := os.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
|
2016-12-16 14:13:23 +00:00
|
|
|
return err != nil || !strings.Contains(string(content), "0")
|
|
|
|
}
|
|
|
|
|
|
|
|
func overlayFSSupported() bool {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems")
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return bytes.Contains(out, []byte("overlay\n"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-12-24 12:25:53 +00:00
|
|
|
if testEnv.IsLocalDaemon() {
|
2021-07-14 14:45:02 +00:00
|
|
|
SysInfo = sysinfo.New()
|
2017-09-11 14:23:59 +00:00
|
|
|
}
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|