Skip to content

Commit 3a1b0f2

Browse files
committed
kubelet/kuberuntime: switch to runc/libct
runc/libcontainer/cgroups.ParseCgroupFile is a universal function; for cgroup v2 it returns path to unified in a map with "" as a key. Let's use it here, dropping cgroups dependency entirely. Amends commit e86d02b. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 847be85 commit 3a1b0f2

File tree

5 files changed

+6
-520
lines changed

5 files changed

+6
-520
lines changed

LICENSES/third_party/forked/cgroups/LICENSE

-201
This file was deleted.

pkg/kubelet/kuberuntime/kuberuntime_container_linux.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
4646
"k8s.io/kubernetes/pkg/kubelet/qos"
4747
kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
48-
cgroups "k8s.io/kubernetes/third_party/forked/cgroups"
4948
"k8s.io/utils/ptr"
5049
)
5150

@@ -354,12 +353,16 @@ var swapControllerAvailable = func() bool {
354353
p := "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"
355354
if isCgroup2UnifiedMode() {
356355
// memory.swap.max does not exist in the cgroup root, so we check /sys/fs/cgroup/<SELF>/memory.swap.max
357-
_, unified, err := cgroups.ParseCgroupFileUnified("/proc/self/cgroup")
356+
cm, err := libcontainercgroups.ParseCgroupFile("/proc/self/cgroup")
358357
if err != nil {
359358
klog.V(5).ErrorS(fmt.Errorf("failed to parse /proc/self/cgroup: %w", err), warn)
360359
return
361360
}
362-
p = filepath.Join("/sys/fs/cgroup", unified, "memory.swap.max")
361+
// Fr cgroup v2 unified hierarchy, there are no per-controller
362+
// cgroup paths, so the cm map returned by ParseCgroupFile above
363+
// has a single element where the key is empty string ("") and
364+
// the value is the cgroup path the <pid> is in.
365+
p = filepath.Join("/sys/fs/cgroup", cm[""], "memory.swap.max")
363366
}
364367
if _, err := os.Stat(p); err != nil {
365368
if !errors.Is(err, os.ErrNotExist) {
@@ -392,7 +395,6 @@ func (m swapConfigurationHelper) ConfigureLimitedSwap(lcr *runtimeapi.LinuxConta
392395

393396
containerMemoryRequest := container.Resources.Requests.Memory()
394397
swapLimit, err := calcSwapForBurstablePods(containerMemoryRequest.Value(), int64(m.machineInfo.MemoryCapacity), int64(m.machineInfo.SwapCapacity))
395-
396398
if err != nil {
397399
klog.ErrorS(err, "cannot calculate swap allocation amount; disallowing swap")
398400
m.ConfigureNoSwap(lcr)

0 commit comments

Comments
 (0)