Skip to content

Commit f8479b6

Browse files
committed
deps: switch to opencontainers/cgroups
The new opencontainers/cgroups repo used to be part of runc. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 3753629 commit f8479b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1164
-1383
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/moby/sys/capability v0.4.0
2929
github.com/onsi/ginkgo/v2 v2.23.0
3030
github.com/onsi/gomega v1.36.2
31+
github.com/opencontainers/cgroups v0.0.1
3132
github.com/opencontainers/go-digest v1.0.0
3233
github.com/opencontainers/image-spec v1.1.1
3334
github.com/opencontainers/runc v1.2.5

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ github.com/onsi/ginkgo/v2 v2.23.0 h1:FA1xjp8ieYDzlgS5ABTpdUDB7wtngggONc8a7ku2NqQ
252252
github.com/onsi/ginkgo/v2 v2.23.0/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM=
253253
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
254254
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
255+
github.com/opencontainers/cgroups v0.0.1 h1:MXjMkkFpKv6kpuirUa4USFBas573sSAY082B4CiHEVA=
256+
github.com/opencontainers/cgroups v0.0.1/go.mod h1:s8lktyhlGUqM7OSRL5P7eAW6Wb+kWPNvt4qvVfzA5vs=
255257
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
256258
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
257259
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=

pkg/cgroups/blkio_linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/opencontainers/runc/libcontainer/cgroups"
15-
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
16-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
17-
"github.com/opencontainers/runc/libcontainer/configs"
14+
"github.com/opencontainers/cgroups"
15+
"github.com/opencontainers/cgroups/fs"
16+
"github.com/opencontainers/cgroups/fs2"
1817
)
1918

2019
type linuxBlkioHandler struct {
@@ -26,7 +25,7 @@ func getBlkioHandler() *linuxBlkioHandler {
2625
}
2726

2827
// Apply set the specified constraints
29-
func (c *linuxBlkioHandler) Apply(ctr *CgroupControl, res *configs.Resources) error {
28+
func (c *linuxBlkioHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
3029
if ctr.cgroup2 {
3130
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
3231
if err != nil {

pkg/cgroups/cgroups_linux.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import (
2323
"github.com/containers/storage/pkg/unshare"
2424
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
2525
"github.com/godbus/dbus/v5"
26-
"github.com/opencontainers/runc/libcontainer/cgroups"
27-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
28-
"github.com/opencontainers/runc/libcontainer/configs"
26+
"github.com/opencontainers/cgroups"
27+
"github.com/opencontainers/cgroups/fs2"
2928
"github.com/sirupsen/logrus"
3029
"golang.org/x/sys/unix"
3130
)
@@ -45,7 +44,7 @@ var (
4544
// CgroupControl controls a cgroup hierarchy
4645
type CgroupControl struct {
4746
cgroup2 bool
48-
config *configs.Cgroup
47+
config *cgroups.Cgroup
4948
systemd bool
5049
// List of additional cgroup subsystems joined that
5150
// do not have a custom handler.
@@ -59,7 +58,7 @@ type controller struct {
5958

6059
type controllerHandler interface {
6160
Create(*CgroupControl) (bool, error)
62-
Apply(*CgroupControl, *configs.Resources) error
61+
Apply(*CgroupControl, *cgroups.Resources) error
6362
Destroy(*CgroupControl) error
6463
Stat(*CgroupControl, *cgroups.Stats) error
6564
}
@@ -298,14 +297,14 @@ func readFileByKeyAsUint64(path, key string) (uint64, error) {
298297
}
299298

300299
// New creates a new cgroup control
301-
func New(path string, resources *configs.Resources) (*CgroupControl, error) {
300+
func New(path string, resources *cgroups.Resources) (*CgroupControl, error) {
302301
cgroup2, err := IsCgroup2UnifiedMode()
303302
if err != nil {
304303
return nil, err
305304
}
306305
control := &CgroupControl{
307306
cgroup2: cgroup2,
308-
config: &configs.Cgroup{
307+
config: &cgroups.Cgroup{
309308
Path: path,
310309
Resources: resources,
311310
},
@@ -327,15 +326,15 @@ func New(path string, resources *configs.Resources) (*CgroupControl, error) {
327326
}
328327

329328
// NewSystemd creates a new cgroup control
330-
func NewSystemd(path string, resources *configs.Resources) (*CgroupControl, error) {
329+
func NewSystemd(path string, resources *cgroups.Resources) (*CgroupControl, error) {
331330
cgroup2, err := IsCgroup2UnifiedMode()
332331
if err != nil {
333332
return nil, err
334333
}
335334
control := &CgroupControl{
336335
cgroup2: cgroup2,
337336
systemd: true,
338-
config: &configs.Cgroup{
337+
config: &cgroups.Cgroup{
339338
Path: path,
340339
Resources: resources,
341340
Rootless: unshare.IsRootless(),
@@ -354,7 +353,7 @@ func Load(path string) (*CgroupControl, error) {
354353
control := &CgroupControl{
355354
cgroup2: cgroup2,
356355
systemd: false,
357-
config: &configs.Cgroup{
356+
config: &cgroups.Cgroup{
358357
Path: path,
359358
},
360359
}
@@ -486,7 +485,7 @@ func (c *CgroupControl) DeleteByPath(path string) error {
486485
}
487486

488487
// Update updates the cgroups
489-
func (c *CgroupControl) Update(resources *configs.Resources) error {
488+
func (c *CgroupControl) Update(resources *cgroups.Resources) error {
490489
for _, h := range handlers {
491490
if err := h.Apply(c, resources); err != nil {
492491
return err

pkg/cgroups/cgroups_linux_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/containers/storage/pkg/unshare"
15-
"github.com/opencontainers/runc/libcontainer/configs"
15+
"github.com/opencontainers/cgroups"
1616
)
1717

1818
func TestCreated(t *testing.T) {
@@ -21,7 +21,7 @@ func TestCreated(t *testing.T) {
2121
return
2222
}
2323

24-
var resources configs.Resources
24+
var resources cgroups.Resources
2525
cgr, err := New("machine.slice", &resources)
2626
if err != nil {
2727
t.Fatal(err)
@@ -45,15 +45,15 @@ func TestResources(t *testing.T) {
4545
return
4646
}
4747

48-
wtDevices := []*configs.WeightDevice{}
49-
devices := []*configs.ThrottleDevice{}
50-
dev1 := configs.NewThrottleDevice(1, 3, 2097152)
51-
dev2 := configs.NewThrottleDevice(3, 10, 2097152)
52-
dev3 := configs.NewWeightDevice(5, 9, 500, 0)
48+
wtDevices := []*cgroups.WeightDevice{}
49+
devices := []*cgroups.ThrottleDevice{}
50+
dev1 := cgroups.NewThrottleDevice(1, 3, 2097152)
51+
dev2 := cgroups.NewThrottleDevice(3, 10, 2097152)
52+
dev3 := cgroups.NewWeightDevice(5, 9, 500, 0)
5353
devices = append(devices, dev1, dev2)
5454
wtDevices = append(wtDevices, dev3)
5555

56-
var resources configs.Resources
56+
var resources cgroups.Resources
5757
resources.CpuPeriod = 100000
5858
resources.CpuQuota = 100000
5959
resources.CpuShares = 100
@@ -151,8 +151,8 @@ func TestResources(t *testing.T) {
151151
t.Fatal(err)
152152
}
153153

154-
resources.BlkioThrottleReadBpsDevice = []*configs.ThrottleDevice{devices[0]}
155-
resources.BlkioThrottleWriteBpsDevice = []*configs.ThrottleDevice{devices[1]}
154+
resources.BlkioThrottleReadBpsDevice = []*cgroups.ThrottleDevice{devices[0]}
155+
resources.BlkioThrottleWriteBpsDevice = []*cgroups.ThrottleDevice{devices[1]}
156156
resources.BlkioWeightDevice = wtDevices
157157

158158
// machine.slice = parent, libpod_pod_ID = path

pkg/cgroups/cpu_linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
"path/filepath"
99
"strconv"
1010

11-
"github.com/opencontainers/runc/libcontainer/cgroups"
12-
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
13-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
14-
"github.com/opencontainers/runc/libcontainer/configs"
11+
"github.com/opencontainers/cgroups"
12+
"github.com/opencontainers/cgroups/fs"
13+
"github.com/opencontainers/cgroups/fs2"
1514
)
1615

1716
type linuxCPUHandler struct {
@@ -23,7 +22,7 @@ func getCPUHandler() *linuxCPUHandler {
2322
}
2423

2524
// Apply set the specified constraints
26-
func (c *linuxCPUHandler) Apply(ctr *CgroupControl, res *configs.Resources) error {
25+
func (c *linuxCPUHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
2726
if ctr.cgroup2 {
2827
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
2928
if err != nil {

pkg/cgroups/cpuset_linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ package cgroups
55
import (
66
"path/filepath"
77

8-
"github.com/opencontainers/runc/libcontainer/cgroups"
9-
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
10-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
11-
"github.com/opencontainers/runc/libcontainer/configs"
8+
"github.com/opencontainers/cgroups"
9+
"github.com/opencontainers/cgroups/fs"
10+
"github.com/opencontainers/cgroups/fs2"
1211
)
1312

1413
type linuxCpusetHandler struct {
@@ -20,7 +19,7 @@ func getCpusetHandler() *linuxCpusetHandler {
2019
}
2120

2221
// Apply set the specified constraints
23-
func (c *linuxCpusetHandler) Apply(ctr *CgroupControl, res *configs.Resources) error {
22+
func (c *linuxCpusetHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
2423
if ctr.cgroup2 {
2524
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
2625
if err != nil {

pkg/cgroups/memory_linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"path/filepath"
88
"strconv"
99

10-
"github.com/opencontainers/runc/libcontainer/cgroups"
11-
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
12-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
13-
"github.com/opencontainers/runc/libcontainer/configs"
10+
"github.com/opencontainers/cgroups"
11+
"github.com/opencontainers/cgroups/fs"
12+
"github.com/opencontainers/cgroups/fs2"
1413
)
1514

1615
type linuxMemHandler struct {
@@ -22,7 +21,7 @@ func getMemoryHandler() *linuxMemHandler {
2221
}
2322

2423
// Apply set the specified constraints
25-
func (c *linuxMemHandler) Apply(ctr *CgroupControl, res *configs.Resources) error {
24+
func (c *linuxMemHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
2625
if ctr.cgroup2 {
2726
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
2827
if err != nil {

pkg/cgroups/pids_linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ package cgroups
55
import (
66
"path/filepath"
77

8-
"github.com/opencontainers/runc/libcontainer/cgroups"
9-
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
10-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
11-
"github.com/opencontainers/runc/libcontainer/configs"
8+
"github.com/opencontainers/cgroups"
9+
"github.com/opencontainers/cgroups/fs"
10+
"github.com/opencontainers/cgroups/fs2"
1211
)
1312

1413
type linuxPidHandler struct {
@@ -20,7 +19,7 @@ func getPidsHandler() *linuxPidHandler {
2019
}
2120

2221
// Apply set the specified constraints
23-
func (c *linuxPidHandler) Apply(ctr *CgroupControl, res *configs.Resources) error {
22+
func (c *linuxPidHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
2423
if ctr.cgroup2 {
2524
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
2625
if err != nil {

pkg/cgroups/systemd_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414

1515
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
1616
"github.com/godbus/dbus/v5"
17-
"github.com/opencontainers/runc/libcontainer/configs"
17+
"github.com/opencontainers/cgroups"
1818
)
1919

2020
type BlkioDev struct {
2121
Device string
2222
Bytes uint64
2323
}
2424

25-
func systemdCreate(resources *configs.Resources, path string, c *systemdDbus.Conn) error {
25+
func systemdCreate(resources *cgroups.Resources, path string, c *systemdDbus.Conn) error {
2626
slice, name := filepath.Split(path)
2727
slice = strings.TrimSuffix(slice, "/")
2828

@@ -150,7 +150,7 @@ func systemdDestroyConn(path string, c *systemdDbus.Conn) error {
150150
return nil
151151
}
152152

153-
func resourcesToProps(res *configs.Resources, v2 bool) (map[string]uint64, map[string]string, map[string][]byte, map[string]int64, map[string][]BlkioDev, error) {
153+
func resourcesToProps(res *cgroups.Resources, v2 bool) (map[string]uint64, map[string]string, map[string][]byte, map[string]int64, map[string][]BlkioDev, error) {
154154
bMap := make(map[string][]byte)
155155
// this array is not used but will be once more resource limits are added
156156
sMap := make(map[string]string)

0 commit comments

Comments
 (0)