Merge pull request #50764 from austinvazquez/move-disk-usage-types-to-daemon-backend

api/types: move disk usage structs to daemon backend
This commit is contained in:
Sebastiaan van Stijn
2025-08-20 18:33:54 +02:00
committed by GitHub
12 changed files with 42 additions and 80 deletions

View File

@@ -1,8 +0,0 @@
package build
// CacheDiskUsage contains disk usage for the build cache.
type CacheDiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*CacheRecord
}

View File

@@ -1,8 +0,0 @@
package container
// DiskUsage contains disk usage for containers.
type DiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*Summary
}

View File

@@ -1,8 +0,0 @@
package image
// DiskUsage contains disk usage for images.
type DiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*Summary
}

View File

@@ -1,8 +0,0 @@
package volume
// DiskUsage contains disk usage for volumes.
type DiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*Volume
}

View File

@@ -38,7 +38,6 @@ import (
networktypes "github.com/moby/moby/api/types/network"
registrytypes "github.com/moby/moby/api/types/registry"
"github.com/moby/moby/api/types/swarm"
volumetypes "github.com/moby/moby/api/types/volume"
"github.com/moby/sys/user"
"github.com/moby/sys/userns"
"github.com/pkg/errors"
@@ -134,9 +133,9 @@ type Daemon struct {
seccompProfile []byte
seccompProfilePath string
usageContainers singleflight.Group[struct{}, *containertypes.DiskUsage]
usageContainers singleflight.Group[struct{}, *backend.ContainerDiskUsage]
usageImages singleflight.Group[struct{}, []*imagetypes.Summary]
usageVolumes singleflight.Group[struct{}, *volumetypes.DiskUsage]
usageVolumes singleflight.Group[struct{}, *backend.VolumeDiskUsage]
usageLayer singleflight.Group[struct{}, int64]
pruneRunning atomic.Bool

View File

@@ -7,7 +7,6 @@ import (
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/api/types/volume"
"github.com/moby/moby/v2/daemon/server/backend"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
@@ -15,8 +14,8 @@ import (
// containerDiskUsage obtains information about container data disk usage
// and makes sure that only one calculation is performed at the same time.
func (daemon *Daemon) containerDiskUsage(ctx context.Context) (*container.DiskUsage, error) {
res, _, err := daemon.usageContainers.Do(ctx, struct{}{}, func(ctx context.Context) (*container.DiskUsage, error) {
func (daemon *Daemon) containerDiskUsage(ctx context.Context) (*backend.ContainerDiskUsage, error) {
res, _, err := daemon.usageContainers.Do(ctx, struct{}{}, func(ctx context.Context) (*backend.ContainerDiskUsage, error) {
// Retrieve container list
containers, err := daemon.Containers(ctx, &container.ListOptions{
Size: true,
@@ -38,7 +37,7 @@ func (daemon *Daemon) containerDiskUsage(ctx context.Context) (*container.DiskUs
ctr.State == container.StateRestarting
}
du := &container.DiskUsage{Items: containers}
du := &backend.ContainerDiskUsage{Items: containers}
for _, ctr := range du.Items {
du.TotalSize += ctr.SizeRw
if !isActive(ctr) {
@@ -70,14 +69,14 @@ func (daemon *Daemon) imageDiskUsage(ctx context.Context) ([]*image.Summary, err
// localVolumesSize obtains information about volume disk usage from volumes service
// and makes sure that only one size calculation is performed at the same time.
func (daemon *Daemon) localVolumesSize(ctx context.Context) (*volume.DiskUsage, error) {
volumes, _, err := daemon.usageVolumes.Do(ctx, struct{}{}, func(ctx context.Context) (*volume.DiskUsage, error) {
func (daemon *Daemon) localVolumesSize(ctx context.Context) (*backend.VolumeDiskUsage, error) {
volumes, _, err := daemon.usageVolumes.Do(ctx, struct{}{}, func(ctx context.Context) (*backend.VolumeDiskUsage, error) {
volumes, err := daemon.volumes.LocalVolumesSize(ctx)
if err != nil {
return nil, err
}
du := &volume.DiskUsage{Items: volumes}
du := &backend.VolumeDiskUsage{Items: volumes}
for _, v := range du.Items {
if v.UsageData.Size != -1 {
if v.UsageData.RefCount == 0 {
@@ -150,7 +149,7 @@ func (daemon *Daemon) SystemDiskUsage(ctx context.Context, opts backend.DiskUsag
}
}
du.Images = &image.DiskUsage{
du.Images = &backend.ImageDiskUsage{
TotalSize: layersSize,
Reclaimable: reclaimable,
Items: images,

View File

@@ -22,8 +22,36 @@ type DiskUsageOptions struct {
// DiskUsage contains the information returned by the backend for the
// GET "/system/df" endpoint.
type DiskUsage struct {
Images *image.DiskUsage
Containers *container.DiskUsage
Volumes *volume.DiskUsage
BuildCache *build.CacheDiskUsage
Images *ImageDiskUsage
Containers *ContainerDiskUsage
Volumes *VolumeDiskUsage
BuildCache *BuildCacheDiskUsage
}
// BuildCacheDiskUsage contains disk usage for the build cache.
type BuildCacheDiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*build.CacheRecord
}
// ContainerDiskUsage contains disk usage for containers.
type ContainerDiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*container.Summary
}
// ImageDiskUsage contains disk usage for images.
type ImageDiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*image.Summary
}
// VolumeDiskUsage contains disk usage for volumes.
type VolumeDiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*volume.Volume
}

View File

@@ -237,7 +237,7 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter,
du := backend.DiskUsage{}
if getBuildCache {
du.BuildCache = &buildtypes.CacheDiskUsage{
du.BuildCache = &backend.BuildCacheDiskUsage{
TotalSize: builderSize,
Items: buildCache,
}

View File

@@ -1,8 +0,0 @@
package build
// CacheDiskUsage contains disk usage for the build cache.
type CacheDiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*CacheRecord
}

View File

@@ -1,8 +0,0 @@
package container
// DiskUsage contains disk usage for containers.
type DiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*Summary
}

View File

@@ -1,8 +0,0 @@
package image
// DiskUsage contains disk usage for images.
type DiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*Summary
}

View File

@@ -1,8 +0,0 @@
package volume
// DiskUsage contains disk usage for volumes.
type DiskUsage struct {
TotalSize int64
Reclaimable int64
Items []*Volume
}