default join cgroup namespace in runc example

Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
lifubang 2020-04-17 15:57:42 +08:00
parent e4981c91b5
commit d0f9b9ce42
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