stats: ignore errors from containers without cgroups

Now `podman stats --all` ignores failures from a container that has no
cgroups.

Closes: https://github.com/containers/podman/issues/24632

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2024-11-28 11:04:16 +01:00
parent ceee7cb0a6
commit 6673f5c202
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772
2 changed files with 15 additions and 1 deletions

View File

@ -1633,7 +1633,8 @@ func (ic *ContainerEngine) ContainerStats(ctx context.Context, namesOrIds []stri
// update the container state
// https://github.com/containers/podman/issues/23334
(errors.Is(err, define.ErrCtrRemoved) || errors.Is(err, define.ErrNoSuchCtr) ||
errors.Is(err, define.ErrCtrStateInvalid) || errors.Is(err, define.ErrCtrStopped)) {
errors.Is(err, define.ErrCtrStateInvalid) || errors.Is(err, define.ErrCtrStopped) ||
errors.Is(err, define.ErrNoCgroups)) {
continue
}
return nil, err

View File

@ -52,6 +52,19 @@ load helpers
# --cgroupns=host is required to have full visibility of the cgroup path inside the container
run_podman run --cgroups=disabled --cgroupns=host --rm $IMAGE cat /proc/self/cgroup
is "$output" $current_cgroup "--cgroups=disabled must not change the current cgroup"
ctr1="c1-$(safename)"
ctr2="c2-$(safename)"
# verify that "podman stats --all" works when there is a container with --cgroups=disabled
run_podman run --cgroups=disabled --name $ctr1 -d $IMAGE top
run_podman run --name $ctr2 -d $IMAGE top
run_podman stats -a --no-stream --no-reset
assert "$output" !~ "$ctr1" "ctr1 not in stats output"
assert "$output" =~ "$ctr2" "ctr2 in stats output"
run_podman rm -f -t 0 $ctr1 $ctr2
}
# vim: filetype=sh