add some e2e tests (unfinished) + fix findMountPoint bug

This commit is contained in:
Nicholas Orlowsky 2023-04-24 11:33:50 -05:00
parent 165d057361
commit 405a5aa44c
No known key found for this signature in database
GPG key ID: 58832FD3AC16C706

View file

@ -38,7 +38,6 @@ import (
func NumCPU() int { func NumCPU() int {
cpus := runtime.NumCPU() cpus := runtime.NumCPU()
cgroupPath, err := libcontainercgroups.FindCgroupMountpoint("", "cpu")
if err != nil { if err != nil {
return cpus return cpus
} }
@ -48,10 +47,11 @@ func NumCPU() int {
cpuPeriod := int64(-1) cpuPeriod := int64(-1)
if cgroupVersion == 1 { if cgroupVersion == 1 {
cgroupPath, err := libcontainercgroups.FindCgroupMountpoint("", "cpu")
cpuQuota = readCgroupFileToInt64(cgroupPath, "cpu.cfs_quota_us") cpuQuota = readCgroupFileToInt64(cgroupPath, "cpu.cfs_quota_us")
cpuPeriod = readCgroupFileToInt64(cgroupPath, "cpu.cfs_period_us") cpuPeriod = readCgroupFileToInt64(cgroupPath, "cpu.cfs_period_us")
} else if cgroupVersion == 2 { } else if cgroupVersion == 2 {
cpuQuota, cpuPeriod = readCgroup2FileToInt64Tuple(cgroupPath, "cpu.max") cpuQuota, cpuPeriod = readCgroup2FileToInt64Tuple("cpu.max")
} }
if cpuQuota == -1 || cpuPeriod == -1 { if cpuQuota == -1 || cpuPeriod == -1 {
@ -71,7 +71,7 @@ func getCgroupVersion() int64 {
} }
func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) { func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) {
contents, err := os.ReadFile(filepath.Join(cgroupPath, cgroupFile)) contents, err := os.ReadFile(filepath.Join("/sys/fs/cgroup/", cgroupFile))
if err != nil { if err != nil {
return -1, -1 return -1, -1