فهرست منبع

daemon: Daemon.tryDetachContainerFromClusterNetwork: cleanup

- Remove intermediate variable
- Optimize the order of checks in the condition; check for unmanaged containers
  first, before getting information about cluster state and network information.
- Simplify the log messages, as the error would already contain the same
  information about the network (name or ID) and container (ID), so would
  print the network ID twice:

    error detaching from network <ID>: could not find network attachment for container <ID> to network <name or ID>

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 سال پیش
والد
کامیت
8153a7760e
1فایلهای تغییر یافته به همراه5 افزوده شده و 6 حذف شده
  1. 5 6
      daemon/container_operations.go

+ 5 - 6
daemon/container_operations.go

@@ -933,18 +933,17 @@ func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n *l
 }
 
 func (daemon *Daemon) tryDetachContainerFromClusterNetwork(network *libnetwork.Network, container *container.Container) {
-	if daemon.clusterProvider != nil && network.Info().Dynamic() && !container.Managed {
+	if !container.Managed && daemon.clusterProvider != nil && network.Info().Dynamic() {
 		if err := daemon.clusterProvider.DetachNetwork(network.Name(), container.ID); err != nil {
-			log.G(context.TODO()).Warnf("error detaching from network %s: %v", network.Name(), err)
+			log.G(context.TODO()).WithError(err).Warn("error detaching from network")
 			if err := daemon.clusterProvider.DetachNetwork(network.ID(), container.ID); err != nil {
-				log.G(context.TODO()).Warnf("error detaching from network %s: %v", network.ID(), err)
+				log.G(context.TODO()).WithError(err).Warn("error detaching from network")
 			}
 		}
 	}
-	attributes := map[string]string{
+	daemon.LogNetworkEventWithAttributes(network, "disconnect", map[string]string{
 		"container": container.ID,
-	}
-	daemon.LogNetworkEventWithAttributes(network, "disconnect", attributes)
+	})
 }
 
 func (daemon *Daemon) initializeNetworking(cfg *config.Config, container *container.Container) error {