Merge pull request #26805 from miaoyq/refactor-allocateNetwork
Replace two array with a map type, make it easier to understand.
This commit is contained in:
commit
8643903e49
1 changed files with 5 additions and 8 deletions
|
@ -502,23 +502,20 @@ func (daemon *Daemon) allocateNetwork(container *container.Container) error {
|
|||
}
|
||||
|
||||
}
|
||||
var (
|
||||
networks []string
|
||||
epConfigs []*network.EndpointSettings
|
||||
)
|
||||
|
||||
// the intermediate map is necessary because "connectToNetwork" modifies "container.NetworkSettings.Networks"
|
||||
networks := make(map[string]*network.EndpointSettings)
|
||||
for n, epConf := range container.NetworkSettings.Networks {
|
||||
if n == defaultNetName {
|
||||
continue
|
||||
}
|
||||
|
||||
networks = append(networks, n)
|
||||
epConfigs = append(epConfigs, epConf)
|
||||
networks[n] = epConf
|
||||
}
|
||||
|
||||
for i, epConf := range epConfigs {
|
||||
for netName, epConf := range networks {
|
||||
cleanOperationalData(epConf)
|
||||
if err := daemon.connectToNetwork(container, networks[i], epConf.EndpointSettings, updateSettings); err != nil {
|
||||
if err := daemon.connectToNetwork(container, netName, epConf.EndpointSettings, updateSettings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue