Merge pull request #11104 from jwhonce/bz/1988252
Only support containers stats using cgroups v2
This commit is contained in:
		
						commit
						1bc8c94409
					
				|  | @ -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"` | ||||
|  |  | |||
|  | @ -1085,6 +1085,8 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error { | |||
| 	//     description: no error
 | ||||
| 	//   404:
 | ||||
| 	//     $ref: "#/responses/NoSuchContainer"
 | ||||
| 	//   409:
 | ||||
| 	//     $ref: "#/responses/ConflictError"
 | ||||
| 	//   500:
 | ||||
| 	//     $ref: "#/responses/InternalError"
 | ||||
| 	r.HandleFunc(VersionedPath("/libpod/containers/{name}/stats"), s.APIHandler(compat.StatsContainer)).Methods(http.MethodGet) | ||||
|  | @ -1113,6 +1115,8 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error { | |||
| 	//     description: no error
 | ||||
| 	//   404:
 | ||||
| 	//     $ref: "#/responses/NoSuchContainer"
 | ||||
| 	//   409:
 | ||||
| 	//     $ref: "#/responses/ConflictError"
 | ||||
| 	//   500:
 | ||||
| 	//     $ref: "#/responses/InternalError"
 | ||||
| 	r.HandleFunc(VersionedPath("/libpod/containers/stats"), s.APIHandler(libpod.StatsContainer)).Methods(http.MethodGet) | ||||
|  |  | |||
|  | @ -65,6 +65,16 @@ t GET libpod/containers/json?last=1 200 \ | |||
| 
 | ||||
| cid=$(jq -r '.[0].Id' <<<"$output") | ||||
| 
 | ||||
| if root; then | ||||
|     t GET libpod/containers/stats?containers='[$cid]' 200 | ||||
| else | ||||
|     if have_cgroupsv2; then | ||||
|         t GET libpod/containers/stats?containers='[$cid]' 200 | ||||
|     else | ||||
|         t GET libpod/containers/stats?containers='[$cid]' 409 | ||||
|     fi | ||||
| fi | ||||
| 
 | ||||
| t DELETE libpod/containers/$cid 204 | ||||
| 
 | ||||
| # Issue #6799: it should be possible to start a container, even w/o args. | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue