Merge pull request #1443 from crosbymichael/daemon-cgroup
Place containerd inside cgroup
This commit is contained in:
commit
49e3d43ff2
@ -25,6 +25,8 @@ type Config struct {
|
|||||||
Subreaper bool `toml:"subreaper"`
|
Subreaper bool `toml:"subreaper"`
|
||||||
// OOMScore adjust the containerd's oom score
|
// OOMScore adjust the containerd's oom score
|
||||||
OOMScore int `toml:"oom_score"`
|
OOMScore int `toml:"oom_score"`
|
||||||
|
// Cgroup specifies cgroup information for the containerd daemon process
|
||||||
|
Cgroup CgroupConfig `toml:"cgroup"`
|
||||||
|
|
||||||
md toml.MetaData
|
md toml.MetaData
|
||||||
}
|
}
|
||||||
@ -46,6 +48,10 @@ type MetricsConfig struct {
|
|||||||
Address string `toml:"address"`
|
Address string `toml:"address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CgroupConfig struct {
|
||||||
|
Path string `toml:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
// Decode unmarshals a plugin specific configuration by plugin id
|
// Decode unmarshals a plugin specific configuration by plugin id
|
||||||
func (c *Config) Decode(id string, v interface{}) (interface{}, error) {
|
func (c *Config) Decode(id string, v interface{}) (interface{}, error) {
|
||||||
data, ok := c.Plugins[id]
|
data, ok := c.Plugins[id]
|
||||||
|
@ -4,8 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/containerd/cgroups"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -35,5 +37,21 @@ func apply(ctx context.Context, config *Config) error {
|
|||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user