Skip to content

Commit 05b0e65

Browse files
committed
api/types: move Container to api/types/container
This moves the `Container` type to the containere package, rename it to `Summary`, and deprecates the old location. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 84ffc64 commit 05b0e65

16 files changed

Lines changed: 54 additions & 55 deletions

File tree

api/server/router/container/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"io"
66

7-
"github.com/docker/docker/api/types"
87
"github.com/docker/docker/api/types/backend"
98
"github.com/docker/docker/api/types/container"
109
"github.com/docker/docker/api/types/filters"
@@ -52,7 +51,7 @@ type monitorBackend interface {
5251
ContainerLogs(ctx context.Context, name string, config *container.LogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
5352
ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
5453
ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
55-
Containers(ctx context.Context, config *container.ListOptions) ([]*types.Container, error)
54+
Containers(ctx context.Context, config *container.ListOptions) ([]*container.Summary, error)
5655
}
5756

5857
// attachBackend includes function to implement to provide container attaching functionality.

api/types/container/container.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,26 @@ type State struct {
105105
FinishedAt string
106106
Health *Health `json:",omitempty"`
107107
}
108+
109+
// Summary contains response of Engine API:
110+
// GET "/containers/json"
111+
type Summary struct {
112+
ID string `json:"Id"`
113+
Names []string
114+
Image string
115+
ImageID string
116+
Command string
117+
Created int64
118+
Ports []Port
119+
SizeRw int64 `json:",omitempty"`
120+
SizeRootFs int64 `json:",omitempty"`
121+
Labels map[string]string
122+
State string
123+
Status string
124+
HostConfig struct {
125+
NetworkMode string `json:",omitempty"`
126+
Annotations map[string]string `json:",omitempty"`
127+
}
128+
NetworkSettings *NetworkSettingsSummary
129+
Mounts []MountPoint
130+
}

api/types/types.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,6 @@ const (
1919
MediaTypeMultiplexedStream = "application/vnd.docker.multiplexed-stream"
2020
)
2121

22-
// Container contains response of Engine API:
23-
// GET "/containers/json"
24-
type Container struct {
25-
ID string `json:"Id"`
26-
Names []string
27-
Image string
28-
ImageID string
29-
Command string
30-
Created int64
31-
Ports []container.Port
32-
SizeRw int64 `json:",omitempty"`
33-
SizeRootFs int64 `json:",omitempty"`
34-
Labels map[string]string
35-
State string
36-
Status string
37-
HostConfig struct {
38-
NetworkMode string `json:",omitempty"`
39-
Annotations map[string]string `json:",omitempty"`
40-
}
41-
NetworkSettings *container.NetworkSettingsSummary
42-
Mounts []container.MountPoint
43-
}
44-
4522
// Ping contains response of Engine API:
4623
// GET "/_ping"
4724
type Ping struct {
@@ -149,7 +126,7 @@ type DiskUsageOptions struct {
149126
type DiskUsage struct {
150127
LayersSize int64
151128
Images []*image.Summary
152-
Containers []*Container
129+
Containers []*container.Summary
153130
Volumes []*volume.Volume
154131
BuildCache []*BuildCache
155132
BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.

api/types/types_deprecated.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ type ContainerNode struct {
210210
Labels map[string]string
211211
}
212212

213+
// Container contains response of Engine API:
214+
// GET "/containers/json"
215+
//
216+
// Deprecated: use [container.Summary].
217+
type Container = container.Summary
218+
213219
// ContainerState stores container's running state
214220
//
215221
// Deprecated: use [container.State].

client/container_list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import (
66
"net/url"
77
"strconv"
88

9-
"github.com/docker/docker/api/types"
109
"github.com/docker/docker/api/types/container"
1110
"github.com/docker/docker/api/types/filters"
1211
)
1312

1413
// ContainerList returns the list of containers in the docker host.
15-
func (cli *Client) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
14+
func (cli *Client) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error) {
1615
query := url.Values{}
1716

1817
if options.All {
@@ -51,7 +50,7 @@ func (cli *Client) ContainerList(ctx context.Context, options container.ListOpti
5150
return nil, err
5251
}
5352

54-
var containers []types.Container
53+
var containers []container.Summary
5554
err = json.NewDecoder(resp.body).Decode(&containers)
5655
return containers, err
5756
}

client/container_list_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/container"
1514
"github.com/docker/docker/api/types/filters"
1615
"github.com/docker/docker/errdefs"
@@ -60,7 +59,7 @@ func TestContainerList(t *testing.T) {
6059
return nil, fmt.Errorf("expected filters incoherent '%v' with actual filters %v", expectedFilters, fltrs)
6160
}
6261

63-
b, err := json.Marshal([]types.Container{
62+
b, err := json.Marshal([]container.Summary{
6463
{
6564
ID: "container_id1",
6665
},

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ContainerAPIClient interface {
5959
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
6060
ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error)
6161
ContainerKill(ctx context.Context, container, signal string) error
62-
ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
62+
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
6363
ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)
6464
ContainerPause(ctx context.Context, container string) error
6565
ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error

container/view.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/containerd/log"
16-
"github.com/docker/docker/api/types"
1716
"github.com/docker/docker/api/types/container"
1817
"github.com/docker/docker/api/types/network"
1918
"github.com/docker/docker/errdefs"
@@ -39,7 +38,7 @@ var (
3938
// Snapshot is a read only view for Containers. It holds all information necessary to serve container queries in a
4039
// versioned ACID in-memory store.
4140
type Snapshot struct {
42-
types.Container
41+
container.Summary
4342

4443
// additional info queries need to filter on
4544
// preserve nanosec resolution for queries
@@ -306,7 +305,7 @@ func (v *View) transform(ctr *Container) *Snapshot {
306305
health = ctr.Health.Status()
307306
}
308307
snapshot := &Snapshot{
309-
Container: types.Container{
308+
Summary: container.Summary{
310309
ID: ctr.ID,
311310
Names: v.getNames(ctr.ID),
312311
ImageID: ctr.ImageID.String(),
@@ -335,8 +334,8 @@ func (v *View) transform(ctr *Container) *Snapshot {
335334
}
336335

337336
if ctr.HostConfig != nil {
338-
snapshot.Container.HostConfig.NetworkMode = string(ctr.HostConfig.NetworkMode)
339-
snapshot.Container.HostConfig.Annotations = maps.Clone(ctr.HostConfig.Annotations)
337+
snapshot.Summary.HostConfig.NetworkMode = string(ctr.HostConfig.NetworkMode)
338+
snapshot.Summary.HostConfig.Annotations = maps.Clone(ctr.HostConfig.Annotations)
340339
snapshot.HostConfig.Isolation = string(ctr.HostConfig.Isolation)
341340
for binding := range ctr.HostConfig.PortBindings {
342341
snapshot.PortBindings[binding] = struct{}{}

daemon/cluster/executor/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Backend interface {
5353
SetContainerSecretReferences(name string, refs []*swarm.SecretReference) error
5454
SetContainerConfigReferences(name string, refs []*swarm.ConfigReference) error
5555
SystemInfo(context.Context) (*system.Info, error)
56-
Containers(ctx context.Context, config *container.ListOptions) ([]*types.Container, error)
56+
Containers(ctx context.Context, config *container.ListOptions) ([]*container.Summary, error)
5757
SetNetworkBootstrapKeys([]*networktypes.EncryptionKey) error
5858
DaemonJoinsCluster(provider cluster.Provider)
5959
DaemonLeavesCluster()

daemon/daemon.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/containerd/log"
3333
"github.com/distribution/reference"
3434
dist "github.com/docker/distribution"
35-
"github.com/docker/docker/api/types"
3635
"github.com/docker/docker/api/types/backend"
3736
containertypes "github.com/docker/docker/api/types/container"
3837
imagetypes "github.com/docker/docker/api/types/image"
@@ -136,7 +135,7 @@ type Daemon struct {
136135
seccompProfile []byte
137136
seccompProfilePath string
138137

139-
usageContainers singleflight.Group[struct{}, []*types.Container]
138+
usageContainers singleflight.Group[struct{}, []*containertypes.Summary]
140139
usageImages singleflight.Group[struct{}, []*imagetypes.Summary]
141140
usageVolumes singleflight.Group[struct{}, []*volume.Volume]
142141
usageLayer singleflight.Group[struct{}, int64]

0 commit comments

Comments
 (0)