Merge pull request #44705 from thaJeztah/inspect_literal

daemon: rename vars that collided, and use struct-literals
This commit is contained in:
Bjorn Neergaard 2022-12-29 16:08:22 -07:00 committed by GitHub
commit d8e3e6d606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 34 deletions

View file

@ -46,10 +46,10 @@ func (daemon *Daemon) ContainerInspectCurrent(name string, size bool) (*types.Co
}
apiNetworks := make(map[string]*networktypes.EndpointSettings)
for name, epConf := range ctr.NetworkSettings.Networks {
for nwName, epConf := range ctr.NetworkSettings.Networks {
if epConf.EndpointSettings != nil {
// We must make a copy of this pointer object otherwise it can race with other operations
apiNetworks[name] = epConf.EndpointSettings.Copy()
apiNetworks[nwName] = epConf.EndpointSettings.Copy()
}
}
@ -93,34 +93,30 @@ func (daemon *Daemon) ContainerInspectCurrent(name string, size bool) (*types.Co
// containerInspect120 serializes the master version of a container into a json type.
func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, error) {
container, err := daemon.GetContainer(name)
ctr, err := daemon.GetContainer(name)
if err != nil {
return nil, err
}
container.Lock()
defer container.Unlock()
ctr.Lock()
defer ctr.Unlock()
base, err := daemon.getInspectData(container)
base, err := daemon.getInspectData(ctr)
if err != nil {
return nil, err
}
mountPoints := container.GetMountPoints()
config := &v1p20.ContainerConfig{
Config: container.Config,
MacAddress: container.Config.MacAddress,
NetworkDisabled: container.Config.NetworkDisabled,
ExposedPorts: container.Config.ExposedPorts,
VolumeDriver: container.HostConfig.VolumeDriver,
}
networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
return &v1p20.ContainerJSON{
ContainerJSONBase: base,
Mounts: mountPoints,
Config: config,
NetworkSettings: networkSettings,
Mounts: ctr.GetMountPoints(),
Config: &v1p20.ContainerConfig{
Config: ctr.Config,
MacAddress: ctr.Config.MacAddress,
NetworkDisabled: ctr.Config.NetworkDisabled,
ExposedPorts: ctr.Config.ExposedPorts,
VolumeDriver: ctr.HostConfig.VolumeDriver,
},
NetworkSettings: daemon.getBackwardsCompatibleNetworkSettings(ctr.NetworkSettings),
}, nil
}

View file

@ -39,25 +39,22 @@ func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON,
volumesRW[m.Destination] = m.RW
}
config := &v1p19.ContainerConfig{
Config: ctr.Config,
MacAddress: ctr.Config.MacAddress,
NetworkDisabled: ctr.Config.NetworkDisabled,
ExposedPorts: ctr.Config.ExposedPorts,
VolumeDriver: ctr.HostConfig.VolumeDriver,
Memory: ctr.HostConfig.Memory,
MemorySwap: ctr.HostConfig.MemorySwap,
CPUShares: ctr.HostConfig.CPUShares,
CPUSet: ctr.HostConfig.CpusetCpus,
}
networkSettings := daemon.getBackwardsCompatibleNetworkSettings(ctr.NetworkSettings)
return &v1p19.ContainerJSON{
ContainerJSONBase: base,
Volumes: volumes,
VolumesRW: volumesRW,
Config: config,
NetworkSettings: networkSettings,
Config: &v1p19.ContainerConfig{
Config: ctr.Config,
MacAddress: ctr.Config.MacAddress,
NetworkDisabled: ctr.Config.NetworkDisabled,
ExposedPorts: ctr.Config.ExposedPorts,
VolumeDriver: ctr.HostConfig.VolumeDriver,
Memory: ctr.HostConfig.Memory,
MemorySwap: ctr.HostConfig.MemorySwap,
CPUShares: ctr.HostConfig.CPUShares,
CPUSet: ctr.HostConfig.CpusetCpus,
},
NetworkSettings: daemon.getBackwardsCompatibleNetworkSettings(ctr.NetworkSettings),
}, nil
}