Skip to content

Commit 9062a35

Browse files
committed
Add support for systemd driver
1 parent a6bf68a commit 9062a35

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

components/ws-daemon/pkg/container/containerd.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ package container
77
import (
88
"context"
99
"encoding/json"
10+
"fmt"
11+
"path/filepath"
12+
"regexp"
1013
"strings"
1114
"sync"
1215
"time"
@@ -455,6 +458,8 @@ func (s *Containerd) IsContainerdReady(ctx context.Context) (bool, error) {
455458
return s.Client.IsServing(ctx)
456459
}
457460

461+
var kubepodsRegexp = regexp.MustCompile(`([^/]+)-([^/]+)-pod`)
462+
458463
// ExtractCGroupPathFromContainer retrieves the CGroupPath from the linux section
459464
// in a container's OCI spec.
460465
func ExtractCGroupPathFromContainer(container containers.Container) (cgroupPath string, err error) {
@@ -466,5 +471,24 @@ func ExtractCGroupPathFromContainer(container containers.Container) (cgroupPath
466471
if spec.Linux == nil {
467472
return "", xerrors.Errorf("container spec has no Linux section")
468473
}
474+
475+
// systemd: /kubepods.slice/kubepods-<QoS-class>.slice/kubepods-<QoS-class>-pod<pod-UID>.slice:<prefix>:<container-iD>
476+
// cgroupfs: /kubepods/<QoS-class>/pod<pod-UID>/<container-iD>
477+
fields := strings.SplitN(spec.Linux.CgroupsPath, ":", 3)
478+
if len(fields) != 3 {
479+
return spec.Linux.CgroupsPath, nil
480+
}
481+
482+
if match := kubepodsRegexp.FindStringSubmatch(fields[0]); len(match) == 3 {
483+
root, class := match[1], match[2]
484+
485+
return filepath.Join(
486+
"/",
487+
fmt.Sprintf("%v.slice", root),
488+
fmt.Sprintf("%v-%v.slice", root, class),
489+
fields[0],
490+
), nil
491+
}
492+
469493
return spec.Linux.CgroupsPath, nil
470494
}

0 commit comments

Comments
 (0)