Merge pull request #1443 from crosbymichael/daemon-cgroup

Place containerd inside cgroup
This commit is contained in:
Kenfe-Mickaël Laventure 2017-08-30 10:45:19 -07:00 committed by GitHub
commit 49e3d43ff2
2 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,8 @@ type Config struct {
Subreaper bool `toml:"subreaper"`
// OOMScore adjust the containerd's oom score
OOMScore int `toml:"oom_score"`
// Cgroup specifies cgroup information for the containerd daemon process
Cgroup CgroupConfig `toml:"cgroup"`
md toml.MetaData
}
@ -46,6 +48,10 @@ type MetricsConfig struct {
Address string `toml:"address"`
}
type CgroupConfig struct {
Path string `toml:"path"`
}
// Decode unmarshals a plugin specific configuration by plugin id
func (c *Config) Decode(id string, v interface{}) (interface{}, error) {
data, ok := c.Plugins[id]

View File

@ -4,8 +4,10 @@ import (
"context"
"os"
"github.com/containerd/cgroups"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/sys"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
const (
@ -35,5 +37,21 @@ func apply(ctx context.Context, config *Config) error {
return err
}
}
if config.Cgroup.Path != "" {
cg, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(config.Cgroup.Path))
if err != nil {
if err != cgroups.ErrCgroupDeleted {
return err
}
if cg, err = cgroups.New(cgroups.V1, cgroups.StaticPath(config.Cgroup.Path), &specs.LinuxResources{}); err != nil {
return err
}
}
if err := cg.Add(cgroups.Process{
Pid: os.Getpid(),
}); err != nil {
return err
}
}
return nil
}