Browse code

Vendoring libnetwork @7b74403be424

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>

Jana Radhakrishnan authored on 2016/10/04 03:52:17
Showing 9 changed files
... ...
@@ -70,7 +70,7 @@ clone git github.com/RackSec/srslog 365bf33cd9acc21ae1c355209865f17228ca534e
70 70
 clone git github.com/imdario/mergo 0.2.1
71 71
 
72 72
 #get libnetwork packages
73
-clone git github.com/docker/libnetwork 66764992b5bff765a5aa2318ca3768ad22c4ce95
73
+clone git github.com/docker/libnetwork 7b74403be4241aea5b01b56adab5eab82a80698b
74 74
 clone git github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
75 75
 clone git github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
76 76
 clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
... ...
@@ -1,4 +1,4 @@
1
-FROM golang:1.5.4
1
+FROM golang:1.7.1
2 2
 RUN apt-get update && apt-get -y install iptables
3 3
 
4 4
 RUN go get github.com/tools/godep \
... ...
@@ -75,6 +75,9 @@ type NetworkController interface {
75 75
 	// ID provides a unique identity for the controller
76 76
 	ID() string
77 77
 
78
+	// BuiltinDrivers returns list of builtin drivers
79
+	BuiltinDrivers() []string
80
+
78 81
 	// Config method returns the bootup configuration for the controller
79 82
 	Config() config.Config
80 83
 
... ...
@@ -324,27 +327,7 @@ func (c *controller) clusterAgentInit() {
324 324
 			c.agentClose()
325 325
 			c.cleanupServiceBindings("")
326 326
 
327
-			c.Lock()
328
-			ingressSandbox := c.ingressSandbox
329
-			c.ingressSandbox = nil
330
-			c.Unlock()
331
-
332
-			if ingressSandbox != nil {
333
-				if err := ingressSandbox.Delete(); err != nil {
334
-					log.Warnf("Could not delete ingress sandbox while leaving: %v", err)
335
-				}
336
-			}
337
-
338
-			n, err := c.NetworkByName("ingress")
339
-			if err != nil {
340
-				log.Warnf("Could not find ingress network while leaving: %v", err)
341
-			}
342
-
343
-			if n != nil {
344
-				if err := n.Delete(); err != nil {
345
-					log.Warnf("Could not delete ingress network while leaving: %v", err)
346
-				}
347
-			}
327
+			c.clearIngress(true)
348 328
 
349 329
 			return
350 330
 		}
... ...
@@ -483,6 +466,17 @@ func (c *controller) ID() string {
483 483
 	return c.id
484 484
 }
485 485
 
486
+func (c *controller) BuiltinDrivers() []string {
487
+	drivers := []string{}
488
+	for _, i := range getInitializers() {
489
+		if i.ntype == "remote" {
490
+			continue
491
+		}
492
+		drivers = append(drivers, i.ntype)
493
+	}
494
+	return drivers
495
+}
496
+
486 497
 func (c *controller) validateHostDiscoveryConfig() bool {
487 498
 	if c.cfg == nil || c.cfg.Cluster.Discovery == "" || c.cfg.Cluster.Address == "" {
488 499
 		return false
... ...
@@ -1108,7 +1102,32 @@ func (c *controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capabili
1108 1108
 }
1109 1109
 
1110 1110
 func (c *controller) Stop() {
1111
+	c.clearIngress(false)
1111 1112
 	c.closeStores()
1112 1113
 	c.stopExternalKeyListener()
1113 1114
 	osl.GC()
1114 1115
 }
1116
+
1117
+func (c *controller) clearIngress(clusterLeave bool) {
1118
+	c.Lock()
1119
+	ingressSandbox := c.ingressSandbox
1120
+	c.ingressSandbox = nil
1121
+	c.Unlock()
1122
+
1123
+	if ingressSandbox != nil {
1124
+		if err := ingressSandbox.Delete(); err != nil {
1125
+			log.Warnf("Could not delete ingress sandbox while leaving: %v", err)
1126
+		}
1127
+	}
1128
+
1129
+	n, err := c.NetworkByName("ingress")
1130
+	if err != nil && clusterLeave {
1131
+		log.Warnf("Could not find ingress network while leaving: %v", err)
1132
+	}
1133
+
1134
+	if n != nil {
1135
+		if err := n.Delete(); err != nil {
1136
+			log.Warnf("Could not delete ingress network while leaving: %v", err)
1137
+		}
1138
+	}
1139
+}
... ...
@@ -44,8 +44,8 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
44 44
 	case "", modeBridge:
45 45
 		// default to macvlan bridge mode if -o macvlan_mode is empty
46 46
 		config.MacvlanMode = modeBridge
47
-	case modeOpt:
48
-		config.MacvlanMode = modeOpt
47
+	case modePrivate:
48
+		config.MacvlanMode = modePrivate
49 49
 	case modePassthru:
50 50
 		config.MacvlanMode = modePassthru
51 51
 	case modeVepa:
... ...
@@ -27,6 +27,38 @@ type GetCapabilityResponse struct {
27 27
 	Scope string
28 28
 }
29 29
 
30
+// AllocateNetworkRequest requests allocation of new network by manager
31
+type AllocateNetworkRequest struct {
32
+	// A network ID that remote plugins are expected to store for future
33
+	// reference.
34
+	NetworkID string
35
+
36
+	// A free form map->object interface for communication of options.
37
+	Options map[string]string
38
+
39
+	// IPAMData contains the address pool information for this network
40
+	IPv4Data, IPv6Data []driverapi.IPAMData
41
+}
42
+
43
+// AllocateNetworkResponse is the response to the AllocateNetworkRequest.
44
+type AllocateNetworkResponse struct {
45
+	Response
46
+	// A free form plugin specific string->string object to be sent in
47
+	// CreateNetworkRequest call in the libnetwork agents
48
+	Options map[string]string
49
+}
50
+
51
+// FreeNetworkRequest is the request to free allocated network in the manager
52
+type FreeNetworkRequest struct {
53
+	// The ID of the network to be freed.
54
+	NetworkID string
55
+}
56
+
57
+// FreeNetworkResponse is the response to a request for freeing a network.
58
+type FreeNetworkResponse struct {
59
+	Response
60
+}
61
+
30 62
 // CreateNetworkRequest requests a new network.
31 63
 type CreateNetworkRequest struct {
32 64
 	// A network ID that remote plugins are expected to store for future
... ...
@@ -88,12 +88,21 @@ func (d *driver) call(methodName string, arg interface{}, retVal maybeError) err
88 88
 	return nil
89 89
 }
90 90
 
91
-func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
92
-	return nil, types.NotImplementedErrorf("not implemented")
91
+func (d *driver) NetworkAllocate(id string, options map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
92
+	create := &api.AllocateNetworkRequest{
93
+		NetworkID: id,
94
+		Options:   options,
95
+		IPv4Data:  ipV4Data,
96
+		IPv6Data:  ipV6Data,
97
+	}
98
+	retVal := api.AllocateNetworkResponse{}
99
+	err := d.call("AllocateNetwork", create, &retVal)
100
+	return retVal.Options, err
93 101
 }
94 102
 
95 103
 func (d *driver) NetworkFree(id string) error {
96
-	return types.NotImplementedErrorf("not implemented")
104
+	fr := &api.FreeNetworkRequest{NetworkID: id}
105
+	return d.call("FreeNetwork", fr, &api.FreeNetworkResponse{})
97 106
 }
98 107
 
99 108
 func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
... ...
@@ -1059,6 +1059,12 @@ func delNameToIP(svcMap map[string][]net.IP, name string, epIP net.IP) {
1059 1059
 }
1060 1060
 
1061 1061
 func (n *network) addSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool) {
1062
+	// Do not add service names for ingress network as this is a
1063
+	// routing only network
1064
+	if n.ingress {
1065
+		return
1066
+	}
1067
+
1062 1068
 	c := n.getController()
1063 1069
 	c.Lock()
1064 1070
 	defer c.Unlock()
... ...
@@ -1086,6 +1092,12 @@ func (n *network) addSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUp
1086 1086
 }
1087 1087
 
1088 1088
 func (n *network) deleteSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool) {
1089
+	// Do not delete service names from ingress network as this is a
1090
+	// routing only network
1091
+	if n.ingress {
1092
+		return
1093
+	}
1094
+
1089 1095
 	c := n.getController()
1090 1096
 	c.Lock()
1091 1097
 	defer c.Unlock()
... ...
@@ -112,14 +112,20 @@ func (nDB *NetworkDB) clusterInit() error {
112 112
 
113 113
 	nDB.networkBroadcasts = &memberlist.TransmitLimitedQueue{
114 114
 		NumNodes: func() int {
115
-			return len(nDB.nodes)
115
+			nDB.RLock()
116
+			num := len(nDB.nodes)
117
+			nDB.RUnlock()
118
+			return num
116 119
 		},
117 120
 		RetransmitMult: config.RetransmitMult,
118 121
 	}
119 122
 
120 123
 	nDB.nodeBroadcasts = &memberlist.TransmitLimitedQueue{
121 124
 		NumNodes: func() int {
122
-			return len(nDB.nodes)
125
+			nDB.RLock()
126
+			num := len(nDB.nodes)
127
+			nDB.RUnlock()
128
+			return num
123 129
 		},
124 130
 		RetransmitMult: config.RetransmitMult,
125 131
 	}
... ...
@@ -559,10 +565,6 @@ func (nDB *NetworkDB) bulkSyncNode(networks []string, node string, unsolicited b
559 559
 		case <-t.C:
560 560
 			logrus.Errorf("Bulk sync to node %s timed out", node)
561 561
 		case <-ch:
562
-			nDB.Lock()
563
-			delete(nDB.bulkSyncAckTbl, node)
564
-			nDB.Unlock()
565
-
566 562
 			logrus.Debugf("%s: Bulk sync to node %s took %s", nDB.config.NodeName, node, time.Now().Sub(startTime))
567 563
 		}
568 564
 		t.Stop()
... ...
@@ -318,12 +318,13 @@ func (nDB *NetworkDB) handleBulkSync(buf []byte) {
318 318
 
319 319
 	// Don't respond to a bulk sync which was not unsolicited
320 320
 	if !bsm.Unsolicited {
321
-		nDB.RLock()
321
+		nDB.Lock()
322 322
 		ch, ok := nDB.bulkSyncAckTbl[bsm.NodeName]
323
-		nDB.RUnlock()
324 323
 		if ok {
325 324
 			close(ch)
325
+			delete(nDB.bulkSyncAckTbl, bsm.NodeName)
326 326
 		}
327
+		nDB.Unlock()
327 328
 
328 329
 		return
329 330
 	}