Browse code

libnet/d/bridge: dead code: no conflict on stale default nw

A check was added to the bridge driver to detect when it was called to
create the default bridge nw whereas a stale default bridge already
existed. In such case, the bridge driver was deleting the stale network
before re-creating it. This check was introduced in docker/libnetwork@6b158eac6a4877c27828f524ad1ca0ea4bd2a789
to fix an issue related to newly introduced live-restore.

However, since commit docker/docker@ecffb6d58cf89371e3f4a20f55c2e614dbdfe880,
the daemon doesn't even try to create default networks if there're
active sandboxes (ie. due to live-restore).

Thus, now it's impossible for the default bridge network to be stale and
to exists when the driver's CreateNetwork() method is called. As such,
the check introduced in the first commit mentioned above is dead code
and can be safely removed.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>

Albin Kerouanton authored on 2024/01/04 19:25:37
Showing 1 changed files
... ...
@@ -42,14 +42,6 @@ const (
42 42
 	DefaultGatewayV6AuxKey = "DefaultGatewayIPv6"
43 43
 )
44 44
 
45
-type defaultBridgeNetworkConflict struct {
46
-	ID string
47
-}
48
-
49
-func (d defaultBridgeNetworkConflict) Error() string {
50
-	return fmt.Sprintf("Stale default bridge network %s", d.ID)
51
-}
52
-
53 45
 type (
54 46
 	iptableCleanFunc   func() error
55 47
 	iptablesCleanFuncs []iptableCleanFunc
... ...
@@ -674,15 +666,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
674 674
 
675 675
 	// check network conflicts
676 676
 	if err = d.checkConflict(config); err != nil {
677
-		nerr, ok := err.(defaultBridgeNetworkConflict)
678
-		if !ok {
679
-			return err
680
-		}
681
-		// Got a conflict with a stale default network, clean that up and continue
682
-		log.G(context.TODO()).Warn(nerr)
683
-		if err := d.deleteNetwork(nerr.ID); err != nil {
684
-			log.G(context.TODO()).WithError(err).Debug("Error while cleaning up network on conflict")
685
-		}
677
+		return err
686 678
 	}
687 679
 
688 680
 	// there is no conflict, now create the network
... ...
@@ -700,15 +684,6 @@ func (d *driver) checkConflict(config *networkConfiguration) error {
700 700
 		nwConfig := nw.config
701 701
 		nw.Unlock()
702 702
 		if err := nwConfig.Conflicts(config); err != nil {
703
-			if nwConfig.DefaultBridge {
704
-				// We encountered and identified a stale default network
705
-				// We must delete it as libnetwork is the source of truth
706
-				// The default network being created must be the only one
707
-				// This can happen only from docker 1.12 on ward
708
-				log.G(context.TODO()).Infof("Found stale default bridge network %s (%s)", nwConfig.ID, nwConfig.BridgeName)
709
-				return defaultBridgeNetworkConflict{nwConfig.ID}
710
-			}
711
-
712 703
 			return types.ForbiddenErrorf("cannot create network %s (%s): conflicts with network %s (%s): %s",
713 704
 				config.ID, config.BridgeName, nwConfig.ID, nwConfig.BridgeName, err.Error())
714 705
 		}