mirror of
https://github.com/containers/podman.git
synced 2026-02-05 15:45:08 +01:00
compat: remove deprecated VirtualSize
Since compat version 1.43 the VirtualSize field in the
GET /images/{name}/json, GET /images/json, and
GET /system/df responses is deprecated and will no
longer be included in API v1.44. Use the Size field
instead, which contains the same information.
Signed-off-by: Nicola Sella <nsella@redhat.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/containers/podman/v5/libpod"
|
||||
"github.com/containers/podman/v5/pkg/api/handlers"
|
||||
"github.com/containers/podman/v5/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v5/pkg/api/handlers/utils/apiutil"
|
||||
api "github.com/containers/podman/v5/pkg/api/types"
|
||||
"github.com/containers/podman/v5/pkg/auth"
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
@@ -340,7 +341,7 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
|
||||
utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s: %s", name, errMsg))
|
||||
return
|
||||
}
|
||||
inspect, err := imageDataToImageInspect(r.Context(), newImage)
|
||||
inspect, err := imageDataToImageInspect(r.Context(), newImage, r)
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to convert ImageData to ImageInspect '%s': %w", name, err))
|
||||
return
|
||||
@@ -348,7 +349,7 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
|
||||
utils.WriteResponse(w, http.StatusOK, inspect)
|
||||
}
|
||||
|
||||
func imageDataToImageInspect(ctx context.Context, l *libimage.Image) (*handlers.ImageInspect, error) {
|
||||
func imageDataToImageInspect(ctx context.Context, l *libimage.Image, r *http.Request) (*handlers.ImageInspect, error) {
|
||||
options := &libimage.InspectOptions{WithParent: true, WithSize: true}
|
||||
info, err := l.Inspect(ctx, options)
|
||||
if err != nil {
|
||||
@@ -407,8 +408,13 @@ func imageDataToImageInspect(ctx context.Context, l *libimage.Image) (*handlers.
|
||||
RootFS: rootfs,
|
||||
Size: info.Size,
|
||||
Variant: "",
|
||||
VirtualSize: info.VirtualSize,
|
||||
}
|
||||
|
||||
if _, err := apiutil.SupportedVersion(r, "<1.44.0"); err == nil {
|
||||
//nolint:staticcheck // Deprecated field
|
||||
dockerImageInspect.VirtualSize = info.VirtualSize
|
||||
}
|
||||
|
||||
return &handlers.ImageInspect{InspectResponse: dockerImageInspect}, nil
|
||||
}
|
||||
|
||||
@@ -482,6 +488,13 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
|
||||
if !query.SharedSize {
|
||||
s.SharedSize = -1
|
||||
}
|
||||
// VirtualSize is deprecated in version 1.43 and removed in version 1.44
|
||||
// See https://docs.docker.com/reference/api/engine/version-history/#v143-api-changes
|
||||
if _, err := apiutil.SupportedVersion(r, "<1.44.0"); err == nil {
|
||||
s.VirtualSize = s.Size
|
||||
} else {
|
||||
s.VirtualSize = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusOK, summaries)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/containers/podman/v5/libpod"
|
||||
"github.com/containers/podman/v5/pkg/api/handlers"
|
||||
"github.com/containers/podman/v5/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v5/pkg/api/handlers/utils/apiutil"
|
||||
api "github.com/containers/podman/v5/pkg/api/types"
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
"github.com/containers/podman/v5/pkg/domain/infra/abi"
|
||||
@@ -41,8 +42,12 @@ func GetDiskUsage(w http.ResponseWriter, r *http.Request) {
|
||||
RepoTags: []string{o.Tag},
|
||||
SharedSize: o.SharedSize,
|
||||
Size: o.Size,
|
||||
VirtualSize: o.Size - o.UniqueSize,
|
||||
}
|
||||
|
||||
if _, err := apiutil.SupportedVersion(r, "<1.44.0"); err == nil {
|
||||
t.VirtualSize = o.Size - o.UniqueSize //nolint:staticcheck // Deprecated field
|
||||
}
|
||||
|
||||
imgs[i] = &t
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ type ImageSummary struct {
|
||||
Created int64
|
||||
Size int64
|
||||
SharedSize int
|
||||
VirtualSize int64
|
||||
VirtualSize int64 `json:",omitempty"`
|
||||
Labels map[string]string
|
||||
Containers int
|
||||
ReadOnly bool `json:",omitempty"`
|
||||
|
||||
@@ -42,6 +42,14 @@ t GET images/json?filter=$IMAGE 200 \
|
||||
length=1 \
|
||||
.[0].Names[0]=$IMAGE
|
||||
|
||||
# Test VirtualSize field is present in API v1.43 (backward compatibility)
|
||||
t GET /v1.43/images/json 200 \
|
||||
.[0].VirtualSize~[0-9]\\+
|
||||
|
||||
# Test VirtualSize field is no longer present in API v1.44+ (deprecated since API v1.43)
|
||||
t GET /v1.44/images/json 200 \
|
||||
.[0].VirtualSize=null
|
||||
|
||||
# Negative test case
|
||||
t GET images/json?filter=nonesuch 200 length=0
|
||||
|
||||
@@ -50,6 +58,14 @@ t GET images/$iid/json 200 \
|
||||
.Id=sha256:$iid \
|
||||
.RepoTags[0]=$IMAGE
|
||||
|
||||
# Test VirtualSize field is present in API v1.43 for single image inspect (backward compatibility)
|
||||
t GET /v1.43/images/$iid/json 200 \
|
||||
.VirtualSize~[0-9]\\+
|
||||
|
||||
# Test VirtualSize field is no longer present in API v1.44+ for single image inspect (deprecated since API v1.43)
|
||||
t GET /v1.44/images/$iid/json 200 \
|
||||
.VirtualSize=null
|
||||
|
||||
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*Download complete.*"
|
||||
t POST "libpod/images/pull?reference=alpine&compatMode=true" 200 .error~null .status~".*Download complete.*"
|
||||
|
||||
|
||||
@@ -38,6 +38,27 @@ cid=$(jq -r '.Id' <<<"$output")
|
||||
t GET system/df 200 '.LayersSize=12180391'
|
||||
t GET libpod/system/df 200 '.ImagesSize=12180391'
|
||||
|
||||
# VirtualSize was computed (somehow) in v1.43 so we need to
|
||||
# build an image to test that the value is returned
|
||||
# in API <= v1.43.
|
||||
IIDFILE=$(mktemp)
|
||||
podman build --iidfile $IIDFILE -<< EOF
|
||||
FROM $IMAGE
|
||||
RUN :
|
||||
EOF
|
||||
|
||||
# Test VirtualSize field is present in API v1.43 for system/df (backward compatibility)
|
||||
t GET /v1.43/system/df 200 \
|
||||
.Images[0].Size~[0-9]\\+ \
|
||||
.Images[0].VirtualSize~[0-9]\\+
|
||||
|
||||
# Test VirtualSize field is no longer present in API v1.44+ for system/df (deprecated since API v1.43)
|
||||
t GET /v1.44/system/df 200 \
|
||||
.Images[0].Size~[0-9]\\+ \
|
||||
.Images[0].VirtualSize=null
|
||||
|
||||
podman rmi -f $(< $IIDFILE)
|
||||
|
||||
# Verify that one container references the volume
|
||||
t GET system/df 200 '.Volumes[0].UsageData.RefCount=1'
|
||||
|
||||
@@ -91,3 +112,5 @@ t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1"]}' param
|
||||
t POST 'libpod/system/prune?volumes=true' params='' 200 .VolumePruneReports[0].Id=foo1
|
||||
|
||||
# TODO add other system prune tests for pods / images
|
||||
|
||||
# vim: filetype=sh
|
||||
|
||||
Reference in New Issue
Block a user