Skip to content

Commit 27dfa4c

Browse files
aledbfroboquat
authored andcommitted
Add support for systemd driver
1 parent 6f0bbbf commit 27dfa4c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

components/ws-daemon/pkg/cgroup/plugin_fuse_v2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/opencontainers/runc/libcontainer/specconv"
1515
"golang.org/x/sys/unix"
1616
"golang.org/x/xerrors"
17+
18+
"github.com/gitpod-io/gitpod/common-go/log"
1719
)
1820

1921
type FuseDeviceEnablerV2 struct{}
@@ -23,6 +25,8 @@ func (c *FuseDeviceEnablerV2) Type() Version { return Version2 }
2325

2426
func (c *FuseDeviceEnablerV2) Apply(ctx context.Context, basePath, cgroupPath string) error {
2527
fullCgroupPath := filepath.Join(basePath, cgroupPath)
28+
log.WithField("cgroupPath", fullCgroupPath).Info("configuring devices")
29+
2630
cgroupFD, err := unix.Open(fullCgroupPath, unix.O_DIRECTORY|unix.O_RDONLY|unix.O_CLOEXEC, 0600)
2731
if err != nil {
2832
return xerrors.Errorf("cannot get directory fd for %s: %w", fullCgroupPath, err)

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

Lines changed: 25 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,25 @@ 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+
fmt.Sprintf("%v-%v.scope", fields[1], fields[2]),
491+
), nil
492+
}
493+
469494
return spec.Linux.CgroupsPath, nil
470495
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ func NewDaemon(config Config, reg prometheus.Registerer) (*Daemon, error) {
6565

6666
cgroupPlugins, err := cgroup.NewPluginHost(config.CPULimit.CGroupBasePath,
6767
&cgroup.CacheReclaim{},
68-
cgroupV1IOLimiter,
69-
cgroupV2IOLimiter,
7068
&cgroup.FuseDeviceEnablerV1{},
7169
&cgroup.FuseDeviceEnablerV2{},
70+
cgroupV1IOLimiter,
71+
cgroupV2IOLimiter,
7272
)
7373
if err != nil {
7474
return nil, err
7575
}
76+
7677
err = reg.Register(cgroupPlugins)
7778
if err != nil {
7879
return nil, xerrors.Errorf("cannot register cgroup plugin metrics: %w", err)

0 commit comments

Comments
 (0)