daemon: Daemon.initializeNetworking: remove var declaration
The function was declaring an err variable which was shadowed. It was intended for directly assigning to a struct field, but as this function is directly mutating an existing object, and the err variable was declared far away from its use, let's use an intermediate var for that to make it slightly more atomic. While at it, also combined two "if" branches. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
12d8029d56
commit
a018bb1da7
1 changed files with 5 additions and 8 deletions
|
@ -948,8 +948,6 @@ func (daemon *Daemon) tryDetachContainerFromClusterNetwork(network *libnetwork.N
|
|||
}
|
||||
|
||||
func (daemon *Daemon) initializeNetworking(cfg *config.Config, container *container.Container) error {
|
||||
var err error
|
||||
|
||||
if container.HostConfig.NetworkMode.IsContainer() {
|
||||
// we need to get the hosts files from the container to join
|
||||
nc, err := daemon.getNetworkedContainer(container.ID, container.HostConfig.NetworkMode.ConnectedContainer())
|
||||
|
@ -967,13 +965,12 @@ func (daemon *Daemon) initializeNetworking(cfg *config.Config, container *contai
|
|||
return nil
|
||||
}
|
||||
|
||||
if container.HostConfig.NetworkMode.IsHost() {
|
||||
if container.Config.Hostname == "" {
|
||||
container.Config.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if container.HostConfig.NetworkMode.IsHost() && container.Config.Hostname == "" {
|
||||
hn, err := os.Hostname()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
container.Config.Hostname = hn
|
||||
}
|
||||
|
||||
if err := daemon.allocateNetwork(cfg, container); err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue