Adding option to configure cgroup to start cri-containerd
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
This commit is contained in:
@@ -24,12 +24,14 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/docker/distribution/reference"
|
||||
imagedigest "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/net/context"
|
||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
|
||||
@@ -352,3 +354,23 @@ func resolveSymbolicLink(path string) (string, error) {
|
||||
}
|
||||
return filepath.EvalSymlinks(path)
|
||||
}
|
||||
|
||||
// loadCgroup loads the cgroup associated with path if it exists and moves the current process into the cgroup. If the cgroup
|
||||
// is not created it is created and returned.
|
||||
func loadCgroup(cgroupPath string) (cgroups.Cgroup, error) {
|
||||
cg, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(cgroupPath))
|
||||
if err != nil {
|
||||
if err != cgroups.ErrCgroupDeleted {
|
||||
return nil, err
|
||||
}
|
||||
if cg, err = cgroups.New(cgroups.V1, cgroups.StaticPath(cgroupPath), &specs.LinuxResources{}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := cg.Add(cgroups.Process{
|
||||
Pid: os.Getpid(),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cg, nil
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ type criContainerdService struct {
|
||||
client *containerd.Client
|
||||
// streamServer is the streaming server serves container streaming request.
|
||||
streamServer streaming.Server
|
||||
// cgroupPath in which the cri-containerd is placed in
|
||||
cgroupPath string
|
||||
}
|
||||
|
||||
// NewCRIContainerdService returns a new instance of CRIContainerdService
|
||||
@@ -95,13 +97,20 @@ func NewCRIContainerdService(
|
||||
networkPluginBinDir,
|
||||
networkPluginConfDir,
|
||||
streamAddress,
|
||||
streamPort string) (CRIContainerdService, error) {
|
||||
streamPort string,
|
||||
cgroupPath string) (CRIContainerdService, error) {
|
||||
// TODO(random-liu): [P2] Recover from runtime state and checkpoint.
|
||||
|
||||
client, err := containerd.New(containerdEndpoint, containerd.WithDefaultNamespace(k8sContainerdNamespace))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize containerd client with endpoint %q: %v", containerdEndpoint, err)
|
||||
}
|
||||
if cgroupPath != "" {
|
||||
_, err := loadCgroup(cgroupPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load cgroup for cgroup path %v: %v", cgroupPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
c := &criContainerdService{
|
||||
os: osinterface.RealOS{},
|
||||
@@ -118,6 +127,7 @@ func NewCRIContainerdService(
|
||||
eventService: client.EventService(),
|
||||
contentStoreService: client.ContentStore(),
|
||||
client: client,
|
||||
cgroupPath: cgroupPath,
|
||||
}
|
||||
|
||||
netPlugin, err := ocicni.InitCNI(networkPluginConfDir, networkPluginBinDir)
|
||||
|
||||
Reference in New Issue
Block a user