1
0
mirror of https://github.com/docker/cli.git synced 2026-01-26 15:41:42 +03:00

Merge pull request #6641 from thaJeztah/bump_modules

vendor: github.com/moby/moby/api, moby/client master
This commit is contained in:
Paweł Gronowski
2025-11-10 17:03:43 +01:00
committed by GitHub
29 changed files with 146 additions and 155 deletions

View File

@@ -8,23 +8,23 @@ import (
type fakeClient struct {
client.Client
checkpointCreateFunc func(container string, options client.CheckpointCreateOptions) error
checkpointDeleteFunc func(container string, options client.CheckpointDeleteOptions) error
checkpointCreateFunc func(container string, options client.CheckpointCreateOptions) (client.CheckpointCreateResult, error)
checkpointDeleteFunc func(container string, options client.CheckpointRemoveOptions) (client.CheckpointRemoveResult, error)
checkpointListFunc func(container string, options client.CheckpointListOptions) (client.CheckpointListResult, error)
}
func (cli *fakeClient) CheckpointCreate(_ context.Context, container string, options client.CheckpointCreateOptions) error {
func (cli *fakeClient) CheckpointCreate(_ context.Context, container string, options client.CheckpointCreateOptions) (client.CheckpointCreateResult, error) {
if cli.checkpointCreateFunc != nil {
return cli.checkpointCreateFunc(container, options)
}
return nil
return client.CheckpointCreateResult{}, nil
}
func (cli *fakeClient) CheckpointDelete(_ context.Context, container string, options client.CheckpointDeleteOptions) error {
func (cli *fakeClient) CheckpointRemove(_ context.Context, container string, options client.CheckpointRemoveOptions) (client.CheckpointRemoveResult, error) {
if cli.checkpointDeleteFunc != nil {
return cli.checkpointDeleteFunc(container, options)
}
return nil
return client.CheckpointRemoveResult{}, nil
}
func (cli *fakeClient) CheckpointList(_ context.Context, container string, options client.CheckpointListOptions) (client.CheckpointListResult, error) {

View File

@@ -41,7 +41,7 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
}
func runCreate(ctx context.Context, dockerCLI command.Cli, opts createOptions) error {
err := dockerCLI.Client().CheckpointCreate(ctx, opts.container, client.CheckpointCreateOptions{
_, err := dockerCLI.Client().CheckpointCreate(ctx, opts.container, client.CheckpointCreateOptions{
CheckpointID: opts.checkpoint,
CheckpointDir: opts.checkpointDir,
Exit: !opts.leaveRunning,

View File

@@ -16,7 +16,7 @@ import (
func TestCheckpointCreateErrors(t *testing.T) {
testCases := []struct {
args []string
checkpointCreateFunc func(container string, options client.CheckpointCreateOptions) error
checkpointCreateFunc func(container string, options client.CheckpointCreateOptions) (client.CheckpointCreateResult, error)
expectedError string
}{
{
@@ -29,8 +29,8 @@ func TestCheckpointCreateErrors(t *testing.T) {
},
{
args: []string{"foo", "bar"},
checkpointCreateFunc: func(container string, options client.CheckpointCreateOptions) error {
return errors.New("error creating checkpoint for container foo")
checkpointCreateFunc: func(container string, options client.CheckpointCreateOptions) (client.CheckpointCreateResult, error) {
return client.CheckpointCreateResult{}, errors.New("error creating checkpoint for container foo")
},
expectedError: "error creating checkpoint for container foo",
},
@@ -61,10 +61,10 @@ func TestCheckpointCreateWithOptions(t *testing.T) {
var actualContainerName string
var actualOptions client.CheckpointCreateOptions
cli := test.NewFakeCli(&fakeClient{
checkpointCreateFunc: func(container string, options client.CheckpointCreateOptions) error {
checkpointCreateFunc: func(container string, options client.CheckpointCreateOptions) (client.CheckpointCreateResult, error) {
actualContainerName = container
actualOptions = options
return nil
return client.CheckpointCreateResult{}, nil
},
})
cmd := newCreateCommand(cli)

View File

@@ -48,5 +48,5 @@ func runList(ctx context.Context, dockerCLI command.Cli, container string, opts
Output: dockerCLI.Out(),
Format: newFormat(formatter.TableFormatKey),
}
return formatWrite(cpCtx, checkpoints.Checkpoints)
return formatWrite(cpCtx, checkpoints.Items)
}

View File

@@ -55,7 +55,7 @@ func TestCheckpointListWithOptions(t *testing.T) {
containerID = container
checkpointDir = options.CheckpointDir
return client.CheckpointListResult{
Checkpoints: []checkpoint.Summary{
Items: []checkpoint.Summary{
{Name: "checkpoint-foo"},
},
}, nil
@@ -63,7 +63,7 @@ func TestCheckpointListWithOptions(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.SetArgs([]string{"container-foo"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.Check(t, cmd.Flags().Set("checkpoint-dir", "/dir/foo"))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("container-foo", containerID))
assert.Check(t, is.Equal("/dir/foo", checkpointDir))

View File

@@ -1,8 +1,6 @@
package checkpoint
import (
"context"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
@@ -22,7 +20,12 @@ func newRemoveCommand(dockerCLI command.Cli) *cobra.Command {
Short: "Remove a checkpoint",
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return runRemove(cmd.Context(), dockerCLI, args[0], args[1], opts)
containerID, checkpointID := args[0], args[1]
_, err := dockerCLI.Client().CheckpointRemove(cmd.Context(), containerID, client.CheckpointRemoveOptions{
CheckpointID: checkpointID,
CheckpointDir: opts.checkpointDir,
})
return err
},
DisableFlagsInUseLine: true,
}
@@ -32,10 +35,3 @@ func newRemoveCommand(dockerCLI command.Cli) *cobra.Command {
return cmd
}
func runRemove(ctx context.Context, dockerCli command.Cli, container string, checkpointID string, opts removeOptions) error {
return dockerCli.Client().CheckpointDelete(ctx, container, client.CheckpointDeleteOptions{
CheckpointID: checkpointID,
CheckpointDir: opts.checkpointDir,
})
}

View File

@@ -14,7 +14,7 @@ import (
func TestCheckpointRemoveErrors(t *testing.T) {
testCases := []struct {
args []string
checkpointDeleteFunc func(container string, options client.CheckpointDeleteOptions) error
checkpointDeleteFunc func(container string, options client.CheckpointRemoveOptions) (client.CheckpointRemoveResult, error)
expectedError string
}{
{
@@ -27,8 +27,8 @@ func TestCheckpointRemoveErrors(t *testing.T) {
},
{
args: []string{"foo", "bar"},
checkpointDeleteFunc: func(container string, options client.CheckpointDeleteOptions) error {
return errors.New("error deleting checkpoint")
checkpointDeleteFunc: func(container string, options client.CheckpointRemoveOptions) (client.CheckpointRemoveResult, error) {
return client.CheckpointRemoveResult{}, errors.New("error deleting checkpoint")
},
expectedError: "error deleting checkpoint",
},
@@ -49,16 +49,16 @@ func TestCheckpointRemoveErrors(t *testing.T) {
func TestCheckpointRemoveWithOptions(t *testing.T) {
var containerID, checkpointID, checkpointDir string
cli := test.NewFakeCli(&fakeClient{
checkpointDeleteFunc: func(container string, options client.CheckpointDeleteOptions) error {
checkpointDeleteFunc: func(container string, options client.CheckpointRemoveOptions) (client.CheckpointRemoveResult, error) {
containerID = container
checkpointID = options.CheckpointID
checkpointDir = options.CheckpointDir
return nil
return client.CheckpointRemoveResult{}, nil
},
})
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"container-foo", "checkpoint-bar"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.Check(t, cmd.Flags().Set("checkpoint-dir", "/dir/foo"))
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("container-foo", containerID))
assert.Check(t, is.Equal("checkpoint-bar", checkpointID))

View File

@@ -247,7 +247,7 @@ func (c *ContainerContext) Ports() string {
// State returns the container's current state (e.g. "running" or "paused").
// Refer to [container.ContainerState] for possible states.
func (c *ContainerContext) State() string {
return c.c.State
return string(c.c.State)
}
// Status returns the container's status in a human readable form (for example,

View File

@@ -152,7 +152,7 @@ func TestContainerPsContext(t *testing.T) {
{
container: container.Summary{State: container.StateRunning},
trunc: true,
expValue: container.StateRunning,
expValue: string(container.StateRunning),
call: ctx.State,
},
{

View File

@@ -55,7 +55,7 @@ func formatWrite(fmtCtx formatter.Context, plugins client.PluginListResult) erro
for _, p := range plugins.Items {
if err := format(&pluginContext{
trunc: fmtCtx.Trunc,
p: *p,
p: p,
}); err != nil {
return err
}

View File

@@ -148,7 +148,7 @@ foobar_bar
}
plugins := client.PluginListResult{
Items: []*plugin.Plugin{
Items: []plugin.Plugin{
{ID: "pluginID1", Name: "foobar_baz", Config: plugin.Config{Description: "description 1"}, Enabled: true},
{ID: "pluginID2", Name: "foobar_bar", Config: plugin.Config{Description: "description 2"}, Enabled: false},
},
@@ -171,7 +171,7 @@ foobar_bar
func TestPluginContextWriteJSON(t *testing.T) {
plugins := client.PluginListResult{
Items: []*plugin.Plugin{
Items: []plugin.Plugin{
{ID: "pluginID1", Name: "foobar_baz"},
{ID: "pluginID2", Name: "foobar_bar"},
},
@@ -197,7 +197,7 @@ func TestPluginContextWriteJSON(t *testing.T) {
func TestPluginContextWriteJSONField(t *testing.T) {
plugins := client.PluginListResult{
Items: []*plugin.Plugin{
Items: []plugin.Plugin{
{ID: "pluginID1", Name: "foobar_baz"},
{ID: "pluginID2", Name: "foobar_bar"},
},

View File

@@ -119,7 +119,7 @@ func TestList(t *testing.T) {
golden: "plugin-list-with-no-trunc-option.golden",
listFunc: func(opts client.PluginListOptions) (client.PluginListResult, error) {
return client.PluginListResult{
Items: []*plugin.Plugin{{
Items: []plugin.Plugin{{
ID: "xyg4z2hiSLO5yTnBJfg4OYia9gKA6Qjd",
Name: "name-foo",
Enabled: true,
@@ -148,7 +148,7 @@ func TestList(t *testing.T) {
golden: "plugin-list-sort.golden",
listFunc: func(client.PluginListOptions) (client.PluginListResult, error) {
return client.PluginListResult{
Items: []*plugin.Plugin{
Items: []plugin.Plugin{
{
ID: "id-1",
Name: "plugin-1-foo",

View File

@@ -28,8 +28,8 @@ require (
github.com/google/uuid v1.6.0
github.com/mattn/go-runewidth v0.0.19
github.com/moby/go-archive v0.1.0
github.com/moby/moby/api v1.52.0-rc.1
github.com/moby/moby/client v0.1.0-rc.1
github.com/moby/moby/api v1.52.0-rc.1.0.20251110152122-7cff366d4383 // master
github.com/moby/moby/client v0.1.0-rc.1.0.20251110152122-7cff366d4383 // master
github.com/moby/patternmatcher v0.6.0
github.com/moby/swarmkit/v2 v2.1.1
github.com/moby/sys/atomicwriter v0.1.0

View File

@@ -113,10 +113,10 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ=
github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo=
github.com/moby/moby/api v1.52.0-rc.1 h1:yiNz/QzD4Jr1gyKl2iMo7OCZwwY+Xb3BltKv1xipwXo=
github.com/moby/moby/api v1.52.0-rc.1/go.mod h1:v0K/motq8oWmx+rtApG1rBTIpQ8KUONUjpf+U73gags=
github.com/moby/moby/client v0.1.0-rc.1 h1:NfuQec3HvQkPf4EvVkoFGPsBvlAc8CCyQN1m1kGSEX8=
github.com/moby/moby/client v0.1.0-rc.1/go.mod h1:qYzoKHz8qu4Ie1j41CWYhfNRHo8uhs5ay7cfx309Aqc=
github.com/moby/moby/api v1.52.0-rc.1.0.20251110152122-7cff366d4383 h1:EtwsCC5qh3+Q08G4m2X+mvkl4iXaVwbLjib4UgZmtY0=
github.com/moby/moby/api v1.52.0-rc.1.0.20251110152122-7cff366d4383/go.mod h1:v0K/motq8oWmx+rtApG1rBTIpQ8KUONUjpf+U73gags=
github.com/moby/moby/client v0.1.0-rc.1.0.20251110152122-7cff366d4383 h1:OBG6NXd/rSJDsfjwe2y7W2swcqiW8/wGrdKB46QgN+A=
github.com/moby/moby/client v0.1.0-rc.1.0.20251110152122-7cff366d4383/go.mod h1:DYvby7ZKcDKbvuhs4/gBptKp+fqMLz0RhVIPUMy+H/Q=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/swarmkit/v2 v2.1.1 h1:yvTJ8MMCc3f0qTA44J6R59EZ5yZawdYopkpuLk4+ICU=

View File

@@ -7,9 +7,7 @@ import (
)
// HealthStatus is a string representation of the container's health.
//
// It currently is an alias for string, but may become a distinct type in future.
type HealthStatus = string
type HealthStatus string
// Health states
const (
@@ -41,7 +39,10 @@ type HealthcheckResult struct {
}
var validHealths = []string{
NoHealthcheck, Starting, Healthy, Unhealthy,
string(NoHealthcheck),
string(Starting),
string(Healthy),
string(Unhealthy),
}
// ValidateHealthStatus checks if the provided string is a valid

View File

@@ -6,9 +6,7 @@ import (
)
// ContainerState is a string representation of the container's current state.
//
// It currently is an alias for string, but may become a distinct type in the future.
type ContainerState = string
type ContainerState string
const (
StateCreated ContainerState = "created" // StateCreated indicates the container is created, but not (yet) started.
@@ -20,8 +18,14 @@ const (
StateDead ContainerState = "dead" // StateDead indicates that the container failed to be deleted. Containers in this state are attempted to be cleaned up when the daemon restarts.
)
var validStates = []ContainerState{
StateCreated, StateRunning, StatePaused, StateRestarting, StateRemoving, StateExited, StateDead,
var validStates = []string{
string(StateCreated),
string(StateRunning),
string(StatePaused),
string(StateRestarting),
string(StateRemoving),
string(StateExited),
string(StateDead),
}
// ValidateContainerState checks if the provided string is a valid

View File

@@ -5,7 +5,7 @@ import (
)
// ListResponse contains the response for the Engine API
type ListResponse []*Plugin
type ListResponse []Plugin
// Privilege describes a permission the user has to accept
// upon installing a plugin.

View File

@@ -24,27 +24,8 @@ const (
// DiskUsage contains response of Engine API:
// GET "/system/df"
type DiskUsage struct {
LegacyDiskUsage
ImageUsage *image.DiskUsage `json:"ImageUsage,omitempty"`
ContainerUsage *container.DiskUsage `json:"ContainerUsage,omitempty"`
VolumeUsage *volume.DiskUsage `json:"VolumeUsage,omitempty"`
BuildCacheUsage *build.DiskUsage `json:"BuildCacheUsage,omitempty"`
}
type LegacyDiskUsage struct {
// Deprecated: kept to maintain backwards compatibility with API < v1.52, use [ImagesDiskUsage.TotalSize] instead.
LayersSize int64 `json:"LayersSize,omitempty"`
// Deprecated: kept to maintain backwards compatibility with API < v1.52, use [ImagesDiskUsage.Items] instead.
Images []image.Summary `json:"Images,omitzero"`
// Deprecated: kept to maintain backwards compatibility with API < v1.52, use [ContainersDiskUsage.Items] instead.
Containers []container.Summary `json:"Containers,omitzero"`
// Deprecated: kept to maintain backwards compatibility with API < v1.52, use [VolumesDiskUsage.Items] instead.
Volumes []volume.Volume `json:"Volumes,omitzero"`
// Deprecated: kept to maintain backwards compatibility with API < v1.52, use [BuildCacheDiskUsage.Items] instead.
BuildCache []build.CacheRecord `json:"BuildCache,omitzero"`
}

View File

@@ -13,7 +13,7 @@ package volume
type ListResponse struct {
// List of volumes
Volumes []*Volume `json:"Volumes"`
Volumes []Volume `json:"Volumes"`
// Warnings that occurred when fetching the list of volumes.
//

View File

@@ -1,16 +0,0 @@
package client
import (
"context"
)
// CheckpointAPIClient defines API client methods for the checkpoints.
//
// Experimental: checkpoint and restore is still an experimental feature,
// and only available if the daemon is running with experimental features
// enabled.
type CheckpointAPIClient interface {
CheckpointCreate(ctx context.Context, container string, options CheckpointCreateOptions) error
CheckpointDelete(ctx context.Context, container string, options CheckpointDeleteOptions) error
CheckpointList(ctx context.Context, container string, options CheckpointListOptions) (CheckpointListResult, error)
}

View File

@@ -13,11 +13,16 @@ type CheckpointCreateOptions struct {
Exit bool
}
// CheckpointCreateResult holds the result from [client.CheckpointCreate].
type CheckpointCreateResult struct {
// Add future fields here
}
// CheckpointCreate creates a checkpoint from the given container.
func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options CheckpointCreateOptions) error {
func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options CheckpointCreateOptions) (CheckpointCreateResult, error) {
containerID, err := trimID("container", containerID)
if err != nil {
return err
return CheckpointCreateResult{}, err
}
requestBody := checkpoint.CreateRequest{
CheckpointID: options.CheckpointID,
@@ -27,5 +32,5 @@ func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, opt
resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, requestBody, nil)
defer ensureReaderClosed(resp)
return err
return CheckpointCreateResult{}, err
}

View File

@@ -1,29 +0,0 @@
package client
import (
"context"
"net/url"
)
// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container.
type CheckpointDeleteOptions struct {
CheckpointID string
CheckpointDir string
}
// CheckpointDelete deletes the checkpoint with the given name from the given container.
func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options CheckpointDeleteOptions) error {
containerID, err := trimID("container", containerID)
if err != nil {
return err
}
query := url.Values{}
if options.CheckpointDir != "" {
query.Set("dir", options.CheckpointDir)
}
resp, err := cli.delete(ctx, "/containers/"+containerID+"/checkpoints/"+options.CheckpointID, query, nil)
defer ensureReaderClosed(resp)
return err
}

View File

@@ -15,7 +15,7 @@ type CheckpointListOptions struct {
// CheckpointListResult holds the result from the CheckpointList method.
type CheckpointListResult struct {
Checkpoints []checkpoint.Summary
Items []checkpoint.Summary
}
// CheckpointList returns the checkpoints of the given container in the docker host.
@@ -33,6 +33,6 @@ func (cli *Client) CheckpointList(ctx context.Context, container string, options
return out, err
}
err = json.NewDecoder(resp.Body).Decode(&out.Checkpoints)
err = json.NewDecoder(resp.Body).Decode(&out.Items)
return out, err
}

View File

@@ -0,0 +1,34 @@
package client
import (
"context"
"net/url"
)
// CheckpointRemoveOptions holds parameters to delete a checkpoint from a container.
type CheckpointRemoveOptions struct {
CheckpointID string
CheckpointDir string
}
// CheckpointRemoveResult represents the result of [Client.CheckpointRemove].
type CheckpointRemoveResult struct {
// No fields currently; placeholder for future use.
}
// CheckpointRemove deletes the checkpoint with the given name from the given container.
func (cli *Client) CheckpointRemove(ctx context.Context, containerID string, options CheckpointRemoveOptions) (CheckpointRemoveResult, error) {
containerID, err := trimID("container", containerID)
if err != nil {
return CheckpointRemoveResult{}, err
}
query := url.Values{}
if options.CheckpointDir != "" {
query.Set("dir", options.CheckpointDir)
}
resp, err := cli.delete(ctx, "/containers/"+containerID+"/checkpoints/"+options.CheckpointID, query, nil)
defer ensureReaderClosed(resp)
return CheckpointRemoveResult{}, err
}

View File

@@ -49,6 +49,17 @@ type HijackDialer interface {
DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error)
}
// CheckpointAPIClient defines API client methods for the checkpoints.
//
// Experimental: checkpoint and restore is still an experimental feature,
// and only available if the daemon is running with experimental features
// enabled.
type CheckpointAPIClient interface {
CheckpointCreate(ctx context.Context, container string, options CheckpointCreateOptions) (CheckpointCreateResult, error)
CheckpointRemove(ctx context.Context, container string, options CheckpointRemoveOptions) (CheckpointRemoveResult, error)
CheckpointList(ctx context.Context, container string, options CheckpointListOptions) (CheckpointListResult, error)
}
// ContainerAPIClient defines API client methods for the containers
type ContainerAPIClient interface {
ContainerCreate(ctx context.Context, options ContainerCreateOptions) (ContainerCreateResult, error)

View File

@@ -15,7 +15,7 @@ type PluginListOptions struct {
// PluginListResult represents the result of a plugin list operation.
type PluginListResult struct {
Items []*plugin.Plugin
Items []plugin.Plugin
}
// PluginList returns the installed plugins

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"net/url"
"slices"
"strings"
"github.com/moby/moby/api/types/build"
"github.com/moby/moby/api/types/container"
@@ -149,14 +148,19 @@ func (cli *Client) DiskUsage(ctx context.Context, options DiskUsageOptions) (Dis
return DiskUsageResult{}, err
}
var du system.DiskUsage
if err := json.NewDecoder(resp.Body).Decode(&du); err != nil {
return DiskUsageResult{}, fmt.Errorf("Error retrieving disk usage: %v", err)
if versions.LessThan(cli.version, "1.52") {
// Generate result from a legacy response.
var du legacyDiskUsage
if err := json.NewDecoder(resp.Body).Decode(&du); err != nil {
return DiskUsageResult{}, fmt.Errorf("retrieving disk usage: %v", err)
}
return diskUsageResultFromLegacyAPI(&du), nil
}
// Generate result from a legacy response.
if versions.LessThan(cli.version, "1.52") {
return diskUsageResultFromLegacyAPI(&du), nil
var du system.DiskUsage
if err := json.NewDecoder(resp.Body).Decode(&du); err != nil {
return DiskUsageResult{}, fmt.Errorf("retrieving disk usage: %v", err)
}
var r DiskUsageResult
@@ -215,7 +219,16 @@ func (cli *Client) DiskUsage(ctx context.Context, options DiskUsageOptions) (Dis
return r, nil
}
func diskUsageResultFromLegacyAPI(du *system.DiskUsage) DiskUsageResult {
// legacyDiskUsage is the response as was used by API < v1.52.
type legacyDiskUsage struct {
LayersSize int64 `json:"LayersSize,omitempty"`
Images []image.Summary `json:"Images,omitzero"`
Containers []container.Summary `json:"Containers,omitzero"`
Volumes []volume.Volume `json:"Volumes,omitzero"`
BuildCache []build.CacheRecord `json:"BuildCache,omitzero"`
}
func diskUsageResultFromLegacyAPI(du *legacyDiskUsage) DiskUsageResult {
return DiskUsageResult{
Images: imageDiskUsageFromLegacyAPI(du),
Containers: containerDiskUsageFromLegacyAPI(du),
@@ -224,7 +237,7 @@ func diskUsageResultFromLegacyAPI(du *system.DiskUsage) DiskUsageResult {
}
}
func imageDiskUsageFromLegacyAPI(du *system.DiskUsage) ImagesDiskUsage {
func imageDiskUsageFromLegacyAPI(du *legacyDiskUsage) ImagesDiskUsage {
idu := ImagesDiskUsage{
TotalSize: du.LayersSize,
TotalCount: int64(len(du.Images)),
@@ -250,7 +263,7 @@ func imageDiskUsageFromLegacyAPI(du *system.DiskUsage) ImagesDiskUsage {
return idu
}
func containerDiskUsageFromLegacyAPI(du *system.DiskUsage) ContainersDiskUsage {
func containerDiskUsageFromLegacyAPI(du *legacyDiskUsage) ContainersDiskUsage {
cdu := ContainersDiskUsage{
TotalCount: int64(len(du.Containers)),
Items: du.Containers,
@@ -259,8 +272,8 @@ func containerDiskUsageFromLegacyAPI(du *system.DiskUsage) ContainersDiskUsage {
var used int64
for _, c := range cdu.Items {
cdu.TotalSize += c.SizeRw
switch strings.ToLower(c.State) {
case "running", "paused", "restarting":
switch c.State {
case container.StateRunning, container.StatePaused, container.StateRestarting:
cdu.ActiveCount++
used += c.SizeRw
}
@@ -270,7 +283,7 @@ func containerDiskUsageFromLegacyAPI(du *system.DiskUsage) ContainersDiskUsage {
return cdu
}
func buildCacheDiskUsageFromLegacyAPI(du *system.DiskUsage) BuildCacheDiskUsage {
func buildCacheDiskUsageFromLegacyAPI(du *legacyDiskUsage) BuildCacheDiskUsage {
bdu := BuildCacheDiskUsage{
TotalCount: int64(len(du.BuildCache)),
Items: du.BuildCache,
@@ -294,7 +307,7 @@ func buildCacheDiskUsageFromLegacyAPI(du *system.DiskUsage) BuildCacheDiskUsage
return bdu
}
func volumeDiskUsageFromLegacyAPI(du *system.DiskUsage) VolumesDiskUsage {
func volumeDiskUsageFromLegacyAPI(du *legacyDiskUsage) VolumesDiskUsage {
vdu := VolumesDiskUsage{
TotalCount: int64(len(du.Volumes)),
Items: du.Volumes,

View File

@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"net/url"
"slices"
"github.com/moby/moby/api/types/volume"
)
@@ -40,16 +39,8 @@ func (cli *Client) VolumeList(ctx context.Context, options VolumeListOptions) (V
return VolumeListResult{}, err
}
res := VolumeListResult{
Items: make([]volume.Volume, 0, len(apiResp.Volumes)),
Warnings: slices.Clone(apiResp.Warnings),
}
for _, vol := range apiResp.Volumes {
if vol != nil {
res.Items = append(res.Items, *vol)
}
}
return res, nil
return VolumeListResult{
Items: apiResp.Volumes,
Warnings: apiResp.Warnings,
}, nil
}

4
vendor/modules.txt vendored
View File

@@ -167,7 +167,7 @@ github.com/moby/docker-image-spec/specs-go/v1
github.com/moby/go-archive
github.com/moby/go-archive/compression
github.com/moby/go-archive/tarheader
# github.com/moby/moby/api v1.52.0-rc.1
# github.com/moby/moby/api v1.52.0-rc.1.0.20251110152122-7cff366d4383
## explicit; go 1.23.0
github.com/moby/moby/api/pkg/authconfig
github.com/moby/moby/api/pkg/stdcopy
@@ -189,7 +189,7 @@ github.com/moby/moby/api/types/storage
github.com/moby/moby/api/types/swarm
github.com/moby/moby/api/types/system
github.com/moby/moby/api/types/volume
# github.com/moby/moby/client v0.1.0-rc.1
# github.com/moby/moby/client v0.1.0-rc.1.0.20251110152122-7cff366d4383
## explicit; go 1.23.0
github.com/moby/moby/client
github.com/moby/moby/client/internal