Merge pull request #50809 from thaJeztah/container_inspect_merge

api/types/container: merge InspectResponse and ContainerJSONBase
This commit is contained in:
Paweł Gronowski
2025-08-27 12:26:19 +02:00
committed by GitHub
6 changed files with 19 additions and 48 deletions

View File

@@ -119,16 +119,9 @@ type Summary struct {
Mounts []MountPoint
}
// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json"
// for API version 1.18 and older.
//
// 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 {
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
// endpoint.
type InspectResponse struct {
ID string `json:"Id"`
Created string
Path string
@@ -151,12 +144,6 @@ type ContainerJSONBase struct {
GraphDriver storage.DriverData
SizeRw *int64 `json:",omitempty"`
SizeRootFs *int64 `json:",omitempty"`
}
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
// endpoint.
type InspectResponse struct {
*ContainerJSONBase
Mounts []MountPoint
Config *Config
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)
}
content, err := json.Marshal(container.InspectResponse{
ContainerJSONBase: &container.ContainerJSONBase{
ID: "container_id",
Image: "image",
Name: "name",
},
ID: "container_id",
Image: "image",
Name: "name",
})
if err != nil {
return nil, err

View File

@@ -86,16 +86,14 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, options
imageManifest.Platform = &ctr.ImagePlatform
}
return &containertypes.InspectResponse{
ContainerJSONBase: base,
Mounts: mountPoints,
Config: ctr.Config,
NetworkSettings: networkSettings,
ImageManifestDescriptor: imageManifest,
}, nil
base.Mounts = mountPoints
base.NetworkSettings = networkSettings
base.ImageManifestDescriptor = imageManifest
return base, 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
hostConfig := *ctr.HostConfig
@@ -130,7 +128,7 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
}
}
inspectResponse := &containertypes.ContainerJSONBase{
inspectResponse := &containertypes.InspectResponse{
ID: ctr.ID,
Created: ctr.Created.Format(time.RFC3339Nano),
Path: ctr.Path,
@@ -162,6 +160,7 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
GraphDriver: storage.DriverData{
Name: ctr.Driver,
},
Config: ctr.Config,
}
// Now set any platform-specific fields

View File

@@ -6,7 +6,7 @@ import (
)
// 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.ResolvConfPath = ctr.ResolvConfPath
resp.HostnamePath = ctr.HostnamePath

View File

@@ -6,6 +6,6 @@ import (
)
// 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
}

View File

@@ -119,16 +119,9 @@ type Summary struct {
Mounts []MountPoint
}
// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json"
// for API version 1.18 and older.
//
// 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 {
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
// endpoint.
type InspectResponse struct {
ID string `json:"Id"`
Created string
Path string
@@ -151,12 +144,6 @@ type ContainerJSONBase struct {
GraphDriver storage.DriverData
SizeRw *int64 `json:",omitempty"`
SizeRootFs *int64 `json:",omitempty"`
}
// InspectResponse is the response for the GET "/containers/{name:.*}/json"
// endpoint.
type InspectResponse struct {
*ContainerJSONBase
Mounts []MountPoint
Config *Config
NetworkSettings *NetworkSettings