summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-12-05 07:35:29 -0800
committerGitHub <noreply@github.com>2019-12-05 07:35:29 -0800
commit4fb724c72e49768ed31d2dc85a7ad579f8d5c872 (patch)
tree86bfbf8435a9eb5fd523363957809a6902b83af1
parentae839dad5add84b5b6ffd4260987d08441196986 (diff)
parent077ee1a10dafcebe8149f674eee10748a2114336 (diff)
downloadpodman-4fb724c72e49768ed31d2dc85a7ad579f8d5c872.tar.gz
podman-4fb724c72e49768ed31d2dc85a7ad579f8d5c872.tar.bz2
podman-4fb724c72e49768ed31d2dc85a7ad579f8d5c872.zip
Merge pull request #4639 from giuseppe/fix-stats-pod
libpod: fix stats for rootless pods
-rw-r--r--libpod/container.go10
-rw-r--r--test/e2e/pod_stats_test.go10
-rw-r--r--test/e2e/stats_test.go9
3 files changed, 24 insertions, 5 deletions
diff --git a/libpod/container.go b/libpod/container.go
index d978e4e38..dcec3ee50 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -6,6 +6,7 @@ import (
"net"
"os"
"path/filepath"
+ "strings"
"time"
"github.com/containernetworking/cni/pkg/types"
@@ -1072,7 +1073,14 @@ func (c *Container) CGroupPath() (string, error) {
case define.SystemdCgroupsManager:
if rootless.IsRootless() {
uid := rootless.GetRootlessUID()
- return filepath.Join(c.config.CgroupParent, fmt.Sprintf("user-%d.slice/user@%d.service/user.slice", uid, uid), createUnitName("libpod", c.ID())), nil
+ parts := strings.SplitN(c.config.CgroupParent, "/", 2)
+
+ dir := ""
+ if len(parts) > 1 {
+ dir = parts[1]
+ }
+
+ return filepath.Join(parts[0], fmt.Sprintf("user-%d.slice/user@%d.service/user.slice/%s", uid, uid, dir), createUnitName("libpod", c.ID())), nil
}
return filepath.Join(c.config.CgroupParent, createUnitName("libpod", c.ID())), nil
default:
diff --git a/test/e2e/pod_stats_test.go b/test/e2e/pod_stats_test.go
index 4d573a2c7..347f33e62 100644
--- a/test/e2e/pod_stats_test.go
+++ b/test/e2e/pod_stats_test.go
@@ -5,6 +5,7 @@ package integration
import (
"os"
+ "github.com/containers/libpod/pkg/cgroups"
. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -13,12 +14,17 @@ import (
var _ = Describe("Podman pod stats", func() {
var (
tempdir string
- err error
podmanTest *PodmanTestIntegration
)
BeforeEach(func() {
- SkipIfRootless()
+ cgroupsv2, err := cgroups.IsCgroup2UnifiedMode()
+ Expect(err).To(BeNil())
+
+ if os.Geteuid() != 0 && !cgroupsv2 {
+ Skip("This function is not enabled for rootless podman not running on cgroups v2")
+ }
+
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)
diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go
index fbf7c9920..762417a17 100644
--- a/test/e2e/stats_test.go
+++ b/test/e2e/stats_test.go
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
+ "github.com/containers/libpod/pkg/cgroups"
. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -16,12 +17,16 @@ import (
var _ = Describe("Podman stats", func() {
var (
tempdir string
- err error
podmanTest *PodmanTestIntegration
)
BeforeEach(func() {
- SkipIfRootless()
+ cgroupsv2, err := cgroups.IsCgroup2UnifiedMode()
+ Expect(err).To(BeNil())
+
+ if os.Geteuid() != 0 && !cgroupsv2 {
+ Skip("This function is not enabled for rootless podman not running on cgroups v2")
+ }
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)