From 85a0799255722df2bf88827672e98efd60501cdc Mon Sep 17 00:00:00 2001 From: Lennart Kindermann Date: Wed, 18 Nov 2020 17:43:24 +0100 Subject: [PATCH 1/4] added better handling of prefixes in the cgroup line Signed-off-by: Lennart Kindermann --- workflow/executor/pns/pns.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/workflow/executor/pns/pns.go b/workflow/executor/pns/pns.go index 7feeca49347d..884fee55ae19 100644 --- a/workflow/executor/pns/pns.go +++ b/workflow/executor/pns/pns.go @@ -418,9 +418,8 @@ func parseContainerIDFromCgroupLine(line string) string { if containerID := parts[len(parts)-1]; containerID != "" { // need to check for empty string because the line may look like: 5:rdma:/ - // for crio we need to get rid of "crio-" prefix and ".scope" suffix - // e.g. crio-7a92a067289f6197148912be1c15f20f0330c7f3c541473d3b9c4043ca137b42.scope - containerID := strings.TrimSuffix(strings.TrimPrefix(containerID, "crio-"), ".scope") + // remove possible ".scope" suffix + containerID := strings.TrimSuffix(containerID, ".scope") // for compatibility with cri-containerd record format when using systemd cgroup path // example record in /proc/{pid}/cgroup: @@ -430,6 +429,12 @@ func parseContainerIDFromCgroupLine(line string) string { containerID = strList[len(strList)-1] containerID = strings.TrimPrefix(containerID, "cri-containerd-") } + + // remove possible "*-" prefix + // e.g. crio-7a92a067289f6197148912be1c15f20f0330c7f3c541473d3b9c4043ca137b42.scope + parts := strings.Split(containerID, "-") + containerID = parts[len(parts)-1] + return containerID } } From 1f0b85f251c58c381a2be66b8acbb8934a431c8e Mon Sep 17 00:00:00 2001 From: Lennart Kindermann Date: Wed, 18 Nov 2020 17:44:26 +0100 Subject: [PATCH 2/4] added testcase for systemd managed kubelet + docker Signed-off-by: Lennart Kindermann --- workflow/executor/pns/pns_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/workflow/executor/pns/pns_test.go b/workflow/executor/pns/pns_test.go index 4c9aa37e18a7..983a9ee3a9ff 100644 --- a/workflow/executor/pns/pns_test.go +++ b/workflow/executor/pns/pns_test.go @@ -31,6 +31,10 @@ func TestPNSExecutor_parseContainerIDFromCgroupLine(t *testing.T) { line: "8:cpu,cpuacct:/kubepods/besteffort/pod2fad8aad-dcd0-4fef-b45a-151630b9a4b5/crio-7a92a067289f6197148912be1c15f20f0330c7f3c541473d3b9c4043ca137b42.scope", expected: "7a92a067289f6197148912be1c15f20f0330c7f3c541473d3b9c4043ca137b42", }, + { + line: "2:cpuacct,cpu:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod1cd87fe8_8ea0_11ea_8d51_566f300c000a.slice/docker-6b40fc7f75fe3210621a287412ac056e43554b1026a01625b48ba7d136d8a125.scope", + expected: "6b40fc7f75fe3210621a287412ac056e43554b1026a01625b48ba7d136d8a125", + }, } for _, testCase := range testCases { From 1fe438da62e0ca03b005d58d7fc55b683c6fb6a8 Mon Sep 17 00:00:00 2001 From: Lennart Kindermann Date: Wed, 18 Nov 2020 17:45:02 +0100 Subject: [PATCH 3/4] corrected the assert order Signed-off-by: Lennart Kindermann --- workflow/executor/pns/pns_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/executor/pns/pns_test.go b/workflow/executor/pns/pns_test.go index 983a9ee3a9ff..b04e1540c2b1 100644 --- a/workflow/executor/pns/pns_test.go +++ b/workflow/executor/pns/pns_test.go @@ -39,6 +39,6 @@ func TestPNSExecutor_parseContainerIDFromCgroupLine(t *testing.T) { for _, testCase := range testCases { containerID := parseContainerIDFromCgroupLine(testCase.line) - assert.Equal(t, containerID, testCase.expected) + assert.Equal(t, testCase.expected, containerID) } } From 7a4c487ffaf172542f9ba431cf804822d73d0522 Mon Sep 17 00:00:00 2001 From: Lennart Kindermann Date: Wed, 18 Nov 2020 19:32:14 +0100 Subject: [PATCH 4/4] removed unnecessary prefix trim Signed-off-by: Lennart Kindermann --- workflow/executor/pns/pns.go | 1 - 1 file changed, 1 deletion(-) diff --git a/workflow/executor/pns/pns.go b/workflow/executor/pns/pns.go index 884fee55ae19..1891e969b9e6 100644 --- a/workflow/executor/pns/pns.go +++ b/workflow/executor/pns/pns.go @@ -427,7 +427,6 @@ func parseContainerIDFromCgroupLine(line string) string { if strings.Contains(containerID, "cri-containerd") { strList := strings.Split(containerID, ":") containerID = strList[len(strList)-1] - containerID = strings.TrimPrefix(containerID, "cri-containerd-") } // remove possible "*-" prefix