Skip to content

Commit 1abc8f6

Browse files
committed
api/types: move container-inspect types to api/types/container
This moves the `ContainerJSONBase`, `ContainerJSON` and `ContainerNode` types to the api/types/container package and deprecates the old location. - `ContainerJSONBase` was renamed to `InspectBase` - `ContainerJSON` was rnamed to `InspectResponse` Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 05b0e65 commit 1abc8f6

18 files changed

Lines changed: 120 additions & 97 deletions

File tree

api/types/container/container.go

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/docker/docker/api/types/mount"
9+
"github.com/docker/docker/api/types/storage"
910
)
1011

1112
// PruneReport contains the response for Engine API:
@@ -90,7 +91,7 @@ type MountPoint struct {
9091
}
9192

9293
// State stores container's running state
93-
// it's part of ContainerJSONBase and will return by "inspect" command
94+
// it's part of InspectBase and returned by "inspect" command
9495
type State struct {
9596
Status string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
9697
Running bool
@@ -128,3 +129,61 @@ type Summary struct {
128129
NetworkSettings *NetworkSettingsSummary
129130
Mounts []MountPoint
130131
}
132+
133+
// ContainerNode stores information about the node that a container
134+
// is running on. It's only used by the Docker Swarm standalone API.
135+
//
136+
// Deprecated: ContainerNode was used for the classic Docker Swarm standalone API. It will be removed in the next release.
137+
type ContainerNode struct {
138+
ID string
139+
IPAddress string `json:"IP"`
140+
Addr string
141+
Name string
142+
Cpus int
143+
Memory int64
144+
Labels map[string]string
145+
}
146+
147+
// InspectBase contains response of Engine API GET "/containers/{name:.*}/json"
148+
// for API version 1.18 and older.
149+
//
150+
// TODO(thaJeztah): combine InspectBase and InspectResponse into a single struct.
151+
// The split between InspectBase (ContainerJSONBase) and InspectResponse (InspectResponse)
152+
// was done in commit 6deaa58ba5f051039643cedceee97c8695e2af74 (https://github.com/moby/moby/pull/13675).
153+
// ContainerJSONBase contained all fields for API < 1.19, and InspectResponse
154+
// held fields that were added in API 1.19 and up. Given that the minimum
155+
// supported API version is now 1.24, we no longer use the separate type.
156+
type InspectBase struct {
157+
ID string `json:"Id"`
158+
Created string
159+
Path string
160+
Args []string
161+
State *State
162+
Image string
163+
ResolvConfPath string
164+
HostnamePath string
165+
HostsPath string
166+
LogPath string
167+
Node *ContainerNode `json:",omitempty"` // Deprecated: Node was only propagated by Docker Swarm standalone API. It sill be removed in the next release.
168+
Name string
169+
RestartCount int
170+
Driver string
171+
Platform string
172+
MountLabel string
173+
ProcessLabel string
174+
AppArmorProfile string
175+
ExecIDs []string
176+
HostConfig *HostConfig
177+
GraphDriver storage.DriverData
178+
SizeRw *int64 `json:",omitempty"`
179+
SizeRootFs *int64 `json:",omitempty"`
180+
}
181+
182+
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
183+
// endpoint.
184+
type InspectResponse struct {
185+
*InspectBase
186+
Mounts []MountPoint
187+
Config *Config
188+
NetworkSettings *NetworkSettings
189+
}

api/types/types.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/docker/docker/api/types/container"
77
"github.com/docker/docker/api/types/filters"
88
"github.com/docker/docker/api/types/image"
9-
"github.com/docker/docker/api/types/storage"
109
"github.com/docker/docker/api/types/swarm"
1110
"github.com/docker/docker/api/types/volume"
1211
)
@@ -64,42 +63,6 @@ type Version struct {
6463
BuildTime string `json:",omitempty"`
6564
}
6665

67-
// ContainerJSONBase contains response of Engine API:
68-
// GET "/containers/{name:.*}/json"
69-
type ContainerJSONBase struct {
70-
ID string `json:"Id"`
71-
Created string
72-
Path string
73-
Args []string
74-
State *container.State
75-
Image string
76-
ResolvConfPath string
77-
HostnamePath string
78-
HostsPath string
79-
LogPath string
80-
Node *ContainerNode `json:",omitempty"` // Deprecated: Node was only propagated by Docker Swarm standalone API. It sill be removed in the next release.
81-
Name string
82-
RestartCount int
83-
Driver string
84-
Platform string
85-
MountLabel string
86-
ProcessLabel string
87-
AppArmorProfile string
88-
ExecIDs []string
89-
HostConfig *container.HostConfig
90-
GraphDriver storage.DriverData
91-
SizeRw *int64 `json:",omitempty"`
92-
SizeRootFs *int64 `json:",omitempty"`
93-
}
94-
95-
// ContainerJSON is newly used struct along with MountPoint
96-
type ContainerJSON struct {
97-
*ContainerJSONBase
98-
Mounts []container.MountPoint
99-
Config *container.Config
100-
NetworkSettings *container.NetworkSettings
101-
}
102-
10366
// DiskUsageObject represents an object type used for disk usage query filtering.
10467
type DiskUsageObject string
10568

api/types/types_deprecated.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,23 @@ type ImageImportSource image.ImportSource
196196
// Deprecated: use [image.LoadResponse].
197197
type ImageLoadResponse = image.LoadResponse
198198

199+
// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json"
200+
// for API version 1.18 and older.
201+
//
202+
// Deprecated: use [container.InspectResponse] or [container.InspectBase]. It will be removed in the next release.
203+
type ContainerJSONBase = container.InspectBase
204+
205+
// ContainerJSON is the response for the GET "/containers/{name:.*}/json"
206+
// endpoint.
207+
//
208+
// Deprecated: use [container.InspectResponse]. It will be removed in the next release.
209+
type ContainerJSON = container.InspectResponse
210+
199211
// ContainerNode stores information about the node that a container
200212
// is running on. It's only used by the Docker Swarm standalone API.
201213
//
202214
// Deprecated: ContainerNode was used for the classic Docker Swarm standalone API. It will be removed in the next release.
203-
type ContainerNode struct {
204-
ID string
205-
IPAddress string `json:"IP"`
206-
Addr string
207-
Name string
208-
Cpus int
209-
Memory int64
210-
Labels map[string]string
211-
}
215+
type ContainerNode = container.ContainerNode //nolint:staticcheck // Ignore SA1019: container.ContainerNode is deprecated.
212216

213217
// Container contains response of Engine API:
214218
// GET "/containers/json"

client/container_inspect.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ import (
77
"io"
88
"net/url"
99

10-
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/container"
1111
)
1212

1313
// ContainerInspect returns the container information.
14-
func (cli *Client) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) {
14+
func (cli *Client) ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error) {
1515
if containerID == "" {
16-
return types.ContainerJSON{}, objectNotFoundError{object: "container", id: containerID}
16+
return container.InspectResponse{}, objectNotFoundError{object: "container", id: containerID}
1717
}
1818
serverResp, err := cli.get(ctx, "/containers/"+containerID+"/json", nil, nil)
1919
defer ensureReaderClosed(serverResp)
2020
if err != nil {
21-
return types.ContainerJSON{}, err
21+
return container.InspectResponse{}, err
2222
}
2323

24-
var response types.ContainerJSON
24+
var response container.InspectResponse
2525
err = json.NewDecoder(serverResp.body).Decode(&response)
2626
return response, err
2727
}
2828

2929
// ContainerInspectWithRaw returns the container information and its raw representation.
30-
func (cli *Client) ContainerInspectWithRaw(ctx context.Context, containerID string, getSize bool) (types.ContainerJSON, []byte, error) {
30+
func (cli *Client) ContainerInspectWithRaw(ctx context.Context, containerID string, getSize bool) (container.InspectResponse, []byte, error) {
3131
if containerID == "" {
32-
return types.ContainerJSON{}, nil, objectNotFoundError{object: "container", id: containerID}
32+
return container.InspectResponse{}, nil, objectNotFoundError{object: "container", id: containerID}
3333
}
3434
query := url.Values{}
3535
if getSize {
@@ -38,15 +38,15 @@ func (cli *Client) ContainerInspectWithRaw(ctx context.Context, containerID stri
3838
serverResp, err := cli.get(ctx, "/containers/"+containerID+"/json", query, nil)
3939
defer ensureReaderClosed(serverResp)
4040
if err != nil {
41-
return types.ContainerJSON{}, nil, err
41+
return container.InspectResponse{}, nil, err
4242
}
4343

4444
body, err := io.ReadAll(serverResp.body)
4545
if err != nil {
46-
return types.ContainerJSON{}, nil, err
46+
return container.InspectResponse{}, nil, err
4747
}
4848

49-
var response types.ContainerJSON
49+
var response container.InspectResponse
5050
rdr := bytes.NewReader(body)
5151
err = json.NewDecoder(rdr).Decode(&response)
5252
return response, body, err

client/container_inspect_test.go

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

13-
"github.com/docker/docker/api/types"
13+
"github.com/docker/docker/api/types/container"
1414
"github.com/docker/docker/errdefs"
1515
"github.com/pkg/errors"
1616
"gotest.tools/v3/assert"
@@ -52,8 +52,8 @@ func TestContainerInspect(t *testing.T) {
5252
if !strings.HasPrefix(req.URL.Path, expectedURL) {
5353
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
5454
}
55-
content, err := json.Marshal(types.ContainerJSON{
56-
ContainerJSONBase: &types.ContainerJSONBase{
55+
content, err := json.Marshal(container.InspectResponse{
56+
InspectBase: &container.InspectBase{
5757
ID: "container_id",
5858
Image: "image",
5959
Name: "name",

client/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ type ContainerAPIClient interface {
5656
ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
5757
ContainerExecStart(ctx context.Context, execID string, options container.ExecStartOptions) error
5858
ContainerExport(ctx context.Context, container string) (io.ReadCloser, error)
59-
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
60-
ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error)
59+
ContainerInspect(ctx context.Context, container string) (container.InspectResponse, error)
60+
ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (container.InspectResponse, []byte, error)
6161
ContainerKill(ctx context.Context, container, signal string) error
6262
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
6363
ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)

daemon/cluster/executor/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/distribution/reference"
99
"github.com/docker/distribution"
10-
"github.com/docker/docker/api/types"
1110
"github.com/docker/docker/api/types/backend"
1211
"github.com/docker/docker/api/types/container"
1312
"github.com/docker/docker/api/types/events"
@@ -45,7 +44,7 @@ type Backend interface {
4544
ActivateContainerServiceBinding(containerName string) error
4645
DeactivateContainerServiceBinding(containerName string) error
4746
UpdateContainerServiceConfig(containerName string, serviceConfig *clustertypes.ServiceConfig) error
48-
ContainerInspectCurrent(ctx context.Context, name string, size bool) (*types.ContainerJSON, error)
47+
ContainerInspectCurrent(ctx context.Context, name string, size bool) (*container.InspectResponse, error)
4948
ContainerWait(ctx context.Context, name string, condition containerpkg.WaitCondition) (<-chan containerpkg.StateStatus, error)
5049
ContainerRm(name string, config *backend.ContainerRmConfig) error
5150
ContainerKill(name string, sig string) error

daemon/cluster/executor/container/adapter.go

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

1414
"github.com/containerd/log"
1515
"github.com/distribution/reference"
16-
"github.com/docker/docker/api/types"
1716
"github.com/docker/docker/api/types/backend"
1817
containertypes "github.com/docker/docker/api/types/container"
1918
"github.com/docker/docker/api/types/events"
@@ -372,13 +371,13 @@ func (c *containerAdapter) start(ctx context.Context) error {
372371
return c.backend.ContainerStart(ctx, c.container.name(), "", "")
373372
}
374373

375-
func (c *containerAdapter) inspect(ctx context.Context) (types.ContainerJSON, error) {
374+
func (c *containerAdapter) inspect(ctx context.Context) (containertypes.InspectResponse, error) {
376375
cs, err := c.backend.ContainerInspectCurrent(ctx, c.container.name(), false)
377376
if ctx.Err() != nil {
378-
return types.ContainerJSON{}, ctx.Err()
377+
return containertypes.InspectResponse{}, ctx.Err()
379378
}
380379
if err != nil {
381-
return types.ContainerJSON{}, err
380+
return containertypes.InspectResponse{}, err
382381
}
383382
return *cs, nil
384383
}

daemon/cluster/executor/container/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/docker/docker/api/types"
11+
"github.com/docker/docker/api/types/container"
1212
"github.com/docker/docker/api/types/events"
1313
executorpkg "github.com/docker/docker/daemon/cluster/executor"
1414
"github.com/docker/docker/errdefs"
@@ -610,7 +610,7 @@ func (r *controller) checkClosed() error {
610610
}
611611
}
612612

613-
func parseContainerStatus(ctnr types.ContainerJSON) (*api.ContainerStatus, error) {
613+
func parseContainerStatus(ctnr container.InspectResponse) (*api.ContainerStatus, error) {
614614
status := &api.ContainerStatus{
615615
ContainerID: ctnr.ID,
616616
PID: int32(ctnr.State.Pid),
@@ -620,7 +620,7 @@ func parseContainerStatus(ctnr types.ContainerJSON) (*api.ContainerStatus, error
620620
return status, nil
621621
}
622622

623-
func parsePortStatus(ctnr types.ContainerJSON) (*api.PortStatus, error) {
623+
func parsePortStatus(ctnr container.InspectResponse) (*api.PortStatus, error) {
624624
status := &api.PortStatus{}
625625

626626
if ctnr.NetworkSettings != nil && len(ctnr.NetworkSettings.Ports) > 0 {

daemon/inspect.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"time"
1111

12-
"github.com/docker/docker/api/types"
1312
"github.com/docker/docker/api/types/backend"
1413
containertypes "github.com/docker/docker/api/types/container"
1514
networktypes "github.com/docker/docker/api/types/network"
@@ -49,7 +48,7 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, size bo
4948

5049
// ContainerInspectCurrent returns low-level information about a
5150
// container in a most recent api version.
52-
func (daemon *Daemon) ContainerInspectCurrent(ctx context.Context, name string, size bool) (*types.ContainerJSON, error) {
51+
func (daemon *Daemon) ContainerInspectCurrent(ctx context.Context, name string, size bool) (*containertypes.InspectResponse, error) {
5352
ctr, err := daemon.GetContainer(name)
5453
if err != nil {
5554
return nil, err
@@ -104,15 +103,15 @@ func (daemon *Daemon) ContainerInspectCurrent(ctx context.Context, name string,
104103
base.SizeRootFs = &sizeRootFs
105104
}
106105

107-
return &types.ContainerJSON{
108-
ContainerJSONBase: base,
109-
Mounts: mountPoints,
110-
Config: ctr.Config,
111-
NetworkSettings: networkSettings,
106+
return &containertypes.InspectResponse{
107+
InspectBase: base,
108+
Mounts: mountPoints,
109+
Config: ctr.Config,
110+
NetworkSettings: networkSettings,
112111
}, nil
113112
}
114113

115-
func (daemon *Daemon) getInspectData(daemonCfg *config.Config, container *container.Container) (*types.ContainerJSONBase, error) {
114+
func (daemon *Daemon) getInspectData(daemonCfg *config.Config, container *container.Container) (*containertypes.InspectBase, error) {
116115
// make a copy to play with
117116
hostConfig := *container.HostConfig
118117

@@ -161,7 +160,7 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, container *contai
161160
Health: containerHealth,
162161
}
163162

164-
contJSONBase := &types.ContainerJSONBase{
163+
contJSONBase := &containertypes.InspectBase{
165164
ID: container.ID,
166165
Created: container.Created.Format(time.RFC3339Nano),
167166
Path: container.Path,

0 commit comments

Comments
 (0)