1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-28 10:47:23 +00:00

Merge pull request #1265 from fidencio/topic/cpu-misc-cgroups-take-cgroupsv1-into-account

cpu: Take cgroupsv1 into account when reading misc.capacity
This commit is contained in:
Kubernetes Prow Robot 2023-07-19 06:12:05 -07:00 committed by GitHub
commit fd0ba3f9d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -122,17 +122,10 @@ func sevParameterEnabled(parameter string) bool {
return false
}
func getCgroupMiscCapacity(resource string) int64 {
func retrieveCgroupMiscCapacityValue(miscCgroupPath *os.File, resource string) int64 {
var totalResources int64 = -1
miscCgroups := hostpath.SysfsDir.Path("fs/cgroup/misc.capacity")
f, err := os.Open(miscCgroups)
if err != nil {
return totalResources
}
defer f.Close()
r := bufio.NewReader(f)
r := bufio.NewReader(miscCgroupPath)
for {
line, _, err := r.ReadLine()
if err != nil {
@ -158,3 +151,18 @@ func getCgroupMiscCapacity(resource string) int64 {
return totalResources
}
func getCgroupMiscCapacity(resource string) int64 {
miscCgroupsPaths := []string{"fs/cgroup/misc.capacity", "fs/cgroup/misc/misc.capacity"}
for _, miscCgroupsPath := range miscCgroupsPaths {
miscCgroups := hostpath.SysfsDir.Path(miscCgroupsPath)
f, err := os.Open(miscCgroups)
if err == nil {
defer f.Close()
return retrieveCgroupMiscCapacityValue(f, resource)
}
}
return -1
}