mirror of
https://github.com/containers/podman.git
synced 2025-06-18 15:39:08 +08:00
Don't fail if one of the cgroups is not setup
It is fairly common for certain cgroups controllers to not be enabled on a system. We should Warn when this happens versus failing, when doing podman stats command. This way users can get information from the other controllers. Fixes: https://github.com/containers/podman/issues/8588 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -24,6 +24,7 @@ var (
|
|||||||
ErrCgroupDeleted = errors.New("cgroup deleted")
|
ErrCgroupDeleted = errors.New("cgroup deleted")
|
||||||
// ErrCgroupV1Rootless means the cgroup v1 were attempted to be used in rootless environment
|
// ErrCgroupV1Rootless means the cgroup v1 were attempted to be used in rootless environment
|
||||||
ErrCgroupV1Rootless = errors.New("no support for CGroups V1 in rootless environments")
|
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
|
// CgroupControl controls a cgroup hierarchy
|
||||||
@ -525,10 +526,19 @@ func (c *CgroupControl) AddPid(pid int) error {
|
|||||||
// Stat returns usage statistics for the cgroup
|
// Stat returns usage statistics for the cgroup
|
||||||
func (c *CgroupControl) Stat() (*Metrics, error) {
|
func (c *CgroupControl) Stat() (*Metrics, error) {
|
||||||
m := Metrics{}
|
m := Metrics{}
|
||||||
|
found := false
|
||||||
for _, h := range handlers {
|
for _, h := range handlers {
|
||||||
if err := h.Stat(c, &m); err != nil {
|
if err := h.Stat(c, &m); err != nil {
|
||||||
|
if !os.IsNotExist(errors.Cause(err)) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
logrus.Warningf("Failed to retrieve cgroup stats: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, ErrStatCgroup
|
||||||
}
|
}
|
||||||
return &m, nil
|
return &m, nil
|
||||||
}
|
}
|
||||||
|
32
pkg/cgroups/cgroups_test.go
Normal file
32
pkg/cgroups/cgroups_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user