From d0f9b9ce4232e64891f18513e7bcb1d2d1d0b973 Mon Sep 17 00:00:00 2001 From: lifubang Date: Fri, 17 Apr 2020 15:57:42 +0800 Subject: [PATCH] default join cgroup namespace in runc example Signed-off-by: lifubang --- libcontainer/specconv/example.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libcontainer/specconv/example.go b/libcontainer/specconv/example.go index 23e225c3..2d5e3791 100644 --- a/libcontainer/specconv/example.go +++ b/libcontainer/specconv/example.go @@ -4,13 +4,14 @@ import ( "os" "strings" + "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runtime-spec/specs-go" ) // Example returns an example spec file, with many options set so a user can // see what a standard spec file looks like. func Example() *specs.Spec { - return &specs.Spec{ + spec := &specs.Spec{ Version: specs.Version, Root: &specs.Root{ 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