Skip to content

Commit 0fa873c

Browse files
committed
libnetwork: remove global store from overlay driver
The overlay driver was creating a global store whenever netlabel.GlobalKVClient was specified in its config argument. This specific label is not used anymore since 142b522 (moby#44875). golangci-lint now detects dead code. This will be fixed in subsequent commits. Signed-off-by: Albin Kerouanton <[email protected]>
1 parent 00037cd commit 0fa873c

3 files changed

Lines changed: 3 additions & 188 deletions

File tree

libnetwork/drivers/overlay/ov_network.go

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
166166
return fmt.Errorf("attempt to create overlay network %v that already exists", n.id)
167167
}
168168

169-
if err := n.writeToStore(); err != nil {
170-
return fmt.Errorf("failed to update data store for network %v: %v", n.id, err)
171-
}
172-
173169
// Make sure no rule is on the way from any stale secure network
174170
if !n.secure {
175171
for _, vni := range vnis {
@@ -213,10 +209,7 @@ func (d *driver) DeleteNetwork(nid string) error {
213209

214210
// This is similar to d.network(), but we need to keep holding the lock
215211
// until we are done removing this network.
216-
n, ok := d.networks[nid]
217-
if !ok {
218-
n = d.restoreNetworkFromStore(nid)
219-
}
212+
n := d.networks[nid]
220213
if n == nil {
221214
return fmt.Errorf("could not find network with id %s", nid)
222215
}
@@ -878,42 +871,14 @@ func (n *network) watchMiss(nlSock *nl.NetlinkSocket, nsPath string) {
878871
}
879872
}
880873

881-
// Restore a network from the store to the driver if it is present.
882-
// Must be called with the driver locked!
883-
func (d *driver) restoreNetworkFromStore(nid string) *network {
884-
n := d.getNetworkFromStore(nid)
885-
if n != nil {
886-
n.driver = d
887-
n.endpoints = endpointTable{}
888-
d.networks[nid] = n
889-
}
890-
return n
891-
}
892-
893874
func (d *driver) network(nid string) *network {
894875
d.Lock()
895-
n, ok := d.networks[nid]
896-
if !ok {
897-
n = d.restoreNetworkFromStore(nid)
898-
}
876+
n := d.networks[nid]
899877
d.Unlock()
900878

901879
return n
902880
}
903881

904-
func (d *driver) getNetworkFromStore(nid string) *network {
905-
if d.store == nil {
906-
return nil
907-
}
908-
909-
n := &network{id: nid}
910-
if err := d.store.GetObject(datastore.Key(n.Key()...), n); err != nil {
911-
return nil
912-
}
913-
914-
return n
915-
}
916-
917882
func (n *network) sandbox() osl.Sandbox {
918883
n.Lock()
919884
defer n.Unlock()
@@ -926,12 +891,6 @@ func (n *network) vxlanID(s *subnet) uint32 {
926891
return s.vni
927892
}
928893

929-
func (n *network) setVxlanID(s *subnet, vni uint32) {
930-
n.Lock()
931-
s.vni = vni
932-
n.Unlock()
933-
}
934-
935894
func (n *network) Key() []string {
936895
return []string{"overlay", "network", n.id}
937896
}
@@ -1047,14 +1006,6 @@ func (n *network) DataScope() string {
10471006
return datastore.GlobalScope
10481007
}
10491008

1050-
func (n *network) writeToStore() error {
1051-
if n.driver.store == nil {
1052-
return nil
1053-
}
1054-
1055-
return n.driver.store.PutObjectAtomic(n)
1056-
}
1057-
10581009
func (n *network) releaseVxlanID() ([]uint32, error) {
10591010
n.Lock()
10601011
nSubnets := len(n.subnets)
@@ -1063,17 +1014,6 @@ func (n *network) releaseVxlanID() ([]uint32, error) {
10631014
return nil, nil
10641015
}
10651016

1066-
if n.driver.store != nil {
1067-
if err := n.driver.store.DeleteObjectAtomic(n); err != nil {
1068-
if err == datastore.ErrKeyModified || err == datastore.ErrKeyNotFound {
1069-
// In both the above cases we can safely assume that the key has been removed by some other
1070-
// instance and so simply get out of here
1071-
return nil, nil
1072-
}
1073-
1074-
return nil, fmt.Errorf("failed to delete network to vxlan id map: %v", err)
1075-
}
1076-
}
10771017
var vnis []uint32
10781018
n.Lock()
10791019
for _, s := range n.subnets {
@@ -1096,35 +1036,7 @@ func (n *network) obtainVxlanID(s *subnet) error {
10961036
if n.vxlanID(s) != 0 {
10971037
return nil
10981038
}
1099-
1100-
if n.driver.store == nil {
1101-
return fmt.Errorf("no valid vxlan id and no datastore configured, cannot obtain vxlan id")
1102-
}
1103-
1104-
for {
1105-
if err := n.driver.store.GetObject(datastore.Key(n.Key()...), n); err != nil {
1106-
return fmt.Errorf("getting network %q from datastore failed %v", n.id, err)
1107-
}
1108-
1109-
if n.vxlanID(s) == 0 {
1110-
vxlanID, err := n.driver.vxlanIdm.GetID(true)
1111-
if err != nil {
1112-
return fmt.Errorf("failed to allocate vxlan id: %v", err)
1113-
}
1114-
1115-
n.setVxlanID(s, uint32(vxlanID))
1116-
if err := n.writeToStore(); err != nil {
1117-
n.driver.vxlanIdm.Release(uint64(n.vxlanID(s)))
1118-
n.setVxlanID(s, 0)
1119-
if err == datastore.ErrKeyModified {
1120-
continue
1121-
}
1122-
return fmt.Errorf("network %q failed to update data store: %v", n.id, err)
1123-
}
1124-
return nil
1125-
}
1126-
return nil
1127-
}
1039+
return fmt.Errorf("no valid vxlan id and no datastore configured, cannot obtain vxlan id")
11281040
}
11291041

11301042
// contains return true if the passed ip belongs to one the network's

libnetwork/drivers/overlay/overlay.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const (
2525
networkType = "overlay"
2626
vethPrefix = "veth"
2727
vethLen = len(vethPrefix) + 7
28-
vxlanIDStart = 256
29-
vxlanIDEnd = (1 << 24) - 1
3028
vxlanEncap = 50
3129
secureOption = "encrypted"
3230
)
@@ -45,7 +43,6 @@ type driver struct {
4543
secMap *encrMap
4644
serfInstance *serf.Serf
4745
networks networkTable
48-
store datastore.DataStore
4946
localStore datastore.DataStore
5047
vxlanIdm *idm.Idm
5148
initOS sync.Once
@@ -71,18 +68,6 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error {
7168
config: config,
7269
}
7370

74-
if data, ok := config[netlabel.GlobalKVClient]; ok {
75-
var err error
76-
dsc, ok := data.(discoverapi.DatastoreConfigData)
77-
if !ok {
78-
return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
79-
}
80-
d.store, err = datastore.NewDataStoreFromConfig(dsc)
81-
if err != nil {
82-
return types.InternalErrorf("failed to initialize data store: %v", err)
83-
}
84-
}
85-
8671
if data, ok := config[netlabel.LocalKVClient]; ok {
8772
var err error
8873
dsc, ok := data.(discoverapi.DatastoreConfigData)
@@ -171,32 +156,6 @@ func (d *driver) configure() error {
171156
// Apply OS specific kernel configs if needed
172157
d.initOS.Do(applyOStweaks)
173158

174-
if d.store == nil {
175-
return nil
176-
}
177-
178-
if d.vxlanIdm == nil {
179-
return d.initializeVxlanIdm()
180-
}
181-
182-
return nil
183-
}
184-
185-
func (d *driver) initializeVxlanIdm() error {
186-
var err error
187-
188-
initVxlanIdm <- true
189-
defer func() { <-initVxlanIdm }()
190-
191-
if d.vxlanIdm != nil {
192-
return nil
193-
}
194-
195-
d.vxlanIdm, err = idm.New(d.store, "vxlan-id", vxlanIDStart, vxlanIDEnd)
196-
if err != nil {
197-
return fmt.Errorf("failed to initialize vxlan id manager: %v", err)
198-
}
199-
200159
return nil
201160
}
202161

@@ -208,25 +167,6 @@ func (d *driver) IsBuiltIn() bool {
208167
return true
209168
}
210169

211-
func validateSelf(node string) error {
212-
advIP := net.ParseIP(node)
213-
if advIP == nil {
214-
return fmt.Errorf("invalid self address (%s)", node)
215-
}
216-
217-
addrs, err := net.InterfaceAddrs()
218-
if err != nil {
219-
return fmt.Errorf("Unable to get interface addresses %v", err)
220-
}
221-
for _, addr := range addrs {
222-
ip, _, err := net.ParseCIDR(addr.String())
223-
if err == nil && ip.Equal(advIP) {
224-
return nil
225-
}
226-
}
227-
return fmt.Errorf("Multi-Host overlay networking requires cluster-advertise(%s) to be configured with a local ip-address that is reachable within the cluster", advIP.String())
228-
}
229-
230170
func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
231171
if self && !d.isSerfAlive() {
232172
d.Lock()
@@ -239,22 +179,6 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
239179
d.localJoinOnce.Do(func() {
240180
d.peerDBUpdateSelf()
241181
})
242-
243-
// If there is no cluster store there is no need to start serf.
244-
if d.store != nil {
245-
if err := validateSelf(advertiseAddress); err != nil {
246-
logrus.Warn(err.Error())
247-
}
248-
err := d.serfInit()
249-
if err != nil {
250-
logrus.Errorf("initializing serf instance failed: %v", err)
251-
d.Lock()
252-
d.advertiseAddress = ""
253-
d.bindAddress = ""
254-
d.Unlock()
255-
return
256-
}
257-
}
258182
}
259183

260184
d.Lock()

libnetwork/drivers/overlay/overlay_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,6 @@ func TestOverlayFiniWithoutConfig(t *testing.T) {
128128
cleanupDriver(t, dt)
129129
}
130130

131-
func TestOverlayConfig(t *testing.T) {
132-
dt := setupDriver(t)
133-
134-
time.Sleep(1 * time.Second)
135-
136-
d := dt.d
137-
if d.notifyCh == nil {
138-
t.Fatal("Driver notify channel wasn't initialized after Config method")
139-
}
140-
141-
if d.exitCh == nil {
142-
t.Fatal("Driver serfloop exit channel wasn't initialized after Config method")
143-
}
144-
145-
if d.serfInstance == nil {
146-
t.Fatal("Driver serfinstance hasn't been initialized after Config method")
147-
}
148-
149-
cleanupDriver(t, dt)
150-
}
151-
152131
func TestOverlayType(t *testing.T) {
153132
dt := &driverTester{t: t}
154133
if err := Register(dt, nil); err != nil {

0 commit comments

Comments
 (0)