@@ -30,7 +30,11 @@ import (
30
30
cmutil "k8s.io/kubernetes/pkg/kubelet/cm/util"
31
31
)
32
32
33
- const cgroupv2MemLimitFile string = "memory.max"
33
+ const (
34
+ cgroupv2MemLimitFile = "memory.max"
35
+ cgroupv2CpuMaxFile = "cpu.max"
36
+ cgroupv2CpuWeightFile = "cpu.weight"
37
+ )
34
38
35
39
// cgroupV2impl implements the CgroupManager interface
36
40
// for cgroup v2.
@@ -100,14 +104,14 @@ func (c *cgroupV2impl) GetCgroupConfig(name CgroupName, resource v1.ResourceName
100
104
101
105
func (c * cgroupV2impl ) getCgroupCPUConfig (cgroupPath string ) (* ResourceConfig , error ) {
102
106
var cpuLimitStr , cpuPeriodStr string
103
- cpuLimitAndPeriod , err := fscommon .GetCgroupParamString (cgroupPath , "cpu.max" )
107
+ cpuLimitAndPeriod , err := fscommon .GetCgroupParamString (cgroupPath , cgroupv2CpuMaxFile )
104
108
if err != nil {
105
- return nil , fmt .Errorf ("failed to read cpu.max file for cgroup %v: %w" , cgroupPath , err )
109
+ return nil , fmt .Errorf ("failed to read %s file for cgroup %v: %w" , cgroupv2CpuMaxFile , cgroupPath , err )
106
110
}
107
111
numItems , errScan := fmt .Sscanf (cpuLimitAndPeriod , "%s %s" , & cpuLimitStr , & cpuPeriodStr )
108
112
if errScan != nil || numItems != 2 {
109
- return nil , fmt .Errorf ("failed to correctly parse content of cpu.max file ('%s') for cgroup %v: %w" ,
110
- cpuLimitAndPeriod , cgroupPath , errScan )
113
+ return nil , fmt .Errorf ("failed to correctly parse content of %s file ('%s') for cgroup %v: %w" ,
114
+ cgroupv2CpuMaxFile , cpuLimitAndPeriod , cgroupPath , errScan )
111
115
}
112
116
cpuLimit := int64 (- 1 )
113
117
if cpuLimitStr != Cgroup2MaxCpuLimit {
@@ -120,7 +124,7 @@ func (c *cgroupV2impl) getCgroupCPUConfig(cgroupPath string) (*ResourceConfig, e
120
124
if errPeriod != nil {
121
125
return nil , fmt .Errorf ("failed to convert CPU period as integer for cgroup %v: %w" , cgroupPath , errPeriod )
122
126
}
123
- cpuWeight , errWeight := fscommon .GetCgroupParamUint (cgroupPath , "cpu.weight" )
127
+ cpuWeight , errWeight := fscommon .GetCgroupParamUint (cgroupPath , cgroupv2CpuWeightFile )
124
128
if errWeight != nil {
125
129
return nil , fmt .Errorf ("failed to read CPU weight for cgroup %v: %w" , cgroupPath , errWeight )
126
130
}
0 commit comments