Skip to content

Commit cdd6f29

Browse files
committed
add containerd support
Signed-off-by: tombokombo <[email protected]>
1 parent 5eac9ec commit cdd6f29

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cgroup/cgroup.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818

1919
dockerIdRegexp = regexp.MustCompile(`([a-z0-9]{64})`)
2020
crioIdRegexp = regexp.MustCompile(`crio-([a-z0-9]{64})`)
21+
containerdIdRegexp = regexp.MustCompile(`cri-containerd-([a-z0-9]{64})`)
2122
lxcIdRegexp = regexp.MustCompile(`/lxc/([^/]+)`)
2223
systemSliceIdRegexp = regexp.MustCompile(`(/system\.slice/([^/]+))`)
2324
)
@@ -29,6 +30,7 @@ const (
2930
ContainerTypeStandaloneProcess
3031
ContainerTypeDocker
3132
ContainerTypeCrio
33+
ContainerTypeContainerd
3234
ContainerTypeLxc
3335
ContainerTypeSystemdService
3436
)
@@ -41,6 +43,8 @@ func (t ContainerType) String() string {
4143
return "docker"
4244
case ContainerTypeCrio:
4345
return "crio"
46+
case ContainerTypeContainerd:
47+
return "cri-containerd"
4448
case ContainerTypeLxc:
4549
return "lxc"
4650
case ContainerTypeSystemdService:
@@ -184,11 +188,15 @@ func containerByCgroup(path string) (ContainerType, string, error) {
184188
return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)
185189
}
186190
return ContainerTypeDocker, matches[1], nil
187-
case "kubepods":
191+
case "kubepods", "kubepods.slice":
188192
crioMatches := crioIdRegexp.FindStringSubmatch(path)
189193
if crioMatches != nil {
190194
return ContainerTypeCrio, crioMatches[1], nil
191195
}
196+
containerdMatches := containerdIdRegexp.FindStringSubmatch(path)
197+
if containerdMatches != nil {
198+
return ContainerTypeContainerd, containerdMatches[1], nil
199+
}
192200
matches := dockerIdRegexp.FindStringSubmatch(path)
193201
if matches == nil {
194202
return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)

containers/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
251251
if cg.ContainerType == cgroup.ContainerTypeSystemdService {
252252
return ContainerID(cg.ContainerId)
253253
}
254-
if cg.ContainerType != cgroup.ContainerTypeDocker {
254+
if cg.ContainerType != cgroup.ContainerTypeDocker && cg.ContainerType != cgroup.ContainerTypeContainerd {
255255
return ""
256256
}
257257
if md.labels["io.kubernetes.pod.name"] != "" {
@@ -271,7 +271,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
271271
}
272272

273273
func getContainerMetadata(cg *cgroup.Cgroup) (*ContainerMetadata, error) {
274-
if cg.ContainerType != cgroup.ContainerTypeDocker {
274+
if cg.ContainerType != cgroup.ContainerTypeDocker && cg.ContainerType != cgroup.ContainerTypeContainerd {
275275
return &ContainerMetadata{}, nil
276276
}
277277
var dockerdErr error

0 commit comments

Comments
 (0)