diff --git a/src/runtime/pkg/resourcecontrol/utils.go b/src/runtime/pkg/resourcecontrol/utils.go index 6fafe2d6a0..835cb54c47 100644 --- a/src/runtime/pkg/resourcecontrol/utils.go +++ b/src/runtime/pkg/resourcecontrol/utils.go @@ -7,6 +7,7 @@ package resourcecontrol import ( "fmt" + "strings" "github.com/opencontainers/runc/libcontainer/devices" "github.com/opencontainers/runtime-spec/specs-go" @@ -57,3 +58,20 @@ func DeviceToLinuxDevice(device string) (specs.LinuxDeviceCgroup, error) { Access: string(dev.Permissions), }, nil } + +func IsSystemdCgroup(cgroupPath string) bool { + + // If we are utilizing systemd to manage cgroups, we expect to receive a path + // in the format slice:scopeprefix:name. A typical example would be: + // + // system.slice:docker:6b4c4a4d0cc2a12c529dcb13a2b8e438dfb3b2a6af34d548d7d + // + // Based on this, let's split by the ':' delimiter and verify that the first + // section has .slice as a suffix. + parts := strings.Split(cgroupPath, ":") + if len(parts) == 3 && strings.HasSuffix(parts[0], ".slice") { + return true + } + + return false +} diff --git a/src/runtime/pkg/resourcecontrol/utils_linux.go b/src/runtime/pkg/resourcecontrol/utils_linux.go index 7a83db8f00..73d77dc235 100644 --- a/src/runtime/pkg/resourcecontrol/utils_linux.go +++ b/src/runtime/pkg/resourcecontrol/utils_linux.go @@ -43,23 +43,6 @@ func ValidCgroupPath(path string, systemdCgroup bool) (string, error) { return filepath.Join(DefaultResourceControllerID, filepath.Clean("/"+path)), nil } -func IsSystemdCgroup(cgroupPath string) bool { - - // If we are utilizing systemd to manage cgroups, we expect to receive a path - // in the format slice:scopeprefix:name. A typical example would be: - // - // system.slice:docker:6b4c4a4d0cc2a12c529dcb13a2b8e438dfb3b2a6af34d548d7d - // - // Based on this, let's split by the ':' delimiter and verify that the first - // section has .slice as a suffix. - parts := strings.Split(cgroupPath, ":") - if len(parts) == 3 && strings.HasSuffix(parts[0], ".slice") { - return true - } - - return false -} - func newProperty(name string, units interface{}) systemdDbus.Property { return systemdDbus.Property{ Name: name,