Skip to content

Commit c237c7e

Browse files
authored
Merge branch 'main' into cpus
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
2 parents c0349f4 + bce3c7e commit c237c7e

18 files changed

+250
-192
lines changed

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 10

.github/workflows/ci.yml

+16-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
# Checkout repos
2424
#
2525
- name: Checkout cgroups
26-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2727
with:
2828
path: src/github.com/containerd/cgroups
2929
fetch-depth: 25
@@ -32,9 +32,9 @@ jobs:
3232
# Install Go
3333
#
3434
- name: Install Go
35-
uses: actions/setup-go@v4
35+
uses: actions/setup-go@v5
3636
with:
37-
go-version: '1.20.x'
37+
go-version: '1.22.x'
3838
cache-dependency-path: src/github.com/containerd/cgroups
3939

4040
- name: Project checks
@@ -50,24 +50,24 @@ jobs:
5050

5151
strategy:
5252
matrix:
53-
go-version: [1.19.x, 1.20.x]
53+
go-version: [1.22.x, 1.23.x]
5454

5555
steps:
5656
- name: Checkout cgroups
57-
uses: actions/checkout@v3
57+
uses: actions/checkout@v4
5858
with:
5959
path: src/github.com/containerd/cgroups
6060

6161
- name: Install Go
62-
uses: actions/setup-go@v4
62+
uses: actions/setup-go@v5
6363
with:
64-
go-version: ${{ matrix.go }}
64+
go-version: ${{ matrix.go-version }}
6565
cache-dependency-path: src/github.com/containerd/cgroups
6666

6767
- name: golangci-lint
68-
uses: golangci/golangci-lint-action@v3
68+
uses: golangci/golangci-lint-action@v6
6969
with:
70-
version: v1.51.1
70+
version: v1.62.0
7171
args: --verbose
7272
working-directory: src/github.com/containerd/cgroups
7373

@@ -78,21 +78,21 @@ jobs:
7878

7979
strategy:
8080
matrix:
81-
go-version: [1.19.x, 1.20.x]
81+
go-version: [1.22.x, 1.23.x]
8282
# Ubuntu-20.04 has cgroups v1 default; Ubuntu-22.04 has cgroups v2 default.
8383
os: [ubuntu-20.04, ubuntu-22.04]
8484

8585
runs-on: ${{ matrix.os }}
8686
steps:
8787
- name: Checkout cgroups
88-
uses: actions/checkout@v3
88+
uses: actions/checkout@v4
8989
with:
9090
path: src/github.com/containerd/cgroups
9191

9292
- name: Install Go
93-
uses: actions/setup-go@v4
93+
uses: actions/setup-go@v5
9494
with:
95-
go-version: ${{ matrix.go }}
95+
go-version: ${{ matrix.go-version }}
9696
# Disable Go caching feature when compiling across Linux distributions due to collisions until https://github.com/actions/setup-go/issues/368 is resolved.
9797
cache: false
9898

@@ -111,14 +111,14 @@ jobs:
111111

112112
steps:
113113
- name: Checkout cgroups
114-
uses: actions/checkout@v3
114+
uses: actions/checkout@v4
115115
with:
116116
path: src/github.com/containerd/cgroups
117117

118118
- name: Install Go
119-
uses: actions/setup-go@v4
119+
uses: actions/setup-go@v5
120120
with:
121-
go-version: '1.19.x'
121+
go-version: '1.22.x'
122122
cache-dependency-path: src/github.com/containerd/cgroups
123123

124124
- name: Set env

cgroup1/cgroup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (c *cgroup) AddTask(process Process, subsystems ...Name) error {
196196
return c.add(process, cgroupTasks, subsystems...)
197197
}
198198

199-
// writeCgroupsProcs writes to the file, but retries on EINVAL.
199+
// writeCgroupProcs writes to the file, but retries on EINVAL.
200200
func writeCgroupProcs(path string, content []byte, perm fs.FileMode) error {
201201
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, perm)
202202
if err != nil {

cgroup1/memory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func getMemorySettings(resources *specs.LinuxResources) []memorySettings {
433433
},
434434
{
435435
name: "kmem.limit_in_bytes",
436-
value: mem.Kernel,
436+
value: mem.Kernel, //nolint:staticcheck // SA1019: mem.Kernel is deprecated
437437
},
438438
{
439439
name: "kmem.tcp.limit_in_bytes",

cgroup1/pids.go

+2-2
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
}

cgroup1/subsystem.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/containerd/cgroups/v3"
2423
v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
24+
"github.com/moby/sys/userns"
2525
specs "github.com/opencontainers/runtime-spec/specs-go"
2626
)
2727

@@ -60,7 +60,7 @@ func Subsystems() []Name {
6060
Blkio,
6161
Rdma,
6262
}
63-
if !cgroups.RunningInUserNS() {
63+
if !userns.RunningInUserNS() {
6464
n = append(n, Devices)
6565
}
6666
if _, err := os.Stat("/sys/kernel/mm/hugepages"); err == nil {

cgroup1/utils.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/containerd/cgroups/v3"
3030
units "github.com/docker/go-units"
31+
"github.com/moby/sys/userns"
3132
specs "github.com/opencontainers/runtime-spec/specs-go"
3233
)
3334

@@ -53,7 +54,7 @@ func defaults(root string) ([]Subsystem, error) {
5354
}
5455
// only add the devices cgroup if we are not in a user namespace
5556
// because modifications are not allowed
56-
if !cgroups.RunningInUserNS() {
57+
if !userns.RunningInUserNS() {
5758
s = append(s, NewDevices(root))
5859
}
5960
// add the hugetlb cgroup if error wasn't due to missing hugetlb
@@ -196,7 +197,7 @@ func parseKV(raw string) (string, uint64, error) {
196197
// The resulting map does not have an element for cgroup v2 unified hierarchy.
197198
// Use [cgroups.ParseCgroupFileUnified] to get the unified path.
198199
func ParseCgroupFile(path string) (map[string]string, error) {
199-
x, _, err := ParseCgroupFileUnified(path)
200+
x, _, err := cgroups.ParseCgroupFileUnified(path)
200201
return x, err
201202
}
202203

cgroup2/cpuv2_test.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,24 @@ func TestCgroupv2CpuStats(t *testing.T) {
3838
// The burst in the range [0, $quota].
3939
burst uint64 = 1000
4040
)
41-
max := "10000 8000"
42-
res := Resources{
41+
42+
c, err := NewManager(defaultCgroup2Path, groupPath, &Resources{
4343
CPU: &CPU{
4444
Weight: &weight,
4545
Burst: &burst,
4646
Max: NewCPUMax(&quota, &period),
4747
Cpus: "0",
4848
Mems: "0",
4949
},
50-
}
51-
c, err := NewManager(defaultCgroup2Path, groupPath, &res)
50+
})
5251
require.NoError(t, err, "failed to init new cgroup manager")
5352
t.Cleanup(func() {
54-
os.Remove(c.path)
53+
_ = os.Remove(c.path)
5554
})
5655

5756
checkFileContent(t, c.path, "cpu.weight", strconv.FormatUint(weight, 10))
58-
checkFileContent(t, c.path, "cpu.max", max)
5957
checkFileContent(t, c.path, "cpu.max.burst", strconv.FormatUint(burst, 10))
58+
checkFileContent(t, c.path, "cpu.max", "10000 8000")
6059
checkFileContent(t, c.path, "cpuset.cpus", "0")
6160
checkFileContent(t, c.path, "cpuset.mems", "0")
6261
}
@@ -87,8 +86,7 @@ func TestSystemdCgroupCpuController(t *testing.T) {
8786
checkCgroupMode(t)
8887
group := fmt.Sprintf("testing-cpu-%d.scope", os.Getpid())
8988
var weight uint64 = 100
90-
res := Resources{CPU: &CPU{Weight: &weight}}
91-
c, err := NewSystemd("", group, os.Getpid(), &res)
89+
c, err := NewSystemd("", group, os.Getpid(), &Resources{CPU: &CPU{Weight: &weight}})
9290
require.NoError(t, err, "failed to init new cgroup systemd manager")
9391

9492
checkFileContent(t, c.path, "cpu.weight", strconv.FormatUint(weight, 10))
@@ -101,13 +99,12 @@ func TestSystemdCgroupCpuController_NilWeight(t *testing.T) {
10199
var quota int64 = 10000
102100
var period uint64 = 8000
103101
cpuMax := NewCPUMax(&quota, &period)
104-
res := Resources{
102+
_, err := NewSystemd("/", group, -1, &Resources{
105103
CPU: &CPU{
106104
Weight: nil,
107105
Max: cpuMax,
108106
},
109-
}
110-
_, err := NewSystemd("/", group, -1, &res)
107+
})
111108
require.NoError(t, err, "failed to init new cgroup systemd manager")
112109
}
113110

cgroup2/devicefilter_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ func TestDeviceFilter_Nil(t *testing.T) {
5454
// load parameters into registers
5555
0: LdXMemH dst: r2 src: r1 off: 0 imm: 0
5656
1: LdXMemW dst: r3 src: r1 off: 0 imm: 0
57-
2: RSh32Imm dst: r3 imm: 16
57+
2: RShImm32 dst: r3 imm: 16
5858
3: LdXMemW dst: r4 src: r1 off: 4 imm: 0
5959
4: LdXMemW dst: r5 src: r1 off: 8 imm: 0
6060
block-0:
6161
// return 0 (reject)
62-
5: Mov32Imm dst: r0 imm: 0
62+
5: MovImm32 dst: r0 imm: 0
6363
6: Exit
6464
`
6565
testDeviceFilter(t, nil, expected)
@@ -79,12 +79,12 @@ func TestDeviceFilter_Privileged(t *testing.T) {
7979
// load parameters into registers
8080
0: LdXMemH dst: r2 src: r1 off: 0 imm: 0
8181
1: LdXMemW dst: r3 src: r1 off: 0 imm: 0
82-
2: RSh32Imm dst: r3 imm: 16
82+
2: RShImm32 dst: r3 imm: 16
8383
3: LdXMemW dst: r4 src: r1 off: 4 imm: 0
8484
4: LdXMemW dst: r5 src: r1 off: 8 imm: 0
8585
block-0:
8686
// return 1 (accept)
87-
5: Mov32Imm dst: r0 imm: 1
87+
5: MovImm32 dst: r0 imm: 1
8888
6: Exit
8989
`
9090
testDeviceFilter(t, devices, expected)
@@ -111,19 +111,19 @@ func TestDeviceFilter_PrivilegedExceptSingleDevice(t *testing.T) {
111111
// load parameters into registers
112112
0: LdXMemH dst: r2 src: r1 off: 0 imm: 0
113113
1: LdXMemW dst: r3 src: r1 off: 0 imm: 0
114-
2: RSh32Imm dst: r3 imm: 16
114+
2: RShImm32 dst: r3 imm: 16
115115
3: LdXMemW dst: r4 src: r1 off: 4 imm: 0
116116
4: LdXMemW dst: r5 src: r1 off: 8 imm: 0
117117
block-0:
118118
// return 0 (reject) if type==b && major == 8 && minor == 0
119119
5: JNEImm dst: r2 off: -1 imm: 1 <block-1>
120120
6: JNEImm dst: r4 off: -1 imm: 8 <block-1>
121121
7: JNEImm dst: r5 off: -1 imm: 0 <block-1>
122-
8: Mov32Imm dst: r0 imm: 0
122+
8: MovImm32 dst: r0 imm: 0
123123
9: Exit
124124
block-1:
125125
// return 1 (accept)
126-
10: Mov32Imm dst: r0 imm: 1
126+
10: MovImm32 dst: r0 imm: 1
127127
11: Exit
128128
`
129129
testDeviceFilter(t, devices, expected)
@@ -159,19 +159,19 @@ func TestDeviceFilter_Weird(t *testing.T) {
159159
// load parameters into registers
160160
0: LdXMemH dst: r2 src: r1 off: 0 imm: 0
161161
1: LdXMemW dst: r3 src: r1 off: 0 imm: 0
162-
2: RSh32Imm dst: r3 imm: 16
162+
2: RShImm32 dst: r3 imm: 16
163163
3: LdXMemW dst: r4 src: r1 off: 4 imm: 0
164164
4: LdXMemW dst: r5 src: r1 off: 8 imm: 0
165165
block-0:
166166
// return 0 (reject) if type==b && major == 8 && minor == 2
167167
5: JNEImm dst: r2 off: -1 imm: 1 <block-1>
168168
6: JNEImm dst: r4 off: -1 imm: 8 <block-1>
169169
7: JNEImm dst: r5 off: -1 imm: 2 <block-1>
170-
8: Mov32Imm dst: r0 imm: 0
170+
8: MovImm32 dst: r0 imm: 0
171171
9: Exit
172172
block-1:
173173
// return 1 (accept)
174-
10: Mov32Imm dst: r0 imm: 1
174+
10: MovImm32 dst: r0 imm: 1
175175
11: Exit
176176
`
177177
testDeviceFilter(t, devices, expected)

0 commit comments

Comments
 (0)