Skip to content

Commit 1ffbf2d

Browse files
committed
rename/remove vars that collided with builtin, minor linting and cleanup
- remove / rename `max` variables, as that's now a builtin - inline some variables - suppress an unhandled error in a t.Cleanup Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent be0e520 commit 1ffbf2d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

cgroup1/pids.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ func (p *pidsController) Stat(path string, stats *v1.Metrics) error {
6666
if err != nil {
6767
return err
6868
}
69-
max, err := readUint(filepath.Join(p.Path(path), "pids.max"))
69+
pidsMax, err := readUint(filepath.Join(p.Path(path), "pids.max"))
7070
if err != nil {
7171
return err
7272
}
7373
stats.Pids = &v1.PidsStat{
7474
Current: current,
75-
Limit: max,
75+
Limit: pidsMax,
7676
}
7777
return nil
7878
}

cgroup2/cpuv2_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ func TestCgroupv2CpuStats(t *testing.T) {
3636
period uint64 = 8000
3737
weight uint64 = 100
3838
)
39-
max := "10000 8000"
40-
res := Resources{
39+
40+
c, err := NewManager(defaultCgroup2Path, groupPath, &Resources{
4141
CPU: &CPU{
4242
Weight: &weight,
4343
Max: NewCPUMax(&quota, &period),
4444
Cpus: "0",
4545
Mems: "0",
4646
},
47-
}
48-
c, err := NewManager(defaultCgroup2Path, groupPath, &res)
47+
})
4948
require.NoError(t, err, "failed to init new cgroup manager")
5049
t.Cleanup(func() {
51-
os.Remove(c.path)
50+
_ = os.Remove(c.path)
5251
})
5352

5453
checkFileContent(t, c.path, "cpu.weight", strconv.FormatUint(weight, 10))
55-
checkFileContent(t, c.path, "cpu.max", max)
54+
checkFileContent(t, c.path, "cpu.max", "10000 8000")
5655
checkFileContent(t, c.path, "cpuset.cpus", "0")
5756
checkFileContent(t, c.path, "cpuset.mems", "0")
5857
}
@@ -61,8 +60,7 @@ func TestSystemdCgroupCpuController(t *testing.T) {
6160
checkCgroupMode(t)
6261
group := fmt.Sprintf("testing-cpu-%d.scope", os.Getpid())
6362
var weight uint64 = 100
64-
res := Resources{CPU: &CPU{Weight: &weight}}
65-
c, err := NewSystemd("", group, os.Getpid(), &res)
63+
c, err := NewSystemd("", group, os.Getpid(), &Resources{CPU: &CPU{Weight: &weight}})
6664
require.NoError(t, err, "failed to init new cgroup systemd manager")
6765

6866
checkFileContent(t, c.path, "cpu.weight", strconv.FormatUint(weight, 10))
@@ -75,13 +73,12 @@ func TestSystemdCgroupCpuController_NilWeight(t *testing.T) {
7573
var quota int64 = 10000
7674
var period uint64 = 8000
7775
cpuMax := NewCPUMax(&quota, &period)
78-
res := Resources{
76+
_, err := NewSystemd("/", group, -1, &Resources{
7977
CPU: &CPU{
8078
Weight: nil,
8179
Max: cpuMax,
8280
},
83-
}
84-
_, err := NewSystemd("/", group, -1, &res)
81+
})
8582
require.NoError(t, err, "failed to init new cgroup systemd manager")
8683
}
8784

0 commit comments

Comments
 (0)