diff --git a/workflow/executor/pns/pns.go b/workflow/executor/pns/pns.go index 7feeca49347d..1891e969b9e6 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: @@ -428,8 +427,13 @@ 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 + // e.g. crio-7a92a067289f6197148912be1c15f20f0330c7f3c541473d3b9c4043ca137b42.scope + parts := strings.Split(containerID, "-") + containerID = parts[len(parts)-1] + return containerID } } diff --git a/workflow/executor/pns/pns_test.go b/workflow/executor/pns/pns_test.go index 4c9aa37e18a7..b04e1540c2b1 100644 --- a/workflow/executor/pns/pns_test.go +++ b/workflow/executor/pns/pns_test.go @@ -31,10 +31,14 @@ 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 { containerID := parseContainerIDFromCgroupLine(testCase.line) - assert.Equal(t, containerID, testCase.expected) + assert.Equal(t, testCase.expected, containerID) } }