mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Extract common code from disconnectFromNetwork and releaseNetwork
Both method are trying to detach the container from a cluster network. The code is exactly the same, this removes the duplication. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
af0d9bdfe4
commit
cb6832c6d3
1 changed files with 16 additions and 20 deletions
|
@ -829,18 +829,26 @@ func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n li
|
||||||
|
|
||||||
delete(container.NetworkSettings.Networks, n.Name())
|
delete(container.NetworkSettings.Networks, n.Name())
|
||||||
|
|
||||||
if daemon.clusterProvider != nil && n.Info().Dynamic() && !container.Managed {
|
daemon.tryDetachContainerFromClusterNetwork(n, container)
|
||||||
if err := daemon.clusterProvider.DetachNetwork(n.Name(), container.ID); err != nil {
|
|
||||||
logrus.Warnf("error detaching from network %s: %v", n.Name(), err)
|
|
||||||
if err := daemon.clusterProvider.DetachNetwork(n.ID(), container.ID); err != nil {
|
|
||||||
logrus.Warnf("error detaching from network %s: %v", n.ID(), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) tryDetachContainerFromClusterNetwork(network libnetwork.Network, container *container.Container) {
|
||||||
|
if daemon.clusterProvider != nil && network.Info().Dynamic() && !container.Managed {
|
||||||
|
if err := daemon.clusterProvider.DetachNetwork(network.Name(), container.ID); err != nil {
|
||||||
|
logrus.Warnf("error detaching from network %s: %v", network.Name(), err)
|
||||||
|
if err := daemon.clusterProvider.DetachNetwork(network.ID(), container.ID); err != nil {
|
||||||
|
logrus.Warnf("error detaching from network %s: %v", network.ID(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attributes := map[string]string{
|
||||||
|
"container": container.ID,
|
||||||
|
}
|
||||||
|
daemon.LogNetworkEventWithAttributes(network, "disconnect", attributes)
|
||||||
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) initializeNetworking(container *container.Container) error {
|
func (daemon *Daemon) initializeNetworking(container *container.Container) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -931,19 +939,7 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, nw := range networks {
|
for _, nw := range networks {
|
||||||
if daemon.clusterProvider != nil && nw.Info().Dynamic() && !container.Managed {
|
daemon.tryDetachContainerFromClusterNetwork(nw, container)
|
||||||
if err := daemon.clusterProvider.DetachNetwork(nw.Name(), container.ID); err != nil {
|
|
||||||
logrus.Warnf("error detaching from network %s: %v", nw.Name(), err)
|
|
||||||
if err := daemon.clusterProvider.DetachNetwork(nw.ID(), container.ID); err != nil {
|
|
||||||
logrus.Warnf("error detaching from network %s: %v", nw.ID(), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
attributes := map[string]string{
|
|
||||||
"container": container.ID,
|
|
||||||
}
|
|
||||||
daemon.LogNetworkEventWithAttributes(nw, "disconnect", attributes)
|
|
||||||
}
|
}
|
||||||
networkActions.WithValues("release").UpdateSince(start)
|
networkActions.WithValues("release").UpdateSince(start)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue