Make sure CFS_BANDWIDTH is available for --cpus

pull/9255/head
Anders F Björklund 2020-09-15 12:54:39 +02:00
parent f18eed2afd
commit f718e39ab9
1 changed files with 18 additions and 1 deletions

View File

@ -156,7 +156,24 @@ func CreateContainerNode(p CreateParams) error {
runArgs = append(runArgs, "--security-opt", "apparmor=unconfined") runArgs = append(runArgs, "--security-opt", "apparmor=unconfined")
} }
cpuCfsPeriod := true
cpuCfsQuota := true
if runtime.GOOS == "linux" {
if _, err := os.Stat("/sys/fs/cgroup/cpu/cpu.cfs_period_us"); os.IsNotExist(err) {
cpuCfsPeriod = false
}
if _, err := os.Stat("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"); os.IsNotExist(err) {
cpuCfsQuota = false
}
if !cpuCfsPeriod || !cpuCfsQuota {
// requires CONFIG_CFS_BANDWIDTH
glog.Warning("Your kernel does not support CPU cfs period/quota or the cgroup is not mounted.")
}
}
if cpuCfsPeriod && cpuCfsQuota {
runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs)) runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs))
}
memcgSwap := true memcgSwap := true
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {