api/types/container: merge InspectResponse and ContainerJSONBase

Merge the two types instead of embedding the ContainerJSONBase.
This should have no impact on the API response, but users constructing
a response through struct literals will need to update their code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-26 14:04:26 +02:00
parent 835afb123a
commit fae54e03af
6 changed files with 19 additions and 48 deletions

View File

@@ -119,16 +119,9 @@ type Summary struct {
Mounts []MountPoint Mounts []MountPoint
} }
// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json" // InspectResponse is the response for the GET "/containers/{name:.*}/json"
// for API version 1.18 and older. // endpoint.
// type InspectResponse struct {
// TODO(thaJeztah): combine ContainerJSONBase and InspectResponse into a single struct.
// The split between ContainerJSONBase (ContainerJSONBase) and InspectResponse (InspectResponse)
// was done in commit 6deaa58ba5f051039643cedceee97c8695e2af74 (https://github.com/moby/moby/pull/13675).
// ContainerJSONBase contained all fields for API < 1.19, and InspectResponse
// held fields that were added in API 1.19 and up. Given that the minimum
// supported API version is now 1.24, we no longer use the separate type.
type ContainerJSONBase struct {
ID string `json:"Id"` ID string `json:"Id"`
Created string Created string
Path string Path string
@@ -151,12 +144,6 @@ type ContainerJSONBase struct {
GraphDriver storage.DriverData GraphDriver storage.DriverData
SizeRw *int64 `json:",omitempty"` SizeRw *int64 `json:",omitempty"`
SizeRootFs *int64 `json:",omitempty"` SizeRootFs *int64 `json:",omitempty"`
}
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
// endpoint.
type InspectResponse struct {
*ContainerJSONBase
Mounts []MountPoint Mounts []MountPoint
Config *Config Config *Config
NetworkSettings *NetworkSettings NetworkSettings *NetworkSettings

View File

@@ -75,11 +75,9 @@ func TestContainerInspect(t *testing.T) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
} }
content, err := json.Marshal(container.InspectResponse{ content, err := json.Marshal(container.InspectResponse{
ContainerJSONBase: &container.ContainerJSONBase{ ID: "container_id",
ID: "container_id", Image: "image",
Image: "image", Name: "name",
Name: "name",
},
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -86,16 +86,15 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, options
imageManifest.Platform = &ctr.ImagePlatform imageManifest.Platform = &ctr.ImagePlatform
} }
return &containertypes.InspectResponse{ base.Mounts = mountPoints
ContainerJSONBase: base, base.Config = ctr.Config
Mounts: mountPoints, base.NetworkSettings = networkSettings
Config: ctr.Config, base.ImageManifestDescriptor = imageManifest
NetworkSettings: networkSettings,
ImageManifestDescriptor: imageManifest, return base, nil
}, nil
} }
func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Container) (*containertypes.ContainerJSONBase, error) { func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Container) (*containertypes.InspectResponse, error) {
// make a copy to play with // make a copy to play with
hostConfig := *ctr.HostConfig hostConfig := *ctr.HostConfig
@@ -130,7 +129,7 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
} }
} }
inspectResponse := &containertypes.ContainerJSONBase{ inspectResponse := &containertypes.InspectResponse{
ID: ctr.ID, ID: ctr.ID,
Created: ctr.Created.Format(time.RFC3339Nano), Created: ctr.Created.Format(time.RFC3339Nano),
Path: ctr.Path, Path: ctr.Path,

View File

@@ -6,7 +6,7 @@ import (
) )
// This sets platform-specific fields // This sets platform-specific fields
func setPlatformSpecificContainerFields(ctr *containerpkg.Container, resp *container.ContainerJSONBase) *container.ContainerJSONBase { func setPlatformSpecificContainerFields(ctr *containerpkg.Container, resp *container.InspectResponse) *container.InspectResponse {
resp.AppArmorProfile = ctr.AppArmorProfile resp.AppArmorProfile = ctr.AppArmorProfile
resp.ResolvConfPath = ctr.ResolvConfPath resp.ResolvConfPath = ctr.ResolvConfPath
resp.HostnamePath = ctr.HostnamePath resp.HostnamePath = ctr.HostnamePath

View File

@@ -6,6 +6,6 @@ import (
) )
// This sets platform-specific fields // This sets platform-specific fields
func setPlatformSpecificContainerFields(ctr *containerpkg.Container, resp *container.ContainerJSONBase) *container.ContainerJSONBase { func setPlatformSpecificContainerFields(ctr *containerpkg.Container, resp *container.InspectResponse) *container.InspectResponse {
return resp return resp
} }

View File

@@ -119,16 +119,9 @@ type Summary struct {
Mounts []MountPoint Mounts []MountPoint
} }
// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json" // InspectResponse is the response for the GET "/containers/{name:.*}/json"
// for API version 1.18 and older. // endpoint.
// type InspectResponse struct {
// TODO(thaJeztah): combine ContainerJSONBase and InspectResponse into a single struct.
// The split between ContainerJSONBase (ContainerJSONBase) and InspectResponse (InspectResponse)
// was done in commit 6deaa58ba5f051039643cedceee97c8695e2af74 (https://github.com/moby/moby/pull/13675).
// ContainerJSONBase contained all fields for API < 1.19, and InspectResponse
// held fields that were added in API 1.19 and up. Given that the minimum
// supported API version is now 1.24, we no longer use the separate type.
type ContainerJSONBase struct {
ID string `json:"Id"` ID string `json:"Id"`
Created string Created string
Path string Path string
@@ -151,12 +144,6 @@ type ContainerJSONBase struct {
GraphDriver storage.DriverData GraphDriver storage.DriverData
SizeRw *int64 `json:",omitempty"` SizeRw *int64 `json:",omitempty"`
SizeRootFs *int64 `json:",omitempty"` SizeRootFs *int64 `json:",omitempty"`
}
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
// endpoint.
type InspectResponse struct {
*ContainerJSONBase
Mounts []MountPoint Mounts []MountPoint
Config *Config Config *Config
NetworkSettings *NetworkSettings NetworkSettings *NetworkSettings