From 8509876c898f7150a8a7c052a1c605a31585a7ec Mon Sep 17 00:00:00 2001 From: Kitt Hsu Date: Wed, 1 Jun 2022 02:19:25 +0000 Subject: [PATCH] fix cgroup path prefix for different runtime while using systemd as driver. --- pkg/runtime/runtime.go | 2 +- pkg/utils/cgroup/cgroup.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 135adc8b7..19440e838 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -164,7 +164,7 @@ func (m *containerRuntimeManager) getCgroupName(pod *v1.Pod, containerID string) switch m.cgroupDriver { case "systemd": - return fmt.Sprintf("%s/%s-%s.scope", cgroupName.ToSystemd(), m.runtimeName, containerID), nil + return fmt.Sprintf("%s/%s-%s.scope", cgroupName.ToSystemd(), cgroup.SystemdPathPrefixOfRuntime(m.runtimeName), containerID), nil case "cgroupfs": return fmt.Sprintf("%s/%s", cgroupName.ToCgroupfs(), containerID), nil default: diff --git a/pkg/utils/cgroup/cgroup.go b/pkg/utils/cgroup/cgroup.go index 38ce08dc0..048a524a3 100644 --- a/pkg/utils/cgroup/cgroup.go +++ b/pkg/utils/cgroup/cgroup.go @@ -6,6 +6,8 @@ import ( "strings" cgroupsystemd "github.com/opencontainers/runc/libcontainer/cgroups/systemd" + + "k8s.io/klog" ) // CgroupName is the abstract name of a cgroup prior to any driver specific conversion. @@ -66,3 +68,15 @@ func escapeSystemdCgroupName(part string) string { func (cgroupName CgroupName) ToCgroupfs() string { return "/" + path.Join(cgroupName...) } + +func SystemdPathPrefixOfRuntime(runtimeName string) string { + switch runtimeName { + case "cri-o": + return "crio" + case "containerd": + return "cri-containerd" + default: + klog.Infof("prefix of container runtime %s was not tested. Maybe not correct!", runtimeName) + return runtimeName + } +}