1
0
Fork 0
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:
Vincent Demeester 2017-02-28 11:11:59 +01:00
parent af0d9bdfe4
commit cb6832c6d3
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3

View file

@ -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)
} }