Skip to content

Commit f9e5429

Browse files
committed
libn/d/win/overlay: dedupe NetworkDB definitions
Windows and Linux overlay driver instances are interoperable, working from the same NetworkDB table for peer discovery. As both drivers produce and consume serialized data through the table, they both need to have a shared understanding of the shape and semantics of that data. The Windows overlay driver contains a duplicate copy of the protobuf definitions used for marshaling and unmarshaling the NetworkDB peer entries for dubious reasons. It gives us the flexibility to have the definitions diverge, which is only really useful for shooting ourselves in the foot. Make libnetwork/drivers/overlay the source of truth for the peer record definitions and the name of the NetworkDB table for distributing peer records. Signed-off-by: Cory Snider <[email protected]> (cherry picked from commit 8340e10) Signed-off-by: Cory Snider <[email protected]>
1 parent fc3df55 commit f9e5429

10 files changed

Lines changed: 15 additions & 497 deletions

File tree

libnetwork/drivers/overlay/joinleave.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
127127
return err
128128
}
129129

130-
if err := jinfo.AddTableEntry(ovPeerTable, eid, buf); err != nil {
130+
if err := jinfo.AddTableEntry(OverlayPeerTable, eid, buf); err != nil {
131131
log.G(context.TODO()).Errorf("overlay: Failed adding table entry to joininfo: %v", err)
132132
}
133133

134134
return nil
135135
}
136136

137137
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
138-
if tablename != ovPeerTable {
138+
if tablename != OverlayPeerTable {
139139
log.G(context.TODO()).Errorf("DecodeTableEntry: unexpected table name %s", tablename)
140140
return "", nil
141141
}
@@ -152,7 +152,7 @@ func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (s
152152
}
153153

154154
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
155-
if tableName != ovPeerTable {
155+
if tableName != OverlayPeerTable {
156156
log.G(context.TODO()).Errorf("Unexpected table notification for table %s received", tableName)
157157
return
158158
}

libnetwork/drivers/overlay/ov_network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
197197
}
198198

199199
if nInfo != nil {
200-
if err := nInfo.TableEventRegister(ovPeerTable, driverapi.EndpointObject); err != nil {
200+
if err := nInfo.TableEventRegister(OverlayPeerTable, driverapi.EndpointObject); err != nil {
201201
return err
202202
}
203203
}

libnetwork/drivers/overlay/peer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package overlay
2+
3+
// OverlayPeerTable is the NetworkDB table for overlay network peer discovery.
4+
const OverlayPeerTable = "overlay_peer_table"

libnetwork/drivers/overlay/peerdb.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"github.com/docker/docker/libnetwork/osl"
1717
)
1818

19-
const ovPeerTable = "overlay_peer_table"
20-
2119
type peerEntry struct {
2220
eid string
2321
mac hashable.MACAddr

libnetwork/drivers/windows/overlay/joinleave_windows.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/containerd/log"
99
"github.com/docker/docker/libnetwork/driverapi"
10+
"github.com/docker/docker/libnetwork/drivers/overlay"
1011
"github.com/docker/docker/libnetwork/types"
1112
"github.com/gogo/protobuf/proto"
1213
)
@@ -27,7 +28,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
2728
return fmt.Errorf("could not find endpoint with id %s", eid)
2829
}
2930

30-
buf, err := proto.Marshal(&PeerRecord{
31+
buf, err := proto.Marshal(&overlay.PeerRecord{
3132
EndpointIP: ep.addr.String(),
3233
EndpointMAC: ep.mac.String(),
3334
TunnelEndpointIP: n.providerAddress,
@@ -36,7 +37,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
3637
return err
3738
}
3839

39-
if err := jinfo.AddTableEntry(ovPeerTable, eid, buf); err != nil {
40+
if err := jinfo.AddTableEntry(overlay.OverlayPeerTable, eid, buf); err != nil {
4041
log.G(context.TODO()).Errorf("overlay: Failed adding table entry to joininfo: %v", err)
4142
}
4243

@@ -48,14 +49,14 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
4849
}
4950

5051
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
51-
if tableName != ovPeerTable {
52+
if tableName != overlay.OverlayPeerTable {
5253
log.G(context.TODO()).Errorf("Unexpected table notification for table %s received", tableName)
5354
return
5455
}
5556

5657
eid := key
5758

58-
var peer PeerRecord
59+
var peer overlay.PeerRecord
5960
if err := proto.Unmarshal(value, &peer); err != nil {
6061
log.G(context.TODO()).Errorf("Failed to unmarshal peer record: %v", err)
6162
return

libnetwork/drivers/windows/overlay/ov_network_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/Microsoft/hcsshim"
1313
"github.com/containerd/log"
1414
"github.com/docker/docker/libnetwork/driverapi"
15+
"github.com/docker/docker/libnetwork/drivers/overlay"
1516
"github.com/docker/docker/libnetwork/netlabel"
1617
"github.com/docker/docker/libnetwork/portmapper"
1718
"github.com/docker/docker/libnetwork/types"
@@ -173,7 +174,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
173174
n.interfaceName = interfaceName
174175

175176
if nInfo != nil {
176-
if err := nInfo.TableEventRegister(ovPeerTable, driverapi.EndpointObject); err != nil {
177+
if err := nInfo.TableEventRegister(overlay.OverlayPeerTable, driverapi.EndpointObject); err != nil {
177178
return err
178179
}
179180
}

0 commit comments

Comments
 (0)