cgroups: container: check cgroup path before use it

The container CgroupsPath is optional acording to OCI.

If for some reason the runtime decide to not define one.
just skip cgroup operations.

This is going to be useful for upcoming, sandbox cgroup only
cgroup managment feature.

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
Jose Carlos Venegas Munoz 2019-08-16 08:37:17 -05:00
parent f45b2d9cc6
commit 5a17d671a4

View File

@ -1471,6 +1471,12 @@ func (c *Container) cgroupsCreate() (err error) {
// cgroupsDelete deletes the cgroups on the host for the associated container
func (c *Container) cgroupsDelete() error {
if c.state.CgroupPath == "" {
c.Logger().Debug("container does not have host cgroups: nothing to update")
return nil
}
cgroup, err := cgroupsLoadFunc(cgroups.V1,
cgroups.StaticPath(c.state.CgroupPath))
@ -1506,6 +1512,11 @@ func (c *Container) cgroupsDelete() error {
// cgroupsUpdate updates cgroups on the host for the associated container
func (c *Container) cgroupsUpdate(resources specs.LinuxResources) error {
if c.state.CgroupPath == "" {
c.Logger().Debug("container does not have host cgroups: nothing to update")
return nil
}
cgroup, err := cgroupsLoadFunc(cgroups.V1,
cgroups.StaticPath(c.state.CgroupPath))
if err != nil {