Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail if one of the cgroups is not setup #9110

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/cgroups/cgroups_test.go
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check cgr is what we want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I was just throwing these in to keep the test checker happy. Since I don't see an easy way to test my changes.

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)
}
}