Skip to content

Commit bb54332

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 11441b1 commit bb54332

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
@@ -165,10 +165,6 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
165165
return fmt.Errorf("attempt to create overlay network %v that already exists", n.id)
166166
}
167167

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

213209
// This is similar to d.network(), but we need to keep holding the lock
214210
// until we are done removing this network.
215-
n, ok := d.networks[nid]
216-
if !ok {
217-
n = d.restoreNetworkFromStore(nid)
218-
}
211+
n := d.networks[nid]
219212
if n == nil {
220213
return fmt.Errorf("could not find network with id %s", nid)
221214
}
@@ -865,42 +858,14 @@ func (n *network) watchMiss(nlSock *nl.NetlinkSocket, nsPath string) {
865858
}
866859
}
867860

868-
// Restore a network from the store to the driver if it is present.
869-
// Must be called with the driver locked!
870-
func (d *driver) restoreNetworkFromStore(nid string) *network {
871-
n := d.getNetworkFromStore(nid)
872-
if n != nil {
873-
n.driver = d
874-
n.endpoints = endpointTable{}
875-
d.networks[nid] = n
876-
}
877-
return n
878-
}
879-
880861
func (d *driver) network(nid string) *network {
881862
d.Lock()
882-
n, ok := d.networks[nid]
883-
if !ok {
884-
n = d.restoreNetworkFromStore(nid)
885-
}
863+
n := d.networks[nid]
886864
d.Unlock()
887865

888866
return n
889867
}
890868

891-
func (d *driver) getNetworkFromStore(nid string) *network {
892-
if d.store == nil {
893-
return nil
894-
}
895-
896-
n := &network{id: nid}
897-
if err := d.store.GetObject(datastore.Key(n.Key()...), n); err != nil {
898-
return nil
899-
}
900-
901-
return n
902-
}
903-
904869
func (n *network) sandbox() osl.Sandbox {
905870
n.Lock()
906871
defer n.Unlock()
@@ -913,12 +878,6 @@ func (n *network) vxlanID(s *subnet) uint32 {
913878
return s.vni
914879
}
915880

916-
func (n *network) setVxlanID(s *subnet, vni uint32) {
917-
n.Lock()
918-
s.vni = vni
919-
n.Unlock()
920-
}
921-
922881
func (n *network) Key() []string {
923882
return []string{"overlay", "network", n.id}
924883
}
@@ -1034,14 +993,6 @@ func (n *network) DataScope() string {
1034993
return datastore.GlobalScope
1035994
}
1036995

1037-
func (n *network) writeToStore() error {
1038-
if n.driver.store == nil {
1039-
return nil
1040-
}
1041-
1042-
return n.driver.store.PutObjectAtomic(n)
1043-
}
1044-
1045996
func (n *network) releaseVxlanID() ([]uint32, error) {
1046997
n.Lock()
1047998
nSubnets := len(n.subnets)
@@ -1050,17 +1001,6 @@ func (n *network) releaseVxlanID() ([]uint32, error) {
10501001
return nil, nil
10511002
}
10521003

1053-
if n.driver.store != nil {
1054-
if err := n.driver.store.DeleteObjectAtomic(n); err != nil {
1055-
if err == datastore.ErrKeyModified || err == datastore.ErrKeyNotFound {
1056-
// In both the above cases we can safely assume that the key has been removed by some other
1057-
// instance and so simply get out of here
1058-
return nil, nil
1059-
}
1060-
1061-
return nil, fmt.Errorf("failed to delete network to vxlan id map: %v", err)
1062-
}
1063-
}
10641004
var vnis []uint32
10651005
n.Lock()
10661006
for _, s := range n.subnets {
@@ -1083,35 +1023,7 @@ func (n *network) obtainVxlanID(s *subnet) error {
10831023
if n.vxlanID(s) != 0 {
10841024
return nil
10851025
}
1086-
1087-
if n.driver.store == nil {
1088-
return fmt.Errorf("no valid vxlan id and no datastore configured, cannot obtain vxlan id")
1089-
}
1090-
1091-
for {
1092-
if err := n.driver.store.GetObject(datastore.Key(n.Key()...), n); err != nil {
1093-
return fmt.Errorf("getting network %q from datastore failed %v", n.id, err)
1094-
}
1095-
1096-
if n.vxlanID(s) == 0 {
1097-
vxlanID, err := n.driver.vxlanIdm.GetID(true)
1098-
if err != nil {
1099-
return fmt.Errorf("failed to allocate vxlan id: %v", err)
1100-
}
1101-
1102-
n.setVxlanID(s, uint32(vxlanID))
1103-
if err := n.writeToStore(); err != nil {
1104-
n.driver.vxlanIdm.Release(uint64(n.vxlanID(s)))
1105-
n.setVxlanID(s, 0)
1106-
if err == datastore.ErrKeyModified {
1107-
continue
1108-
}
1109-
return fmt.Errorf("network %q failed to update data store: %v", n.id, err)
1110-
}
1111-
return nil
1112-
}
1113-
return nil
1114-
}
1026+
return fmt.Errorf("no valid vxlan id and no datastore configured, cannot obtain vxlan id")
11151027
}
11161028

11171029
// 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)