mirror of
https://github.com/containers/podman.git
synced 2025-10-18 19:53:58 +08:00
Fix error message on podman stats on cgroups v1 rootless environments
podman stats does not work in rootless environments with cgroups V1. Fix error message and document this fact. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -134,9 +134,13 @@ func statsCmd(c *cliconfig.StatsValues) error {
|
|||||||
initialStats, err := ctr.GetContainerStats(&libpod.ContainerStats{})
|
initialStats, err := ctr.GetContainerStats(&libpod.ContainerStats{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// when doing "all", dont worry about containers that are not running
|
// when doing "all", dont worry about containers that are not running
|
||||||
if c.All && errors.Cause(err) == define.ErrCtrRemoved || errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == define.ErrCtrStateInvalid {
|
cause := errors.Cause(err)
|
||||||
|
if c.All && (cause == define.ErrCtrRemoved || cause == define.ErrNoSuchCtr || cause == define.ErrCtrStateInvalid) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if cause == cgroups.ErrCgroupV1Rootless {
|
||||||
|
err = cause
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
containerStats[ctr.ID()] = initialStats
|
containerStats[ctr.ID()] = initialStats
|
||||||
|
@ -9,6 +9,10 @@ podman\-stats - Display a live stream of 1 or more containers' resource usage st
|
|||||||
## DESCRIPTION
|
## DESCRIPTION
|
||||||
Display a live stream of one or more containers' resource usage statistics
|
Display a live stream of one or more containers' resource usage statistics
|
||||||
|
|
||||||
|
Note: Podman stats will not work in rootless environments that use CGroups V1.
|
||||||
|
Podman stats relies on CGroup information for statistics, and CGroup v1 is not
|
||||||
|
supported for rootless use cases.
|
||||||
|
|
||||||
## OPTIONS
|
## OPTIONS
|
||||||
|
|
||||||
**--all**, **-a**
|
**--all**, **-a**
|
||||||
@ -69,14 +73,14 @@ a9f807ffaacd frosty_hodgkin -- 3.092MB / 16.7GB 0.02% -- / -- --
|
|||||||
# podman stats --no-stream --format=json a9f80
|
# podman stats --no-stream --format=json a9f80
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "a9f807ffaacd",
|
"id": "a9f807ffaacd",
|
||||||
"name": "frosty_hodgkin",
|
"name": "frosty_hodgkin",
|
||||||
"cpu_percent": "--",
|
"cpu_percent": "--",
|
||||||
"mem_usage": "3.092MB / 16.7GB",
|
"mem_usage": "3.092MB / 16.7GB",
|
||||||
"mem_percent": "0.02%",
|
"mem_percent": "0.02%",
|
||||||
"netio": "-- / --",
|
"netio": "-- / --",
|
||||||
"blocki": "-- / --",
|
"blocki": "-- / --",
|
||||||
"pids": "2"
|
"pids": "2"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -204,7 +204,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
|
|||||||
// Get the conmon CGroup
|
// Get the conmon CGroup
|
||||||
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
|
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
|
||||||
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
|
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
|
||||||
if err != nil && err != cgroups.ErrCgroupDeleted {
|
if err != nil && err != cgroups.ErrCgroupDeleted && err != cgroups.ErrCgroupV1Rootless {
|
||||||
removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup %s", p.ID(), conmonCgroupPath)
|
removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup %s", p.ID(), conmonCgroupPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
|
|||||||
// hard - instead, just log errors.
|
// hard - instead, just log errors.
|
||||||
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
|
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
|
||||||
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
|
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
|
||||||
if err != nil && err != cgroups.ErrCgroupDeleted {
|
if err != nil && err != cgroups.ErrCgroupDeleted && err != cgroups.ErrCgroupV1Rootless {
|
||||||
if removalErr == nil {
|
if removalErr == nil {
|
||||||
removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup", p.ID())
|
removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup", p.ID())
|
||||||
} else {
|
} else {
|
||||||
@ -283,7 +283,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cgroup, err := cgroups.Load(p.state.CgroupPath)
|
cgroup, err := cgroups.Load(p.state.CgroupPath)
|
||||||
if err != nil && err != cgroups.ErrCgroupDeleted {
|
if err != nil && err != cgroups.ErrCgroupDeleted && err != cgroups.ErrCgroupV1Rootless {
|
||||||
if removalErr == nil {
|
if removalErr == nil {
|
||||||
removalErr = errors.Wrapf(err, "error retrieving pod %s cgroup", p.ID())
|
removalErr = errors.Wrapf(err, "error retrieving pod %s cgroup", p.ID())
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
systemdDbus "github.com/coreos/go-systemd/dbus"
|
systemdDbus "github.com/coreos/go-systemd/dbus"
|
||||||
"github.com/godbus/dbus"
|
"github.com/godbus/dbus"
|
||||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
@ -19,7 +20,9 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrCgroupDeleted means the cgroup was deleted
|
// ErrCgroupDeleted means the cgroup was deleted
|
||||||
ErrCgroupDeleted = errors.New("cgroups: cgroup deleted")
|
ErrCgroupDeleted = errors.New("cgroup deleted")
|
||||||
|
// ErrCgroupV1Rootless means the cgroup v1 were attempted to be used in rootless environmen
|
||||||
|
ErrCgroupV1Rootless = errors.New("no support for CGroups V1 in rootless environments")
|
||||||
)
|
)
|
||||||
|
|
||||||
// CgroupControl controls a cgroup hierarchy
|
// CgroupControl controls a cgroup hierarchy
|
||||||
@ -339,6 +342,9 @@ func Load(path string) (*CgroupControl, error) {
|
|||||||
p := control.getCgroupv1Path(name)
|
p := control.getCgroupv1Path(name)
|
||||||
if _, err := os.Stat(p); err != nil {
|
if _, err := os.Stat(p); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
if rootless.IsRootless() {
|
||||||
|
return nil, ErrCgroupV1Rootless
|
||||||
|
}
|
||||||
// compatible with the error code
|
// compatible with the error code
|
||||||
// used by containerd/cgroups
|
// used by containerd/cgroups
|
||||||
return nil, ErrCgroupDeleted
|
return nil, ErrCgroupDeleted
|
||||||
|
Reference in New Issue
Block a user