mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #13675 from runcom/13663-config-regression
Expose old config field for api < 1.19
This commit is contained in:
commit
af09b06dfa
3 changed files with 66 additions and 5 deletions
|
@ -1141,6 +1141,14 @@ func (s *Server) getContainersByName(version version.Version, w http.ResponseWri
|
||||||
return fmt.Errorf("Missing parameter")
|
return fmt.Errorf("Missing parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if version.LessThan("1.19") {
|
||||||
|
containerJSONRaw, err := s.daemon.ContainerInspectRaw(vars["name"])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return writeJSON(w, http.StatusOK, containerJSONRaw)
|
||||||
|
}
|
||||||
|
|
||||||
containerJSON, err := s.daemon.ContainerInspect(vars["name"])
|
containerJSON, err := s.daemon.ContainerInspect(vars["name"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -195,12 +195,11 @@ type ContainerState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET "/containers/{name:.*}/json"
|
// GET "/containers/{name:.*}/json"
|
||||||
type ContainerJSON struct {
|
type ContainerJSONBase struct {
|
||||||
Id string
|
Id string
|
||||||
Created time.Time
|
Created time.Time
|
||||||
Path string
|
Path string
|
||||||
Args []string
|
Args []string
|
||||||
Config *runconfig.Config
|
|
||||||
State *ContainerState
|
State *ContainerState
|
||||||
Image string
|
Image string
|
||||||
NetworkSettings *network.Settings
|
NetworkSettings *network.Settings
|
||||||
|
@ -220,3 +219,24 @@ type ContainerJSON struct {
|
||||||
ExecIDs []string
|
ExecIDs []string
|
||||||
HostConfig *runconfig.HostConfig
|
HostConfig *runconfig.HostConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContainerJSON struct {
|
||||||
|
*ContainerJSONBase
|
||||||
|
Config *runconfig.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// backcompatibility struct along with ContainerConfig
|
||||||
|
type ContainerJSONRaw struct {
|
||||||
|
*ContainerJSONBase
|
||||||
|
Config *ContainerConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContainerConfig struct {
|
||||||
|
*runconfig.Config
|
||||||
|
|
||||||
|
// backward compatibility, they now live in HostConfig
|
||||||
|
Memory int64
|
||||||
|
MemorySwap int64
|
||||||
|
CpuShares int64
|
||||||
|
Cpuset string
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,40 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
|
||||||
container.Lock()
|
container.Lock()
|
||||||
defer container.Unlock()
|
defer container.Unlock()
|
||||||
|
|
||||||
|
base, err := daemon.getInspectData(container)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.ContainerJSON{base, container.Config}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) ContainerInspectRaw(name string) (*types.ContainerJSONRaw, error) {
|
||||||
|
container, err := daemon.Get(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
container.Lock()
|
||||||
|
defer container.Unlock()
|
||||||
|
|
||||||
|
base, err := daemon.getInspectData(container)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
config := &types.ContainerConfig{
|
||||||
|
container.Config,
|
||||||
|
container.hostConfig.Memory,
|
||||||
|
container.hostConfig.MemorySwap,
|
||||||
|
container.hostConfig.CpuShares,
|
||||||
|
container.hostConfig.CpusetCpus,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.ContainerJSONRaw{base, config}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSONBase, error) {
|
||||||
// make a copy to play with
|
// make a copy to play with
|
||||||
hostConfig := *container.hostConfig
|
hostConfig := *container.hostConfig
|
||||||
|
|
||||||
|
@ -50,12 +84,11 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
|
||||||
volumesRW[m.Destination] = m.RW
|
volumesRW[m.Destination] = m.RW
|
||||||
}
|
}
|
||||||
|
|
||||||
contJSON := &types.ContainerJSON{
|
contJSONBase := &types.ContainerJSONBase{
|
||||||
Id: container.ID,
|
Id: container.ID,
|
||||||
Created: container.Created,
|
Created: container.Created,
|
||||||
Path: container.Path,
|
Path: container.Path,
|
||||||
Args: container.Args,
|
Args: container.Args,
|
||||||
Config: container.Config,
|
|
||||||
State: containerState,
|
State: containerState,
|
||||||
Image: container.ImageID,
|
Image: container.ImageID,
|
||||||
NetworkSettings: container.NetworkSettings,
|
NetworkSettings: container.NetworkSettings,
|
||||||
|
@ -76,7 +109,7 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
|
||||||
HostConfig: &hostConfig,
|
HostConfig: &hostConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
return contJSON, nil
|
return contJSONBase, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) {
|
func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue