mirror of
https://github.com/moby/buildkit.git
synced 2026-08-04 14:50:21 +00:00
oci: make sure cgroupns is enabled if supported
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user