Skip to content

Commit b7b7839

Browse files
committed
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 <[email protected]>
1 parent 0389651 commit b7b7839

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

pkg/api/handlers/compat/images.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/containers/podman/v5/libpod"
2020
"github.com/containers/podman/v5/pkg/api/handlers"
2121
"github.com/containers/podman/v5/pkg/api/handlers/utils"
22+
"github.com/containers/podman/v5/pkg/api/handlers/utils/apiutil"
2223
api "github.com/containers/podman/v5/pkg/api/types"
2324
"github.com/containers/podman/v5/pkg/auth"
2425
"github.com/containers/podman/v5/pkg/domain/entities"
@@ -340,15 +341,15 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
340341
utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s: %s", name, errMsg))
341342
return
342343
}
343-
inspect, err := imageDataToImageInspect(r.Context(), newImage)
344+
inspect, err := imageDataToImageInspect(r.Context(), newImage, r)
344345
if err != nil {
345346
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to convert ImageData to ImageInspect '%s': %w", name, err))
346347
return
347348
}
348349
utils.WriteResponse(w, http.StatusOK, inspect)
349350
}
350351

351-
func imageDataToImageInspect(ctx context.Context, l *libimage.Image) (*handlers.ImageInspect, error) {
352+
func imageDataToImageInspect(ctx context.Context, l *libimage.Image, r *http.Request) (*handlers.ImageInspect, error) {
352353
options := &libimage.InspectOptions{WithParent: true, WithSize: true}
353354
info, err := l.Inspect(ctx, options)
354355
if err != nil {
@@ -407,8 +408,13 @@ func imageDataToImageInspect(ctx context.Context, l *libimage.Image) (*handlers.
407408
RootFS: rootfs,
408409
Size: info.Size,
409410
Variant: "",
410-
VirtualSize: info.VirtualSize,
411411
}
412+
413+
if _, err := apiutil.SupportedVersion(r, "<1.44.0"); err == nil {
414+
//nolint:staticcheck // Deprecated field
415+
dockerImageInspect.VirtualSize = info.VirtualSize
416+
}
417+
412418
return &handlers.ImageInspect{InspectResponse: dockerImageInspect}, nil
413419
}
414420

@@ -482,6 +488,13 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
482488
if !query.SharedSize {
483489
s.SharedSize = -1
484490
}
491+
// VirtualSize is deprecated in version 1.43 and removed in version 1.44
492+
// See https://docs.docker.com/reference/api/engine/version-history/#v143-api-changes
493+
if _, err := apiutil.SupportedVersion(r, "<1.44.0"); err == nil {
494+
s.VirtualSize = s.Size
495+
} else {
496+
s.VirtualSize = 0
497+
}
485498
}
486499
}
487500
utils.WriteResponse(w, http.StatusOK, summaries)

pkg/api/handlers/compat/system.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/containers/podman/v5/libpod"
1010
"github.com/containers/podman/v5/pkg/api/handlers"
1111
"github.com/containers/podman/v5/pkg/api/handlers/utils"
12+
"github.com/containers/podman/v5/pkg/api/handlers/utils/apiutil"
1213
api "github.com/containers/podman/v5/pkg/api/types"
1314
"github.com/containers/podman/v5/pkg/domain/entities"
1415
"github.com/containers/podman/v5/pkg/domain/infra/abi"
@@ -41,8 +42,12 @@ func GetDiskUsage(w http.ResponseWriter, r *http.Request) {
4142
RepoTags: []string{o.Tag},
4243
SharedSize: o.SharedSize,
4344
Size: o.Size,
44-
VirtualSize: o.Size - o.UniqueSize,
4545
}
46+
47+
if _, err := apiutil.SupportedVersion(r, "<1.44.0"); err == nil {
48+
t.VirtualSize = o.Size - o.UniqueSize //nolint:staticcheck // Deprecated field
49+
}
50+
4651
imgs[i] = &t
4752
}
4853

pkg/domain/entities/types/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ImageSummary struct {
1616
Created int64
1717
Size int64
1818
SharedSize int
19-
VirtualSize int64
19+
VirtualSize int64 `json:",omitempty"`
2020
Labels map[string]string
2121
Containers int
2222
ReadOnly bool `json:",omitempty"`

test/apiv2/10-images.at

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ t GET images/json?filter=$IMAGE 200 \
4242
length=1 \
4343
.[0].Names[0]=$IMAGE
4444

45+
# Test VirtualSize field is present in API v1.43 (backward compatibility)
46+
t GET /v1.43/images/json 200 \
47+
.[0].VirtualSize~[0-9]\\+
48+
49+
# Test VirtualSize field is no longer present in API v1.44+ (deprecated since API v1.43)
50+
t GET /v1.44/images/json 200 \
51+
.[0].VirtualSize=null
52+
4553
# Negative test case
4654
t GET images/json?filter=nonesuch 200 length=0
4755

@@ -50,6 +58,14 @@ t GET images/$iid/json 200 \
5058
.Id=sha256:$iid \
5159
.RepoTags[0]=$IMAGE
5260

61+
# Test VirtualSize field is present in API v1.43 for single image inspect (backward compatibility)
62+
t GET /v1.43/images/$iid/json 200 \
63+
.VirtualSize~[0-9]\\+
64+
65+
# Test VirtualSize field is no longer present in API v1.44+ for single image inspect (deprecated since API v1.43)
66+
t GET /v1.44/images/$iid/json 200 \
67+
.VirtualSize=null
68+
5369
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*Download complete.*"
5470
t POST "libpod/images/pull?reference=alpine&compatMode=true" 200 .error~null .status~".*Download complete.*"
5571

test/apiv2/45-system.at

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ cid=$(jq -r '.Id' <<<"$output")
3838
t GET system/df 200 '.LayersSize=12180391'
3939
t GET libpod/system/df 200 '.ImagesSize=12180391'
4040

41+
# VirtualSize was computed (somehow) in v1.43 so we need to
42+
# build an image to test that the value is returned
43+
# in API <= v1.43.
44+
IIDFILE=$(mktemp)
45+
podman build --iidfile $IIDFILE -<< EOF
46+
FROM $IMAGE
47+
RUN :
48+
EOF
49+
50+
# Test VirtualSize field is present in API v1.43 for system/df (backward compatibility)
51+
t GET /v1.43/system/df 200 \
52+
.Images[0].Size~[0-9]\\+ \
53+
.Images[0].VirtualSize~[0-9]\\+
54+
55+
# Test VirtualSize field is no longer present in API v1.44+ for system/df (deprecated since API v1.43)
56+
t GET /v1.44/system/df 200 \
57+
.Images[0].Size~[0-9]\\+ \
58+
.Images[0].VirtualSize=null
59+
60+
podman rmi -f $(< $IIDFILE)
61+
4162
# Verify that one container references the volume
4263
t GET system/df 200 '.Volumes[0].UsageData.RefCount=1'
4364

@@ -91,3 +112,5 @@ t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1"]}' param
91112
t POST 'libpod/system/prune?volumes=true' params='' 200 .VolumePruneReports[0].Id=foo1
92113

93114
# TODO add other system prune tests for pods / images
115+
116+
# vim: filetype=sh

0 commit comments

Comments
 (0)