Skip to content

Commit f02301a

Browse files
committed
remove uses of deprecated VirtualSize field
The VirtualSize field is deprecated and the upcoming API version v1.44 will no longer propagate the field. See: moby/moby@1261fe6, Given that in docker 1.10 and up (API v1.22), the VirtualSize and Size fields contain the same value, and the "df" endpoint was not supported until API v1.25, we can "safely" use Size instead; see: - 4ae7176 - moby/moby@4352da7 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 59b07b7 commit f02301a

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

cli/command/formatter/disk_usage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.VirtualSize}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}"
17+
defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.Size}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}"
1818
defaultDiskUsageContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.Size}}\t{{.RunningFor}}\t{{.Status}}\t{{.Names}}"
1919
defaultDiskUsageVolumeTableFormat = "table {{.Name}}\t{{.Links}}\t{{.Size}}"
2020
defaultDiskUsageBuildCacheTableFormat = "table {{.ID}}\t{{.CacheType}}\t{{.Size}}\t{{.CreatedSince}}\t{{.LastUsedSince}}\t{{.UsageCount}}\t{{.Shared}}"
@@ -296,10 +296,10 @@ func (c *diskUsageImagesContext) Reclaimable() string {
296296

297297
for _, i := range c.images {
298298
if i.Containers != 0 {
299-
if i.VirtualSize == -1 || i.SharedSize == -1 {
299+
if i.Size == -1 || i.SharedSize == -1 {
300300
continue
301301
}
302-
used += i.VirtualSize - i.SharedSize
302+
used += i.Size - i.SharedSize
303303
}
304304
}
305305

cli/command/formatter/image.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func newImageContext() *imageContext {
205205
"CreatedAt": CreatedAtHeader,
206206
"Size": SizeHeader,
207207
"Containers": containersHeader,
208-
"VirtualSize": SizeHeader,
208+
"VirtualSize": SizeHeader, // Deprecated: VirtualSize is deprecated, and equivalent to Size.
209209
"SharedSize": sharedSizeHeader,
210210
"UniqueSize": uniqueSizeHeader,
211211
}
@@ -260,8 +260,13 @@ func (c *imageContext) Containers() string {
260260
return fmt.Sprintf("%d", c.i.Containers)
261261
}
262262

263+
// VirtualSize shows the virtual size of the image and all of its parent
264+
// images. Starting with docker 1.10, images are self-contained, and
265+
// the VirtualSize is identical to Size.
266+
//
267+
// Deprecated: VirtualSize is deprecated, and equivalent to [imageContext.Size].
263268
func (c *imageContext) VirtualSize() string {
264-
return units.HumanSize(float64(c.i.VirtualSize))
269+
return units.HumanSize(float64(c.i.Size))
265270
}
266271

267272
func (c *imageContext) SharedSize() string {
@@ -272,8 +277,8 @@ func (c *imageContext) SharedSize() string {
272277
}
273278

274279
func (c *imageContext) UniqueSize() string {
275-
if c.i.VirtualSize == -1 || c.i.SharedSize == -1 {
280+
if c.i.Size == -1 || c.i.SharedSize == -1 {
276281
return "N/A"
277282
}
278-
return units.HumanSize(float64(c.i.VirtualSize - c.i.SharedSize))
283+
return units.HumanSize(float64(c.i.Size - c.i.SharedSize))
279284
}

cli/command/formatter/image_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestImageContext(t *testing.T) {
3636
call: ctx.ID,
3737
},
3838
{
39-
imageCtx: imageContext{i: types.ImageSummary{Size: 10, VirtualSize: 10}, trunc: true},
39+
imageCtx: imageContext{i: types.ImageSummary{Size: 10}, trunc: true},
4040
expValue: "10B",
4141
call: ctx.Size,
4242
},
@@ -70,17 +70,17 @@ func TestImageContext(t *testing.T) {
7070
call: ctx.Containers,
7171
},
7272
{
73-
imageCtx: imageContext{i: types.ImageSummary{VirtualSize: 10000}},
73+
imageCtx: imageContext{i: types.ImageSummary{Size: 10000}},
7474
expValue: "10kB",
75-
call: ctx.VirtualSize,
75+
call: ctx.VirtualSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
7676
},
7777
{
7878
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 10000}},
7979
expValue: "10kB",
8080
call: ctx.SharedSize,
8181
},
8282
{
83-
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 5000, VirtualSize: 20000}},
83+
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 5000, Size: 20000}},
8484
expValue: "15kB",
8585
call: ctx.UniqueSize,
8686
},

0 commit comments

Comments
 (0)