pkg/api/handlers/libpod/containers_stats.go: Remove Cgroups v1

Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
This commit is contained in:
Lokesh Mandvekar
2025-11-05 09:30:27 -05:00
parent 30d07aa0c8
commit 5d7358d2bf

View File

@@ -4,7 +4,6 @@ package libpod
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"net/http" "net/http"
@@ -13,25 +12,14 @@ import (
api "github.com/containers/podman/v6/pkg/api/types" api "github.com/containers/podman/v6/pkg/api/types"
"github.com/containers/podman/v6/pkg/domain/entities" "github.com/containers/podman/v6/pkg/domain/entities"
"github.com/containers/podman/v6/pkg/domain/infra/abi" "github.com/containers/podman/v6/pkg/domain/infra/abi"
"github.com/containers/podman/v6/pkg/rootless"
"github.com/gorilla/schema" "github.com/gorilla/schema"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.podman.io/common/pkg/cgroups"
) )
func StatsContainer(w http.ResponseWriter, r *http.Request) { func StatsContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) decoder := r.Context().Value(api.DecoderKey).(*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 {
utils.Error(w, http.StatusConflict, errors.New("container stats resource only available for cgroup v2"))
return
}
}
query := struct { query := struct {
Containers []string `schema:"containers"` Containers []string `schema:"containers"`
Stream bool `schema:"stream"` Stream bool `schema:"stream"`