Pārlūkot izejas kodu

libnetwork/overlay: remove vni allocation

VNI allocations made by the overlay driver were only used by Classic
Swarm. With Swarm v2 mode, the driver ovmanager is responsible of
allocating & releasing them.

Previously, vxlanIdm was initialized when a global store was available
but since 142b522, no global store can be instantiated. As such,
releaseVxlanID actually does actually nothing and iptables rules are
never removed.

The last line of dead code detected by golangci-lint is now gone.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton 2 gadi atpakaļ
vecāks
revīzija
e3708a89cc

+ 0 - 4
libnetwork/drivers/overlay/joinleave.go

@@ -46,10 +46,6 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
 		return fmt.Errorf("could not find subnet for endpoint %s", eid)
 	}
 
-	if err := n.obtainVxlanID(s); err != nil {
-		return fmt.Errorf("couldn't get vxlan id for %q: %v", s.subnetIP.String(), err)
-	}
-
 	if err := n.joinSandbox(s, false, true); err != nil {
 		return fmt.Errorf("network sandbox join failed: %v", err)
 	}

+ 33 - 74
libnetwork/drivers/overlay/ov_network.go

@@ -5,6 +5,7 @@ package overlay
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"net"
 	"os"
@@ -111,37 +112,43 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
 	}
 
 	vnis := make([]uint32, 0, len(ipV4Data))
-	if gval, ok := option[netlabel.GenericData]; ok {
-		optMap := gval.(map[string]string)
-		if val, ok := optMap[netlabel.OverlayVxlanIDList]; ok {
-			logrus.Debugf("overlay: Received vxlan IDs: %s", val)
-			vniStrings := strings.Split(val, ",")
-			for _, vniStr := range vniStrings {
-				vni, err := strconv.Atoi(vniStr)
-				if err != nil {
-					return fmt.Errorf("invalid vxlan id value %q passed", vniStr)
-				}
+	gval, ok := option[netlabel.GenericData]
+	if !ok {
+		return fmt.Errorf("option %s is missing", netlabel.GenericData)
+	}
 
-				vnis = append(vnis, uint32(vni))
-			}
+	optMap := gval.(map[string]string)
+	vnisOpt, ok := optMap[netlabel.OverlayVxlanIDList]
+	if !ok {
+		return errors.New("no VNI provided")
+	}
+	logrus.Debugf("overlay: Received vxlan IDs: %s", vnisOpt)
+	vniStrings := strings.Split(vnisOpt, ",")
+	for _, vniStr := range vniStrings {
+		vni, err := strconv.Atoi(vniStr)
+		if err != nil {
+			return fmt.Errorf("invalid vxlan id value %q passed", vniStr)
 		}
-		if _, ok := optMap[secureOption]; ok {
-			n.secure = true
+
+		vnis = append(vnis, uint32(vni))
+	}
+
+	if _, ok := optMap[secureOption]; ok {
+		n.secure = true
+	}
+	if val, ok := optMap[netlabel.DriverMTU]; ok {
+		var err error
+		if n.mtu, err = strconv.Atoi(val); err != nil {
+			return fmt.Errorf("failed to parse %v: %v", val, err)
 		}
-		if val, ok := optMap[netlabel.DriverMTU]; ok {
-			var err error
-			if n.mtu, err = strconv.Atoi(val); err != nil {
-				return fmt.Errorf("failed to parse %v: %v", val, err)
-			}
-			if n.mtu < 0 {
-				return fmt.Errorf("invalid MTU value: %v", n.mtu)
-			}
+		if n.mtu < 0 {
+			return fmt.Errorf("invalid MTU value: %v", n.mtu)
 		}
 	}
 
-	// If we are getting vnis from libnetwork, either we get for
-	// all subnets or none.
-	if len(vnis) != 0 && len(vnis) < len(ipV4Data) {
+	if len(vnis) == 0 {
+		return errors.New("no VNI provided")
+	} else if len(vnis) < len(ipV4Data) {
 		return fmt.Errorf("insufficient vnis(%d) passed to overlay", len(vnis))
 	}
 
@@ -149,10 +156,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
 		s := &subnet{
 			subnetIP: ipd.Pool,
 			gwIP:     ipd.Gateway,
-		}
-
-		if len(vnis) != 0 {
-			s.vni = vnis[i]
+			vni:      vnis[i],
 		}
 
 		n.subnets = append(n.subnets, s)
@@ -229,18 +233,6 @@ func (d *driver) DeleteNetwork(nid string) error {
 	doPeerFlush = true
 	delete(d.networks, nid)
 
-	vnis, err := n.releaseVxlanID()
-	if err != nil {
-		return err
-	}
-
-	if n.secure {
-		for _, vni := range vnis {
-			programMangle(vni, false)
-			programInput(vni, false)
-		}
-	}
-
 	return nil
 }
 
@@ -874,39 +866,6 @@ func (n *network) DataScope() string {
 	return datastore.GlobalScope
 }
 
-func (n *network) releaseVxlanID() ([]uint32, error) {
-	n.Lock()
-	nSubnets := len(n.subnets)
-	n.Unlock()
-	if nSubnets == 0 {
-		return nil, nil
-	}
-
-	var vnis []uint32
-	n.Lock()
-	for _, s := range n.subnets {
-		if n.driver.vxlanIdm != nil {
-			vnis = append(vnis, s.vni)
-		}
-		s.vni = 0
-	}
-	n.Unlock()
-
-	for _, vni := range vnis {
-		n.driver.vxlanIdm.Release(uint64(vni))
-	}
-
-	return vnis, nil
-}
-
-func (n *network) obtainVxlanID(s *subnet) error {
-	// return if the subnet already has a vxlan id assigned
-	if n.vxlanID(s) != 0 {
-		return nil
-	}
-	return fmt.Errorf("no valid vxlan id and no datastore configured, cannot obtain vxlan id")
-}
-
 // getSubnetforIP returns the subnet to which the given IP belongs
 func (n *network) getSubnetforIP(ip *net.IPNet) *subnet {
 	for _, s := range n.subnets {

+ 0 - 4
libnetwork/drivers/overlay/overlay.go

@@ -13,7 +13,6 @@ import (
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/discoverapi"
 	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/idm"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/osl"
 	"github.com/docker/docker/libnetwork/types"
@@ -28,8 +27,6 @@ const (
 	secureOption = "encrypted"
 )
 
-var initVxlanIdm = make(chan (bool), 1)
-
 type driver struct {
 	bindAddress      string
 	advertiseAddress string
@@ -38,7 +35,6 @@ type driver struct {
 	secMap           *encrMap
 	networks         networkTable
 	localStore       datastore.DataStore
-	vxlanIdm         *idm.Idm
 	initOS           sync.Once
 	localJoinOnce    sync.Once
 	keys             []*key

+ 0 - 4
libnetwork/drivers/overlay/peerdb.go

@@ -315,10 +315,6 @@ func (d *driver) peerAddOp(nid, eid string, peerIP net.IP, peerIPMask net.IPMask
 		return fmt.Errorf("couldn't find the subnet %q in network %q", IP.String(), n.id)
 	}
 
-	if err := n.obtainVxlanID(s); err != nil {
-		return fmt.Errorf("couldn't get vxlan id for %q: %v", s.subnetIP.String(), err)
-	}
-
 	if err := n.joinSandbox(s, false, false); err != nil {
 		return fmt.Errorf("subnet sandbox join failed for %q: %v", s.subnetIP.String(), err)
 	}