Skip to content

Commit 2e3b895

Browse files
authored
Merge pull request kubernetes#130363 from mutokrm/style-const
Style: use const rather than string in cgroup_v2
2 parents 65321bf + a933481 commit 2e3b895

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/kubelet/cm/cgroup_v2_manager_linux.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import (
3030
cmutil "k8s.io/kubernetes/pkg/kubelet/cm/util"
3131
)
3232

33-
const cgroupv2MemLimitFile string = "memory.max"
33+
const (
34+
cgroupv2MemLimitFile = "memory.max"
35+
cgroupv2CpuMaxFile = "cpu.max"
36+
cgroupv2CpuWeightFile = "cpu.weight"
37+
)
3438

3539
// cgroupV2impl implements the CgroupManager interface
3640
// for cgroup v2.
@@ -100,14 +104,14 @@ func (c *cgroupV2impl) GetCgroupConfig(name CgroupName, resource v1.ResourceName
100104

101105
func (c *cgroupV2impl) getCgroupCPUConfig(cgroupPath string) (*ResourceConfig, error) {
102106
var cpuLimitStr, cpuPeriodStr string
103-
cpuLimitAndPeriod, err := fscommon.GetCgroupParamString(cgroupPath, "cpu.max")
107+
cpuLimitAndPeriod, err := fscommon.GetCgroupParamString(cgroupPath, cgroupv2CpuMaxFile)
104108
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)
106110
}
107111
numItems, errScan := fmt.Sscanf(cpuLimitAndPeriod, "%s %s", &cpuLimitStr, &cpuPeriodStr)
108112
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)
111115
}
112116
cpuLimit := int64(-1)
113117
if cpuLimitStr != Cgroup2MaxCpuLimit {
@@ -120,7 +124,7 @@ func (c *cgroupV2impl) getCgroupCPUConfig(cgroupPath string) (*ResourceConfig, e
120124
if errPeriod != nil {
121125
return nil, fmt.Errorf("failed to convert CPU period as integer for cgroup %v: %w", cgroupPath, errPeriod)
122126
}
123-
cpuWeight, errWeight := fscommon.GetCgroupParamUint(cgroupPath, "cpu.weight")
127+
cpuWeight, errWeight := fscommon.GetCgroupParamUint(cgroupPath, cgroupv2CpuWeightFile)
124128
if errWeight != nil {
125129
return nil, fmt.Errorf("failed to read CPU weight for cgroup %v: %w", cgroupPath, errWeight)
126130
}

0 commit comments

Comments
 (0)