Use namespace in default cgroup path
By default, the generated spec will place containers in cgroups by their ids, we need to use the namespace as the cgroup root to avoid containers with the same name being placed in the same cgroup. ``` 11:perf_event:/to/redis 10:freezer:/to/redis 9:memory:/to/redis 8:devices:/to/redis 7:net_cls,net_prio:/to/redis 6:pids:/to/redis 5:hugetlb:/to/redis 4:cpuset:/to/redis 3:blkio:/to/redis 2:cpu,cpuacct:/to/redis 1:name=systemd:/to/redis 11:perf_event:/te/redis 10:freezer:/te/redis 9:memory:/te/redis 8:devices:/te/redis 7:net_cls,net_prio:/te/redis 6:pids:/te/redis 5:hugetlb:/te/redis 4:cpuset:/te/redis 3:blkio:/te/redis 2:cpu,cpuacct:/te/redis 1:name=systemd:/te/redis ``` Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/containers"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -98,7 +100,7 @@ func test(c config) error {
|
||||
return err
|
||||
}
|
||||
logrus.Info("generating spec from image")
|
||||
spec, err := containerd.GenerateSpec(ctx, client, nil, containerd.WithImageConfig(image), containerd.WithProcessArgs("true"))
|
||||
spec, err := containerd.GenerateSpec(ctx, client, &containers.Container{ID: ""}, containerd.WithImageConfig(image), containerd.WithProcessArgs("true"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,7 +122,7 @@ func test(c config) error {
|
||||
w := &worker{
|
||||
id: i,
|
||||
wg: &wg,
|
||||
spec: spec,
|
||||
spec: *spec,
|
||||
image: image,
|
||||
client: client,
|
||||
}
|
||||
@@ -158,7 +160,7 @@ type worker struct {
|
||||
|
||||
client *containerd.Client
|
||||
image containerd.Image
|
||||
spec *specs.Spec
|
||||
spec specs.Spec
|
||||
}
|
||||
|
||||
func (w *worker) run(ctx, tctx context.Context) {
|
||||
@@ -194,8 +196,9 @@ func (w *worker) run(ctx, tctx context.Context) {
|
||||
}
|
||||
|
||||
func (w *worker) runContainer(ctx context.Context, id string) error {
|
||||
w.spec.Linux.CgroupsPath = filepath.Join("/", fmt.Sprint(w.id), id)
|
||||
c, err := w.client.NewContainer(ctx, id,
|
||||
containerd.WithSpec(w.spec),
|
||||
containerd.WithSpec(&w.spec),
|
||||
containerd.WithNewSnapshot(id, w.image),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user