Merge pull request #4242 from thaJeztah/dont_use_deprecated_virtualsize

remove uses of deprecated VirtualSize field
This commit is contained in:
Sebastiaan van Stijn 2023-04-28 15:51:49 +02:00 committed by GitHub
commit 69181952e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

View File

@ -14,7 +14,7 @@ import (
)
const (
defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.VirtualSize}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}"
defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.Size}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}"
defaultDiskUsageContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.Size}}\t{{.RunningFor}}\t{{.Status}}\t{{.Names}}"
defaultDiskUsageVolumeTableFormat = "table {{.Name}}\t{{.Links}}\t{{.Size}}"
defaultDiskUsageBuildCacheTableFormat = "table {{.ID}}\t{{.CacheType}}\t{{.Size}}\t{{.CreatedSince}}\t{{.LastUsedSince}}\t{{.UsageCount}}\t{{.Shared}}"
@ -296,10 +296,10 @@ func (c *diskUsageImagesContext) Reclaimable() string {
for _, i := range c.images {
if i.Containers != 0 {
if i.VirtualSize == -1 || i.SharedSize == -1 {
if i.Size == -1 || i.SharedSize == -1 {
continue
}
used += i.VirtualSize - i.SharedSize
used += i.Size - i.SharedSize
}
}

View File

@ -205,7 +205,7 @@ func newImageContext() *imageContext {
"CreatedAt": CreatedAtHeader,
"Size": SizeHeader,
"Containers": containersHeader,
"VirtualSize": SizeHeader,
"VirtualSize": SizeHeader, // Deprecated: VirtualSize is deprecated, and equivalent to Size.
"SharedSize": sharedSizeHeader,
"UniqueSize": uniqueSizeHeader,
}
@ -260,8 +260,13 @@ func (c *imageContext) Containers() string {
return fmt.Sprintf("%d", c.i.Containers)
}
// VirtualSize shows the virtual size of the image and all of its parent
// images. Starting with docker 1.10, images are self-contained, and
// the VirtualSize is identical to Size.
//
// Deprecated: VirtualSize is deprecated, and equivalent to [imageContext.Size].
func (c *imageContext) VirtualSize() string {
return units.HumanSize(float64(c.i.VirtualSize))
return units.HumanSize(float64(c.i.Size))
}
func (c *imageContext) SharedSize() string {
@ -272,8 +277,8 @@ func (c *imageContext) SharedSize() string {
}
func (c *imageContext) UniqueSize() string {
if c.i.VirtualSize == -1 || c.i.SharedSize == -1 {
if c.i.Size == -1 || c.i.SharedSize == -1 {
return "N/A"
}
return units.HumanSize(float64(c.i.VirtualSize - c.i.SharedSize))
return units.HumanSize(float64(c.i.Size - c.i.SharedSize))
}

View File

@ -36,7 +36,7 @@ func TestImageContext(t *testing.T) {
call: ctx.ID,
},
{
imageCtx: imageContext{i: types.ImageSummary{Size: 10, VirtualSize: 10}, trunc: true},
imageCtx: imageContext{i: types.ImageSummary{Size: 10}, trunc: true},
expValue: "10B",
call: ctx.Size,
},
@ -70,9 +70,9 @@ func TestImageContext(t *testing.T) {
call: ctx.Containers,
},
{
imageCtx: imageContext{i: types.ImageSummary{VirtualSize: 10000}},
imageCtx: imageContext{i: types.ImageSummary{Size: 10000}},
expValue: "10kB",
call: ctx.VirtualSize,
call: ctx.VirtualSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
},
{
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 10000}},
@ -80,7 +80,7 @@ func TestImageContext(t *testing.T) {
call: ctx.SharedSize,
},
{
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 5000, VirtualSize: 20000}},
imageCtx: imageContext{i: types.ImageSummary{SharedSize: 5000, Size: 20000}},
expValue: "15kB",
call: ctx.UniqueSize,
},