Skip to content

Commit

Permalink
Merge pull request #45469 from thaJeztah/deprecate_virtualsize_STEP2
Browse files Browse the repository at this point in the history
API: omit deprecated VirtualSize field for API v1.44 and up
  • Loading branch information
AkihiroSuda committed May 16, 2023
2 parents 9548916 + 913b0f5 commit 1371aee
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 38 deletions.
9 changes: 8 additions & 1 deletion api/server/router/image/image_routes.go
Expand Up @@ -263,6 +263,10 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite
return err
}

version := httputils.VersionFromContext(ctx)
if versions.LessThan(version, "1.44") {
imageInspect.VirtualSize = imageInspect.Size //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
}
return httputils.WriteJSON(w, http.StatusOK, imageInspect)
}

Expand Down Expand Up @@ -299,7 +303,6 @@ func (ir *imageRouter) toImageInspect(img *image.Image) (*types.ImageInspect, er
Os: img.OperatingSystem(),
OsVersion: img.OSVersion,
Size: img.Details.Size,
VirtualSize: img.Details.Size, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
GraphDriver: types.GraphDriverData{
Name: img.Details.Driver,
Data: img.Details.Metadata,
Expand Down Expand Up @@ -357,6 +360,7 @@ func (ir *imageRouter) getImagesJSON(ctx context.Context, w http.ResponseWriter,
}

useNone := versions.LessThan(version, "1.43")
withVirtualSize := versions.LessThan(version, "1.44")
for _, img := range images {
if useNone {
if len(img.RepoTags) == 0 && len(img.RepoDigests) == 0 {
Expand All @@ -371,6 +375,9 @@ func (ir *imageRouter) getImagesJSON(ctx context.Context, w http.ResponseWriter,
img.RepoDigests = []string{}
}
}
if withVirtualSize {
img.VirtualSize = img.Size //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
}
}

return httputils.WriteJSON(w, http.StatusOK, images)
Expand Down
5 changes: 5 additions & 0 deletions api/server/router/system/system_routes.go
Expand Up @@ -185,6 +185,11 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter,
b.Parent = "" //nolint:staticcheck // ignore SA1019 (Parent field is deprecated)
}
}
if versions.LessThan(version, "1.44") {
for _, b := range systemDiskUsage.Images {
b.VirtualSize = b.Size //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
}
}

du := types.DiskUsage{
BuildCache: buildCache,
Expand Down
16 changes: 2 additions & 14 deletions api/swagger.yaml
Expand Up @@ -1781,13 +1781,7 @@ definitions:
description: |
Total size of the image including all layers it is composed of.
In versions of Docker before v1.10, this field was calculated from
the image itself and all of its parent images. Images are now stored
self-contained, and no longer use a parent-chain, making this field
an equivalent of the Size field.
> **Deprecated**: this field is kept for backward compatibility, but
> will be removed in API v1.44.
Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
type: "integer"
format: "int64"
example: 1239828
Expand Down Expand Up @@ -1925,12 +1919,7 @@ definitions:
description: |-
Total size of the image including all layers it is composed of.
In versions of Docker before v1.10, this field was calculated from
the image itself and all of its parent images. Images are now stored
self-contained, and no longer use a parent-chain, making this field
an equivalent of the Size field.
Deprecated: this field is kept for backward compatibility, and will be removed in API v1.44.
Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
type: "integer"
format: "int64"
example: 172064416
Expand Down Expand Up @@ -9066,7 +9055,6 @@ paths:
Created: 1466724217
Size: 1092588
SharedSize: 0
VirtualSize: 1092588
Labels: {}
Containers: 1
Containers:
Expand Down
7 changes: 1 addition & 6 deletions api/types/image_summary.go
Expand Up @@ -84,11 +84,6 @@ type ImageSummary struct {

// Total size of the image including all layers it is composed of.
//
// In versions of Docker before v1.10, this field was calculated from
// the image itself and all of its parent images. Images are now stored
// self-contained, and no longer use a parent-chain, making this field
// an equivalent of the Size field.
//
// Deprecated: this field is kept for backward compatibility, and will be removed in API v1.44.
// Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
VirtualSize int64 `json:"VirtualSize,omitempty"`
}
7 changes: 1 addition & 6 deletions api/types/types.go
Expand Up @@ -118,12 +118,7 @@ type ImageInspect struct {
// VirtualSize is the total size of the image including all layers it is
// composed of.
//
// In versions of Docker before v1.10, this field was calculated from
// the image itself and all of its parent images. Docker v1.10 and up
// store images self-contained, and no longer use a parent-chain, making
// this field an equivalent of the Size field.
//
// Deprecated: Unused in API 1.43 and up, but kept for backward compatibility with older API versions.
// Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
VirtualSize int64 `json:"VirtualSize,omitempty"`

// GraphDriver holds information about the storage driver used to store the
Expand Down
1 change: 0 additions & 1 deletion daemon/containerd/image_list.go
Expand Up @@ -250,7 +250,6 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con
RepoDigests: repoDigests,
RepoTags: repoTags,
Size: totalSize,
VirtualSize: totalSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
// -1 indicates that the value has not been set (avoids ambiguity
// between 0 (default) and "not set". We cannot use a pointer (nil)
// for this, as the JSON representation uses "omitempty", which would
Expand Down
9 changes: 4 additions & 5 deletions daemon/images/image_list.go
Expand Up @@ -257,11 +257,10 @@ func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions)

func newImageSummary(image *image.Image, size int64) *types.ImageSummary {
summary := &types.ImageSummary{
ParentID: image.Parent.String(),
ID: image.ID().String(),
Created: image.Created.Unix(),
Size: size,
VirtualSize: size, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
ParentID: image.Parent.String(),
ID: image.ID().String(),
Created: image.Created.Unix(),
Size: size,
// -1 indicates that the value has not been set (avoids ambiguity
// between 0 (default) and "not set". We cannot use a pointer (nil)
// for this, as the JSON representation uses "omitempty", which would
Expand Down
4 changes: 4 additions & 0 deletions docs/api/version-history.md
Expand Up @@ -17,6 +17,10 @@ keywords: "API, Docker, rcli, REST, documentation"

[Docker Engine API v1.44](https://docs.docker.com/engine/api/v1.44/) documentation

* The `VirtualSize` field in the `GET /images/{name}/json`, `GET /images/json`,
and `GET /system/df` responses is now omitted. Use the `Size` field instead,
which contains the same information.

## v1.43 API changes

[Docker Engine API v1.43](https://docs.docker.com/engine/api/v1.43/) documentation
Expand Down
9 changes: 4 additions & 5 deletions integration/system/disk_usage_test.go
Expand Up @@ -57,11 +57,10 @@ func TestDiskUsage(t *testing.T) {
LayersSize: du.LayersSize,
Images: []*types.ImageSummary{
{
Created: du.Images[0].Created,
ID: du.Images[0].ID,
RepoTags: []string{"busybox:latest"},
Size: du.LayersSize,
VirtualSize: du.LayersSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
Created: du.Images[0].Created,
ID: du.Images[0].ID,
RepoTags: []string{"busybox:latest"},
Size: du.LayersSize,
},
},
Containers: []*types.Container{},
Expand Down

0 comments on commit 1371aee

Please sign in to comment.