summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-12-08 09:59:00 -0500
committerMatthew Heon <matthew.heon@pm.me>2020-12-08 09:59:00 -0500
commit46337b4708362e9fe2915c7efddc353d88a2cb5e (patch)
tree5412a06203ddc5380663df921143fccb9728765f
parent0cccba834ff2939579f7ef4c340a9337dc9d7d2c (diff)
downloadpodman-46337b4708362e9fe2915c7efddc353d88a2cb5e.tar.gz
podman-46337b4708362e9fe2915c7efddc353d88a2cb5e.tar.bz2
podman-46337b4708362e9fe2915c7efddc353d88a2cb5e.zip
Make `podman stats` slirp check more robust
Just checking for `rootless.IsRootless()` does not catch all the cases where slirp4netns is in use - we actually allow it to be used as root as well. Fortify the conditional here so we don't fail in the root + slirp case. Fixes #7883 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r--libpod/networking_linux.go7
-rw-r--r--test/e2e/stats_test.go10
2 files changed, 13 insertions, 4 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 2171a9208..bf27989bf 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -900,10 +900,9 @@ func (r *Runtime) reloadContainerNetwork(ctr *Container) ([]*cnitypes.Result, er
func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
var netStats *netlink.LinkStatistics
- // rootless v2 cannot seem to resolve its network connection to
- // collect statistics. For now, we allow stats to at least run
- // by returning nil
- if rootless.IsRootless() {
+ // With slirp4netns, we can't collect statistics at present.
+ // For now, we allow stats to at least run by returning nil
+ if rootless.IsRootless() || ctr.config.NetMode.IsSlirp4netns() {
return netStats, nil
}
netNSPath, netPathErr := getContainerNetNS(ctr)
diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go
index 5e8a7a3d0..ab117a2a0 100644
--- a/test/e2e/stats_test.go
+++ b/test/e2e/stats_test.go
@@ -128,6 +128,16 @@ var _ = Describe("Podman stats", func() {
Expect(session.ExitCode()).To(Equal(0))
})
+ It("podman stats on container with forced slirp4netns", func() {
+ // This will force the slirp4netns net mode to be tested as root
+ session := podmanTest.Podman([]string{"run", "-d", "--net", "slirp4netns", ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ session = podmanTest.Podman([]string{"stats", "--no-stream", "-a"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
+
// Regression test for #8265
It("podman stats with custom memory limits", func() {
// Run thre containers. One with a memory limit. Make sure