Skip to content

Commit 82c069c

Browse files
committed
api/types/system: move DiskUsage, DiskUsageOptions to api/types/backend
These types were introduced in f07242f, but while their description mentions it's the type used for the response, it actually isn't, and it's used by the backend, but ultimately marshaled to the "types.DiskUsage" struct; https://github.com/moby/moby/blob/7dc46c6e0c727a746ecfb8427c0c3cbd998059bc/daemon/server/router/system/system_routes.go#L254-L270 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 436a546 commit 82c069c

7 files changed

Lines changed: 67 additions & 54 deletions

File tree

api/types/backend/disk_usage.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package backend
2+
3+
import (
4+
"github.com/moby/moby/api/types/build"
5+
"github.com/moby/moby/api/types/container"
6+
"github.com/moby/moby/api/types/image"
7+
"github.com/moby/moby/api/types/volume"
8+
)
9+
10+
// DiskUsageOptions holds parameters for system disk usage query.
11+
type DiskUsageOptions struct {
12+
// Containers controls whether container disk usage should be computed.
13+
Containers bool
14+
15+
// Images controls whether image disk usage should be computed.
16+
Images bool
17+
18+
// Volumes controls whether volume disk usage should be computed.
19+
Volumes bool
20+
}
21+
22+
// DiskUsage contains the information returned by the backend for the
23+
// GET "/system/df" endpoint.
24+
type DiskUsage struct {
25+
Images *image.DiskUsage
26+
Containers *container.DiskUsage
27+
Volumes *volume.DiskUsage
28+
BuildCache *build.CacheDiskUsage
29+
}

api/types/system/disk_usage.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

daemon/disk_usage.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/docker/docker/daemon/server/router/system"
7+
"github.com/moby/moby/api/types/backend"
88
"github.com/moby/moby/api/types/container"
99
"github.com/moby/moby/api/types/filters"
1010
"github.com/moby/moby/api/types/image"
11-
systemtypes "github.com/moby/moby/api/types/system"
1211
"github.com/moby/moby/api/types/volume"
1312
"github.com/pkg/errors"
1413
"golang.org/x/sync/errgroup"
@@ -103,10 +102,10 @@ func (daemon *Daemon) layerDiskUsage(ctx context.Context) (int64, error) {
103102

104103
// SystemDiskUsage returns information about the daemon data disk usage.
105104
// Callers must not mutate contents of the returned fields.
106-
func (daemon *Daemon) SystemDiskUsage(ctx context.Context, opts system.DiskUsageOptions) (*systemtypes.DiskUsage, error) {
105+
func (daemon *Daemon) SystemDiskUsage(ctx context.Context, opts backend.DiskUsageOptions) (*backend.DiskUsage, error) {
107106
eg, ctx := errgroup.WithContext(ctx)
108107

109-
du := &systemtypes.DiskUsage{}
108+
du := &backend.DiskUsage{}
110109
if opts.Containers {
111110
eg.Go(func() (err error) {
112111
du.Containers, err = daemon.containerDiskUsage(ctx)

daemon/server/router/system/backend.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/moby/moby/api/types"
8+
"github.com/moby/moby/api/types/backend"
89
"github.com/moby/moby/api/types/build"
910
"github.com/moby/moby/api/types/events"
1011
"github.com/moby/moby/api/types/filters"
@@ -13,24 +14,12 @@ import (
1314
"github.com/moby/moby/api/types/system"
1415
)
1516

16-
// DiskUsageOptions holds parameters for system disk usage query.
17-
type DiskUsageOptions struct {
18-
// Containers controls whether container disk usage should be computed.
19-
Containers bool
20-
21-
// Images controls whether image disk usage should be computed.
22-
Images bool
23-
24-
// Volumes controls whether volume disk usage should be computed.
25-
Volumes bool
26-
}
27-
2817
// Backend is the methods that need to be implemented to provide
2918
// system specific functionality.
3019
type Backend interface {
3120
SystemInfo(context.Context) (*system.Info, error)
3221
SystemVersion(context.Context) (types.Version, error)
33-
SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*system.DiskUsage, error)
22+
SystemDiskUsage(ctx context.Context, opts backend.DiskUsageOptions) (*backend.DiskUsage, error)
3423
SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{})
3524
UnsubscribeFromEvents(chan interface{})
3625
AuthenticateToRegistry(ctx context.Context, authConfig *registry.AuthConfig) (string, error)

daemon/server/router/system/system_routes.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/docker/docker/daemon/server/router/build"
1616
"github.com/docker/docker/pkg/ioutils"
1717
"github.com/moby/moby/api/types"
18+
"github.com/moby/moby/api/types/backend"
1819
buildtypes "github.com/moby/moby/api/types/build"
1920
"github.com/moby/moby/api/types/events"
2021
"github.com/moby/moby/api/types/filters"
@@ -183,11 +184,11 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter,
183184

184185
eg, ctx := errgroup.WithContext(ctx)
185186

186-
var systemDiskUsage *system.DiskUsage
187+
var systemDiskUsage *backend.DiskUsage
187188
if getContainers || getImages || getVolumes {
188189
eg.Go(func() error {
189190
var err error
190-
systemDiskUsage, err = s.backend.SystemDiskUsage(ctx, DiskUsageOptions{
191+
systemDiskUsage, err = s.backend.SystemDiskUsage(ctx, backend.DiskUsageOptions{
191192
Containers: getContainers,
192193
Images: getImages,
193194
Volumes: getVolumes,
@@ -238,7 +239,7 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter,
238239
}
239240
}
240241

241-
du := system.DiskUsage{}
242+
du := backend.DiskUsage{}
242243
if getBuildCache {
243244
du.BuildCache = &buildtypes.CacheDiskUsage{
244245
TotalSize: builderSize,

vendor/github.com/moby/moby/api/types/backend/disk_usage.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/moby/moby/api/types/system/disk_usage.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)