Merge pull request #338 from miaoyq/debug-add-shim-to-cgroup
Put containerd-shim into pod cgroup
This commit is contained in:
commit
4d713ece79
22
pkg/opts/task.go
Normal file
22
pkg/opts/task.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd"
|
||||||
|
"github.com/containerd/containerd/linux/runcopts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithContainerdShimCgroup returns function that sets the containerd
|
||||||
|
// shim cgroup path
|
||||||
|
func WithContainerdShimCgroup(path string) containerd.NewTaskOpts {
|
||||||
|
return func(_ context.Context, _ *containerd.Client, r *containerd.TaskInfo) error {
|
||||||
|
r.Options = &runcopts.CreateOptions{
|
||||||
|
ShimCgroup: path,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Since Options is an interface different WithXXX will be needed to set different
|
||||||
|
// combinations of CreateOptions.
|
@ -26,6 +26,7 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
|
||||||
|
customopts "github.com/kubernetes-incubator/cri-containerd/pkg/opts"
|
||||||
cio "github.com/kubernetes-incubator/cri-containerd/pkg/server/io"
|
cio "github.com/kubernetes-incubator/cri-containerd/pkg/server/io"
|
||||||
containerstore "github.com/kubernetes-incubator/cri-containerd/pkg/store/container"
|
containerstore "github.com/kubernetes-incubator/cri-containerd/pkg/store/container"
|
||||||
)
|
)
|
||||||
@ -127,7 +128,12 @@ func (c *criContainerdService) startContainer(ctx context.Context,
|
|||||||
return cntr.IO, nil
|
return cntr.IO, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, ioCreation)
|
var taskOpts []containerd.NewTaskOpts
|
||||||
|
cgroup := sandbox.Config.GetLinux().GetCgroupParent()
|
||||||
|
if cgroup != "" {
|
||||||
|
taskOpts = append(taskOpts, customopts.WithContainerdShimCgroup(cgroup))
|
||||||
|
}
|
||||||
|
task, err := container.NewTask(ctx, ioCreation, taskOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create containerd task: %v", err)
|
return fmt.Errorf("failed to create containerd task: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
|
||||||
|
customopts "github.com/kubernetes-incubator/cri-containerd/pkg/opts"
|
||||||
sandboxstore "github.com/kubernetes-incubator/cri-containerd/pkg/store/sandbox"
|
sandboxstore "github.com/kubernetes-incubator/cri-containerd/pkg/store/sandbox"
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/util"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/util"
|
||||||
)
|
)
|
||||||
@ -198,8 +199,12 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
|
|||||||
// Create sandbox task in containerd.
|
// Create sandbox task in containerd.
|
||||||
glog.V(5).Infof("Create sandbox container (id=%q, name=%q).",
|
glog.V(5).Infof("Create sandbox container (id=%q, name=%q).",
|
||||||
id, name)
|
id, name)
|
||||||
|
var taskOpts []containerd.NewTaskOpts
|
||||||
|
if cgroup := sandbox.Config.GetLinux().GetCgroupParent(); cgroup != "" {
|
||||||
|
taskOpts = append(taskOpts, customopts.WithContainerdShimCgroup(cgroup))
|
||||||
|
}
|
||||||
// We don't need stdio for sandbox container.
|
// We don't need stdio for sandbox container.
|
||||||
task, err := container.NewTask(ctx, containerd.NullIO)
|
task, err := container.NewTask(ctx, containerd.NullIO, taskOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create task for sandbox %q: %v", id, err)
|
return nil, fmt.Errorf("failed to create task for sandbox %q: %v", id, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user