vc: make cgroup usage configurable if rootless

rootless execution does not yet support cgroups, so if running
rootlessly skip the cgroup creation and deletion.

Fixes: 1877

Signed-off-by: Gabi Beyer <gabrielle.n.beyer@intel.com>
This commit is contained in:
Gabi Beyer 2019-07-11 19:32:47 +00:00 committed by Marco Vedovati
parent 5f0799f1b7
commit 41407cfbed
2 changed files with 9 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"github.com/kata-containers/runtime/pkg/rootless"
"github.com/kata-containers/runtime/virtcontainers/device/config" "github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/device/manager" "github.com/kata-containers/runtime/virtcontainers/device/manager"
"github.com/kata-containers/runtime/virtcontainers/store" "github.com/kata-containers/runtime/virtcontainers/store"
@ -909,7 +910,7 @@ func (c *Container) create() (err error) {
} }
c.process = *process c.process = *process
if !c.sandbox.config.SandboxCgroupOnly { if !c.sandbox.config.SandboxCgroupOnly || !rootless.IsRootless() {
if err = c.cgroupsCreate(); err != nil { if err = c.cgroupsCreate(); err != nil {
return return
} }
@ -940,7 +941,8 @@ func (c *Container) delete() error {
return err return err
} }
if !c.sandbox.config.SandboxCgroupOnly { // If running rootless, there are no cgroups to remove
if !c.sandbox.config.SandboxCgroupOnly || !rootless.IsRootless() {
if err := c.cgroupsDelete(); err != nil { if err := c.cgroupsDelete(); err != nil {
return err return err
} }

View File

@ -26,6 +26,7 @@ import (
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
"github.com/kata-containers/agent/protocols/grpc" "github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/pkg/rootless"
"github.com/kata-containers/runtime/virtcontainers/device/api" "github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config" "github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/device/drivers" "github.com/kata-containers/runtime/virtcontainers/device/drivers"
@ -764,9 +765,11 @@ func (s *Sandbox) Delete() error {
} }
} }
if !rootless.IsRootless() {
if err := s.cgroupsDelete(); err != nil { if err := s.cgroupsDelete(); err != nil {
return err return err
} }
}
globalSandboxList.removeSandbox(s.id) globalSandboxList.removeSandbox(s.id)