diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-01-28 16:37:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-28 16:37:19 -0500 |
commit | 0c6a889a7ec93964a12a10870920727e13e438c3 (patch) | |
tree | 200f719cbda73f16209ab400442a33b2d4a1b634 | |
parent | 2ee034c1e6ddd9918b97ddea2fd3e6388ec8f60b (diff) | |
parent | 89bb8a9b368b1f42fb5ff8ca612aa3d4981cff3a (diff) | |
download | podman-0c6a889a7ec93964a12a10870920727e13e438c3.tar.gz podman-0c6a889a7ec93964a12a10870920727e13e438c3.tar.bz2 podman-0c6a889a7ec93964a12a10870920727e13e438c3.zip |
Merge pull request #9110 from rhatdan/cgroups
Don't fail if one of the cgroups is not setup
-rw-r--r-- | pkg/cgroups/cgroups.go | 12 | ||||
-rw-r--r-- | pkg/cgroups/cgroups_test.go | 32 |
2 files changed, 43 insertions, 1 deletions
diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go index c200dd01a..285fd093a 100644 --- a/pkg/cgroups/cgroups.go +++ b/pkg/cgroups/cgroups.go @@ -24,6 +24,7 @@ var ( ErrCgroupDeleted = errors.New("cgroup deleted") // ErrCgroupV1Rootless means the cgroup v1 were attempted to be used in rootless environment ErrCgroupV1Rootless = errors.New("no support for CGroups V1 in rootless environments") + ErrStatCgroup = errors.New("no cgroup available for gathering user statistics") ) // CgroupControl controls a cgroup hierarchy @@ -525,10 +526,19 @@ func (c *CgroupControl) AddPid(pid int) error { // Stat returns usage statistics for the cgroup func (c *CgroupControl) Stat() (*Metrics, error) { m := Metrics{} + found := false for _, h := range handlers { if err := h.Stat(c, &m); err != nil { - return nil, err + if !os.IsNotExist(errors.Cause(err)) { + return nil, err + } + logrus.Warningf("Failed to retrieve cgroup stats: %v", err) + continue } + found = true + } + if !found { + return nil, ErrStatCgroup } return &m, nil } diff --git a/pkg/cgroups/cgroups_test.go b/pkg/cgroups/cgroups_test.go new file mode 100644 index 000000000..54315f7be --- /dev/null +++ b/pkg/cgroups/cgroups_test.go @@ -0,0 +1,32 @@ +package cgroups + +import ( + "testing" + + "github.com/containers/podman/v2/pkg/rootless" + spec "github.com/opencontainers/runtime-spec/specs-go" +) + +func TestCreated(t *testing.T) { + // tests only works in rootless mode + if rootless.IsRootless() { + return + } + + var resources spec.LinuxResources + cgr, err := New("machine.slice", &resources) + if err != nil { + t.Error(err) + } + if err := cgr.Delete(); err != nil { + t.Error(err) + } + + cgr, err = NewSystemd("machine.slice") + if err != nil { + t.Error(err) + } + if err := cgr.Delete(); err != nil { + t.Error(err) + } +} |