oci: make sure cgroupns is enabled if supported

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2023-07-07 15:15:21 -07:00
parent c6a1835928
commit c96364913e
3 changed files with 26 additions and 0 deletions

View File

@@ -137,6 +137,12 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
return nil, nil, err
}
if cgroupNamespaceSupported() {
s.Linux.Namespaces = append(s.Linux.Namespaces, specs.LinuxNamespace{
Type: specs.CgroupNamespace,
})
}
if len(meta.Ulimit) == 0 {
// reset open files limit
s.Process.Rlimits = nil

View File

@@ -6,7 +6,9 @@ package oci
import (
"context"
"fmt"
"os"
"strings"
"sync"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/oci"
@@ -21,6 +23,11 @@ import (
"github.com/pkg/errors"
)
var (
cgroupNSOnce sync.Once
supportsCgroupNS bool
)
const (
tracingSocketPath = "/dev/otel-grpc.sock"
)
@@ -139,3 +146,12 @@ func getTracingSocketMount(socket string) specs.Mount {
func getTracingSocket() string {
return fmt.Sprintf("unix://%s", tracingSocketPath)
}
func cgroupNamespaceSupported() bool {
cgroupNSOnce.Do(func() {
if _, err := os.Stat("/proc/self/ns/cgroup"); !os.IsNotExist(err) {
supportsCgroupNS = true
}
})
return supportsCgroupNS
}

View File

@@ -63,3 +63,7 @@ func getTracingSocketMount(socket string) specs.Mount {
func getTracingSocket() string {
return fmt.Sprintf("npipe://%s", filepath.ToSlash(tracingSocketPath))
}
func cgroupNamespaceSupported() bool {
return false
}