From 82fd1e524858b8ac514d0e92a871c04f2bcb3783 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 30 Jul 2021 09:57:50 +0530 Subject: [PATCH] util: getCgroupPidsFile produces striped path when extra : present This commit uses `string.SplitN` instead of `string.Split`. The path for pids.max has extra `:` symbols in it due to which getCgroupPidsFile() splits the string into 5 tokens instead of 3 leading to loss of part of the path. As a result, the below error is reported: `Failed to get the PID limit, can not reconfigure: open /sys/fs/cgroup/pids/system.slice/containerd.service/ kubepods-besteffort-pod183b9d14_aed1_4b66_a696_da0c738bc012.slice/pids.max: no such file or directory` SplitN takes an argument n and splits the string accordingly which helps us to get the desired file path. Fixes: #2337 Co-authored-by: Yati Padia Signed-off-by: Yati Padia (cherry picked from commit 16ec97d8f75ae362c1e0f243601d39487d7c092c) --- internal/util/pidlimit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/util/pidlimit.go b/internal/util/pidlimit.go index 4ac566efb..19271ba06 100644 --- a/internal/util/pidlimit.go +++ b/internal/util/pidlimit.go @@ -47,7 +47,7 @@ func getCgroupPidsFile() (string, error) { scanner := bufio.NewScanner(cgroup) var slice string for scanner.Scan() { - parts := strings.Split(scanner.Text(), ":") + parts := strings.SplitN(scanner.Text(), ":", 3) if parts == nil || len(parts) < 3 { continue }