Эх сурвалжийг харах

add containerd support

Signed-off-by: tombokombo <[email protected]>
tombokombo 4 жил өмнө
parent
commit
cdd6f29036

+ 9 - 1
cgroup/cgroup.go

@@ -18,6 +18,7 @@ var (
 
 
 	dockerIdRegexp      = regexp.MustCompile(`([a-z0-9]{64})`)
 	dockerIdRegexp      = regexp.MustCompile(`([a-z0-9]{64})`)
 	crioIdRegexp        = regexp.MustCompile(`crio-([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/([^/]+)`)
 	lxcIdRegexp         = regexp.MustCompile(`/lxc/([^/]+)`)
 	systemSliceIdRegexp = regexp.MustCompile(`(/system\.slice/([^/]+))`)
 	systemSliceIdRegexp = regexp.MustCompile(`(/system\.slice/([^/]+))`)
 )
 )
@@ -29,6 +30,7 @@ const (
 	ContainerTypeStandaloneProcess
 	ContainerTypeStandaloneProcess
 	ContainerTypeDocker
 	ContainerTypeDocker
 	ContainerTypeCrio
 	ContainerTypeCrio
+	ContainerTypeContainerd
 	ContainerTypeLxc
 	ContainerTypeLxc
 	ContainerTypeSystemdService
 	ContainerTypeSystemdService
 )
 )
@@ -41,6 +43,8 @@ func (t ContainerType) String() string {
 		return "docker"
 		return "docker"
 	case ContainerTypeCrio:
 	case ContainerTypeCrio:
 		return "crio"
 		return "crio"
+	case ContainerTypeContainerd:
+		return "cri-containerd"
 	case ContainerTypeLxc:
 	case ContainerTypeLxc:
 		return "lxc"
 		return "lxc"
 	case ContainerTypeSystemdService:
 	case ContainerTypeSystemdService:
@@ -184,11 +188,15 @@ func containerByCgroup(path string) (ContainerType, string, error) {
 			return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)
 			return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)
 		}
 		}
 		return ContainerTypeDocker, matches[1], nil
 		return ContainerTypeDocker, matches[1], nil
-	case "kubepods":
+	case "kubepods", "kubepods.slice":
 		crioMatches := crioIdRegexp.FindStringSubmatch(path)
 		crioMatches := crioIdRegexp.FindStringSubmatch(path)
 		if crioMatches != nil {
 		if crioMatches != nil {
 			return ContainerTypeCrio, crioMatches[1], nil
 			return ContainerTypeCrio, crioMatches[1], nil
 		}
 		}
+		containerdMatches := containerdIdRegexp.FindStringSubmatch(path)
+		if containerdMatches != nil {
+			return ContainerTypeContainerd, containerdMatches[1], nil
+		}
 		matches := dockerIdRegexp.FindStringSubmatch(path)
 		matches := dockerIdRegexp.FindStringSubmatch(path)
 		if matches == nil {
 		if matches == nil {
 			return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)
 			return ContainerTypeUnknown, "", fmt.Errorf("invalid docker cgroup %s", path)

+ 2 - 2
containers/registry.go

@@ -251,7 +251,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
 	if cg.ContainerType == cgroup.ContainerTypeSystemdService {
 	if cg.ContainerType == cgroup.ContainerTypeSystemdService {
 		return ContainerID(cg.ContainerId)
 		return ContainerID(cg.ContainerId)
 	}
 	}
-	if cg.ContainerType != cgroup.ContainerTypeDocker {
+	if cg.ContainerType != cgroup.ContainerTypeDocker && cg.ContainerType != cgroup.ContainerTypeContainerd {
 		return ""
 		return ""
 	}
 	}
 	if md.labels["io.kubernetes.pod.name"] != "" {
 	if md.labels["io.kubernetes.pod.name"] != "" {
@@ -271,7 +271,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
 }
 }
 
 
 func getContainerMetadata(cg *cgroup.Cgroup) (*ContainerMetadata, error) {
 func getContainerMetadata(cg *cgroup.Cgroup) (*ContainerMetadata, error) {
-	if cg.ContainerType != cgroup.ContainerTypeDocker {
+	if cg.ContainerType != cgroup.ContainerTypeDocker && cg.ContainerType != cgroup.ContainerTypeContainerd {
 		return &ContainerMetadata{}, nil
 		return &ContainerMetadata{}, nil
 	}
 	}
 	var dockerdErr error
 	var dockerdErr error