Skip to content

Commit

Permalink
Added cgroup type
Browse files Browse the repository at this point in the history
Add domain threaded and domain invalid cgroup type.

Signed-off-by: yaoyinnan <[email protected]>
  • Loading branch information
yaoyinnan committed Jan 27, 2024
1 parent d131035 commit 7519b18
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cgroup2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"github.com/containerd/cgroups/v3/cgroup2/stats"

systemdDbus "github.com/coreos/go-systemd/v22/dbus"
"github.com/godbus/dbus/v5"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -242,8 +240,10 @@ func setResources(path string, resources *Resources) error {
type CgroupType string

const (
Domain CgroupType = "domain"
Threaded CgroupType = "threaded"
Domain CgroupType = "domain"
DomainThreaded CgroupType = "domain threaded"
DomainInvalid CgroupType = "domain invalid"
Threaded CgroupType = "threaded"
)

func (c *Manager) GetType() (CgroupType, error) {
Expand Down
33 changes: 26 additions & 7 deletions cgroup2/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
Expand Down Expand Up @@ -283,20 +282,40 @@ func TestCgroupType(t *testing.T) {
checkCgroupMode(t)
manager, err := NewManager(defaultCgroup2Path, "/test-type", ToResources(&specs.LinuxResources{}))
require.NoError(t, err)
t.Cleanup(func() {
_ = manager.Delete()
})
submanager, err := NewManager(defaultCgroup2Path, "/test-type/sub", ToResources(&specs.LinuxResources{}))
require.NoError(t, err)

// Check initial type is domain
cgType, err := manager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, Domain)

// Swap to threaded
require.NoError(t, manager.SetType(Threaded))
// Swap sub cgroup to threaded
require.NoError(t, submanager.SetType(Threaded))

cgType, err = manager.GetType()
// Check sub cgroup type is threaded
cgType, err = submanager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, Threaded)

// Check parent cgroup type is domain threaded
cgType, err = manager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, DomainThreaded)

subsubmanager, err := NewManager(defaultCgroup2Path, "/test-type/sub/sub", ToResources(&specs.LinuxResources{}))
require.NoError(t, err)

// Check sub cgroup type is domain invalid
cgType, err = submanager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, DomainInvalid)

t.Cleanup(func() {
_ = subsubmanager.Delete()
_ = submanager.Delete()
_ = manager.Delete()
})
}

func TestCgroupv2PSIStats(t *testing.T) {
Expand Down

0 comments on commit 7519b18

Please sign in to comment.