diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-05-16 12:45:09 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-17 23:10:12 +0000 |
commit | 7e1ea9d26dff92c346bb11640fdab523d513e867 (patch) | |
tree | 28fca87c36fa1ddf5c357c61e2677626ed27835a /libpod/runtime_pod.go | |
parent | 018d2c6b1d23acf7fe67e809498bc354eaf6becf (diff) | |
download | podman-7e1ea9d26dff92c346bb11640fdab523d513e867.tar.gz podman-7e1ea9d26dff92c346bb11640fdab523d513e867.tar.bz2 podman-7e1ea9d26dff92c346bb11640fdab523d513e867.zip |
Add per-pod CGroups
Pods can now create their own (cgroupfs) cgroups which containers
in them can (optionally) use.
This presently only works with CGroupFS, systemd cgroups are
still WIP
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #784
Approved by: rhatdan
Diffstat (limited to 'libpod/runtime_pod.go')
-rw-r--r-- | libpod/runtime_pod.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go index 4ca8da9ee..3872a4b67 100644 --- a/libpod/runtime_pod.go +++ b/libpod/runtime_pod.go @@ -2,9 +2,12 @@ package libpod import ( "path" + "path/filepath" "strings" + "github.com/containerd/cgroups" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // Contains the public Runtime API for pods @@ -56,12 +59,21 @@ func (r *Runtime) NewPod(options ...PodCreateOption) (*Pod, error) { } else if strings.HasSuffix(path.Base(pod.config.CgroupParent), ".slice") { return nil, errors.Wrapf(ErrInvalidArg, "systemd slice received as cgroup parent when using cgroupfs") } + // Creating CGroup path is currently a NOOP until proper systemd + // cgroup management is merged case SystemdCgroupsManager: if pod.config.CgroupParent == "" { pod.config.CgroupParent = SystemdDefaultCgroupParent } else if len(pod.config.CgroupParent) < 6 || !strings.HasSuffix(path.Base(pod.config.CgroupParent), ".slice") { return nil, errors.Wrapf(ErrInvalidArg, "did not receive systemd slice as cgroup parent when using systemd to manage cgroups") } + // If we are set to use pod cgroups, set the cgroup parent that + // all containers in the pod will share + // No need to create it with cgroupfs - the first container to + // launch should do it for us + if pod.config.UsePodCgroup { + pod.state.CgroupPath = filepath.Join(pod.config.CgroupParent, pod.ID()) + } default: return nil, errors.Wrapf(ErrInvalidArg, "unsupported CGroup manager: %s - cannot validate cgroup parent", r.config.CgroupManager) } @@ -211,6 +223,29 @@ func (r *Runtime) RemovePod(p *Pod, removeCtrs, force bool) error { ctr.valid = false } + // Remove pod cgroup, if present + if p.state.CgroupPath != "" { + switch p.runtime.config.CgroupManager { + case SystemdCgroupsManager: + // NOOP for now, until proper systemd cgroup management + // is implemented + case CgroupfsCgroupsManager: + // Delete the cgroupfs cgroup + logrus.Debugf("Removing pod cgroup %s", p.state.CgroupPath) + + cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(p.state.CgroupPath)) + if err != nil && err != cgroups.ErrCgroupDeleted { + return err + } else if err == nil { + if err := cgroup.Delete(); err != nil { + return err + } + } + default: + return errors.Wrapf(ErrInvalidArg, "unknown cgroups manager %s specified", p.runtime.config.CgroupManager) + } + } + // Remove pod from state if err := r.state.RemovePod(p); err != nil { return err |