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 <ypadia@redhat.com>
Signed-off-by: Yati Padia <ypadia@redhat.com>
(cherry picked from commit 16ec97d8f7)
This commit is contained in:
Artur Troian 2021-07-30 09:57:50 +05:30 committed by mergify[bot]
parent 966841cafc
commit 82fd1e5248

View File

@ -47,7 +47,7 @@ func getCgroupPidsFile() (string, error) {
scanner := bufio.NewScanner(cgroup) scanner := bufio.NewScanner(cgroup)
var slice string var slice string
for scanner.Scan() { for scanner.Scan() {
parts := strings.Split(scanner.Text(), ":") parts := strings.SplitN(scanner.Text(), ":", 3)
if parts == nil || len(parts) < 3 { if parts == nil || len(parts) < 3 {
continue continue
} }