Skip to content

Commit

Permalink
fix: executor/pns containerid prefix fix (argoproj#4555)
Browse files Browse the repository at this point in the history
Signed-off-by: Lennart Kindermann <[email protected]>
  • Loading branch information
L3Nerd committed Nov 19, 2020
1 parent 53195ed commit 48af024
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions workflow/executor/pns/pns.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,22 @@ 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:
// 9:cpuset:/kubepods-besteffort-pod30556cce_0f92_11eb_b36d_02623cf324c8.slice:cri-containerd:c688c856b21cfb29c1dbf6c14793435e44a1299dfc12add33283239bffed2620
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
}
}
Expand Down
6 changes: 5 additions & 1 deletion workflow/executor/pns/pns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 48af024

Please sign in to comment.