summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2021-08-04 09:53:58 +0000
committerGitHub <noreply@github.com>2021-08-04 09:53:58 +0000
commit1bc8c94409c1c9dc47b4569833af534beba9333f (patch)
tree722448d98c733e7db10bf44b6ff3cfc80a632175 /pkg/api/handlers
parent1ed91065b9356a2e5a07303b8d454268b83ee0f1 (diff)
parent9cc974c9637554620248941642d58ff34df90ba0 (diff)
downloadpodman-1bc8c94409c1c9dc47b4569833af534beba9333f.tar.gz
podman-1bc8c94409c1c9dc47b4569833af534beba9333f.tar.bz2
podman-1bc8c94409c1c9dc47b4569833af534beba9333f.zip
Merge pull request #11104 from jwhonce/bz/1988252
Only support containers stats using cgroups v2
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/libpod/containers_stats.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/containers_stats.go b/pkg/api/handlers/libpod/containers_stats.go
index 75c404d4f..22faab71f 100644
--- a/pkg/api/handlers/libpod/containers_stats.go
+++ b/pkg/api/handlers/libpod/containers_stats.go
@@ -7,8 +7,10 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/pkg/api/handlers/utils"
+ "github.com/containers/podman/v3/pkg/cgroups"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra/abi"
+ "github.com/containers/podman/v3/pkg/rootless"
"github.com/gorilla/schema"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -20,6 +22,16 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
+ // Check if service is running rootless (cheap check)
+ if rootless.IsRootless() {
+ // if so, then verify cgroup v2 available (more expensive check)
+ if isV2, _ := cgroups.IsCgroup2UnifiedMode(); !isV2 {
+ msg := "Container stats resource only available for cgroup v2"
+ utils.Error(w, msg, http.StatusConflict, errors.New(msg))
+ return
+ }
+ }
+
query := struct {
Containers []string `schema:"containers"`
Stream bool `schema:"stream"`