Просмотр исходного кода

added support for containers within the `runtime.slice` cgroup (#17)

Nikolay Sivko 3 лет назад
Родитель
Сommit
d604eef02b
2 измененных файлов с 7 добавлено и 2 удалено
  1. 2 2
      cgroup/cgroup.go
  2. 5 0
      cgroup/cgroup_test.go

+ 2 - 2
cgroup/cgroup.go

@@ -22,7 +22,7 @@ var (
 	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/([^/]+))`)
+	systemSliceIdRegexp = regexp.MustCompile(`(/(system|runtime)\.slice/([^/]+))`)
 )
 
 type Version uint8
@@ -156,7 +156,7 @@ func containerByCgroup(path string) (ContainerType, string, error) {
 		}
 		return ContainerTypeLxc, matches[1], nil
 	}
-	if prefix == "system.slice" {
+	if prefix == "system.slice" || prefix == "runtime.slice" {
 		matches := systemSliceIdRegexp.FindStringSubmatch(path)
 		if matches == nil {
 			return ContainerTypeUnknown, "", fmt.Errorf("invalid systemd cgroup %s", path)

+ 5 - 0
cgroup/cgroup_test.go

@@ -109,6 +109,11 @@ func TestContainerByCgroup(t *testing.T) {
 	as.Equal("/system.slice/system-serial\\x2dgetty.slice", id)
 	as.Nil(err)
 
+	typ, id, err = containerByCgroup("/runtime.slice/kubelet.service")
+	as.Equal(typ, ContainerTypeSystemdService)
+	as.Equal("/runtime.slice/kubelet.service", id)
+	as.Nil(err)
+
 	typ, id, err = containerByCgroup("/system.slice/system-postgresql.slice/[email protected]")
 	as.Equal(typ, ContainerTypeSystemdService)
 	as.Equal("/system.slice/system-postgresql.slice", id)