Skip to content

Commit

Permalink
add containerd support
Browse files Browse the repository at this point in the history
Signed-off-by: tombokombo <[email protected]>
  • Loading branch information
tombokombo committed Mar 11, 2022
1 parent 5eac9ec commit cdd6f29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion cgroup/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (

dockerIdRegexp = regexp.MustCompile(`([a-z0-9]{64})`)
crioIdRegexp = regexp.MustCompile(`crio-([a-z0-9]{64})`)
containerdIdRegexp = regexp.MustCompile(`cri-containerd-([a-z0-9]{64})`)
lxcIdRegexp = regexp.MustCompile(`/lxc/([^/]+)`)
systemSliceIdRegexp = regexp.MustCompile(`(/system\.slice/([^/]+))`)
)
Expand All @@ -29,6 +30,7 @@ const (
ContainerTypeStandaloneProcess
ContainerTypeDocker
ContainerTypeCrio
ContainerTypeContainerd
ContainerTypeLxc
ContainerTypeSystemdService
)
Expand All @@ -41,6 +43,8 @@ func (t ContainerType) String() string {
return "docker"
case ContainerTypeCrio:
return "crio"
case ContainerTypeContainerd:
return "cri-containerd"
case ContainerTypeLxc:
return "lxc"
case ContainerTypeSystemdService:
Expand Down Expand Up @@ -184,11 +188,15 @@ func containerByCgroup(path string) (ContainerType, string, error) {
return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)
}
return ContainerTypeDocker, matches[1], nil
case "kubepods":
case "kubepods", "kubepods.slice":
crioMatches := crioIdRegexp.FindStringSubmatch(path)
if crioMatches != nil {
return ContainerTypeCrio, crioMatches[1], nil
}
containerdMatches := containerdIdRegexp.FindStringSubmatch(path)
if containerdMatches != nil {
return ContainerTypeContainerd, containerdMatches[1], nil
}
matches := dockerIdRegexp.FindStringSubmatch(path)
if matches == nil {
return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)
Expand Down
4 changes: 2 additions & 2 deletions containers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
if cg.ContainerType == cgroup.ContainerTypeSystemdService {
return ContainerID(cg.ContainerId)
}
if cg.ContainerType != cgroup.ContainerTypeDocker {
if cg.ContainerType != cgroup.ContainerTypeDocker && cg.ContainerType != cgroup.ContainerTypeContainerd {
return ""
}
if md.labels["io.kubernetes.pod.name"] != "" {
Expand All @@ -271,7 +271,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
}

func getContainerMetadata(cg *cgroup.Cgroup) (*ContainerMetadata, error) {
if cg.ContainerType != cgroup.ContainerTypeDocker {
if cg.ContainerType != cgroup.ContainerTypeDocker && cg.ContainerType != cgroup.ContainerTypeContainerd {
return &ContainerMetadata{}, nil
}
var dockerdErr error
Expand Down

0 comments on commit cdd6f29

Please sign in to comment.