Skip to content

Commit c963649

Browse files
committed
oci: make sure cgroupns is enabled if supported
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent c6a1835 commit c963649

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

executor/oci/spec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
137137
return nil, nil, err
138138
}
139139

140+
if cgroupNamespaceSupported() {
141+
s.Linux.Namespaces = append(s.Linux.Namespaces, specs.LinuxNamespace{
142+
Type: specs.CgroupNamespace,
143+
})
144+
}
145+
140146
if len(meta.Ulimit) == 0 {
141147
// reset open files limit
142148
s.Process.Rlimits = nil

executor/oci/spec_unix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package oci
66
import (
77
"context"
88
"fmt"
9+
"os"
910
"strings"
11+
"sync"
1012

1113
"github.com/containerd/containerd/containers"
1214
"github.com/containerd/containerd/oci"
@@ -21,6 +23,11 @@ import (
2123
"github.com/pkg/errors"
2224
)
2325

26+
var (
27+
cgroupNSOnce sync.Once
28+
supportsCgroupNS bool
29+
)
30+
2431
const (
2532
tracingSocketPath = "/dev/otel-grpc.sock"
2633
)
@@ -139,3 +146,12 @@ func getTracingSocketMount(socket string) specs.Mount {
139146
func getTracingSocket() string {
140147
return fmt.Sprintf("unix://%s", tracingSocketPath)
141148
}
149+
150+
func cgroupNamespaceSupported() bool {
151+
cgroupNSOnce.Do(func() {
152+
if _, err := os.Stat("/proc/self/ns/cgroup"); !os.IsNotExist(err) {
153+
supportsCgroupNS = true
154+
}
155+
})
156+
return supportsCgroupNS
157+
}

executor/oci/spec_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ func getTracingSocketMount(socket string) specs.Mount {
6363
func getTracingSocket() string {
6464
return fmt.Sprintf("npipe://%s", filepath.ToSlash(tracingSocketPath))
6565
}
66+
67+
func cgroupNamespaceSupported() bool {
68+
return false
69+
}

0 commit comments

Comments
 (0)