Skip to content

Commit

Permalink
cgroup: upgrade to containerd/cgroup/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
shankerwangmiao committed Jan 11, 2025
1 parent 236a082 commit 07fb03d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
github.com/boltdb/bolt v1.3.1
github.com/codeskyblue/go-sh v0.0.0-20200712050446-30169cf553fe
github.com/containerd/cgroups v1.1.0
github.com/containerd/cgroups/v3 v3.0.5
github.com/dennwc/btrfs v0.0.0-20241002142654-12ae127e0bf6
github.com/dgraph-io/badger/v2 v2.2007.4
github.com/docker/go-units v0.5.0
Expand Down
11 changes: 6 additions & 5 deletions worker/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

"golang.org/x/sys/unix"

cgv1 "github.com/containerd/cgroups"
cgv2 "github.com/containerd/cgroups/v2"
cgroups "github.com/containerd/cgroups/v3"

Check failure on line 15 in worker/cgroup.go

View workflow job for this annotation

GitHub Actions / Test

missing go.sum entry for module providing package github.com/containerd/cgroups/v3 (imported by github.com/tuna/tunasync/worker); to add:
cgv1 "github.com/containerd/cgroups/v3/cgroup1"

Check failure on line 16 in worker/cgroup.go

View workflow job for this annotation

GitHub Actions / Test

missing go.sum entry for module providing package github.com/containerd/cgroups/v3/cgroup1 (imported by github.com/tuna/tunasync/worker); to add:
cgv2 "github.com/containerd/cgroups/v3/cgroup2"

Check failure on line 17 in worker/cgroup.go

View workflow job for this annotation

GitHub Actions / Test

missing go.sum entry for module providing package github.com/containerd/cgroups/v3/cgroup2 (imported by github.com/tuna/tunasync/worker); to add:
"github.com/moby/moby/pkg/reexec"
contspecs "github.com/opencontainers/runtime-spec/specs-go"
)
Expand Down Expand Up @@ -83,7 +84,7 @@ func initCgroup(cfg *cgroupConfig) error {
baseGroup = filepath.Join("/", baseGroup)
}

cfg.isUnified = cgv1.Mode() == cgv1.Unified
cfg.isUnified = cgroups.Mode() == cgroups.Unified

if cfg.isUnified {
logger.Debugf("Cgroup V2 detected")
Expand All @@ -98,7 +99,7 @@ func initCgroup(cfg *cgroupConfig) error {
logger.Infof("Using cgroup path: %s", g)

var err error
if cfg.cgMgrV2, err = cgv2.LoadManager("/sys/fs/cgroup", g); err != nil {
if cfg.cgMgrV2, err = cgv2.Load(g); err != nil {
return err
}
if baseGroup == "" {
Expand Down Expand Up @@ -167,7 +168,7 @@ func initCgroup(cfg *cgroupConfig) error {
}
logger.Infof("Loading cgroup")
var err error
if cfg.cgMgrV1, err = cgv1.Load(cgv1.V1, pather, func(cfg *cgv1.InitConfig) error {
if cfg.cgMgrV1, err = cgv1.Load(pather, func(cfg *cgv1.InitConfig) error {
cfg.InitCheck = cgv1.AllowAny
return nil
}); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions worker/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"
"time"

cgv1 "github.com/containerd/cgroups"
cgv2 "github.com/containerd/cgroups/v2"
cgv1 "github.com/containerd/cgroups/v3/cgroup1"
cgv2 "github.com/containerd/cgroups/v3/cgroup2"
units "github.com/docker/go-units"
"github.com/moby/moby/pkg/reexec"

Expand Down Expand Up @@ -250,7 +250,7 @@ sleep 30
if cgcf.Group == "" {
wkrg, err := cgv2.NestedGroupPath("")
So(err, ShouldBeNil)
wkrMgr, err := cgv2.LoadManager("/sys/fs/cgroup", wkrg)
wkrMgr, err := cgv2.Load(wkrg)
allCtrls, err := wkrMgr.Controllers()
So(err, ShouldBeNil)
err = wkrMgr.ToggleControllers(allCtrls, cgv2.Disable)
Expand Down Expand Up @@ -290,7 +290,7 @@ sleep 30
return path, err
}
})(cgv1.NestedPath(""))
wkrMgr, err := cgv1.Load(cgv1.V1, pather, func(cfg *cgv1.InitConfig) error {
wkrMgr, err := cgv1.Load(pather, func(cfg *cgv1.InitConfig) error {
cfg.InitCheck = cgv1.AllowAny
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"

"github.com/BurntSushi/toml"
cgv1 "github.com/containerd/cgroups"
cgv2 "github.com/containerd/cgroups/v2"
cgv1 "github.com/containerd/cgroups/v3/cgroup1"
cgv2 "github.com/containerd/cgroups/v3/cgroup2"
units "github.com/docker/go-units"
"github.com/imdario/mergo"
)
Expand Down
2 changes: 1 addition & 1 deletion worker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/codeskyblue/go-sh"
cgv1 "github.com/containerd/cgroups"
cgv1 "github.com/containerd/cgroups/v3/cgroup1"
"github.com/moby/moby/pkg/reexec"
"golang.org/x/sys/unix"
)
Expand Down

0 comments on commit 07fb03d

Please sign in to comment.