Merge pull request #2322 from lifubang/forceCgroupNS

cgroupv2: default join cgroup namespace in runc example
This commit is contained in:
Akihiro Suda 2020-04-18 05:47:33 +09:00 committed by GitHub
commit bf0a8e1747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -4,13 +4,14 @@ import (
"os" "os"
"strings" "strings"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
) )
// Example returns an example spec file, with many options set so a user can // Example returns an example spec file, with many options set so a user can
// see what a standard spec file looks like. // see what a standard spec file looks like.
func Example() *specs.Spec { func Example() *specs.Spec {
return &specs.Spec{ spec := &specs.Spec{
Version: specs.Version, Version: specs.Version,
Root: &specs.Root{ Root: &specs.Root{
Path: "rootfs", Path: "rootfs",
@ -155,6 +156,12 @@ func Example() *specs.Spec {
}, },
}, },
} }
if cgroups.IsCgroup2UnifiedMode() {
spec.Linux.Namespaces = append(spec.Linux.Namespaces, specs.LinuxNamespace{
Type: "cgroup",
})
}
return spec
} }
// ToRootless converts the given spec file into one that should work with // ToRootless converts the given spec file into one that should work with