Skip to content

Commit 844023f

Browse files
committed
libnetwork/driverapi: make EventNotify optional
Overlay is the only driver which makes use of the EventNotify facility, yet all other driver implementations are forced to provide a stub implementation. Move the EventNotify and DecodeTableEntry methods into a new optional TableWatcher interface and remove the stubs from all the other drivers. Signed-off-by: Cory Snider <[email protected]>
1 parent 69c3c56 commit 844023f

17 files changed

Lines changed: 34 additions & 111 deletions

File tree

daemon/libnetwork/agent.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,19 @@ func (n *Network) Services() map[string]ServiceInfo {
491491
// Walk through the driver's tables, have the driver decode the entries
492492
// and return the tuple {ep ID, value}. value is a string that coveys
493493
// relevant info about the endpoint.
494-
for _, table := range n.driverTables {
495-
if table.objType != driverapi.EndpointObject {
496-
continue
497-
}
498-
for key, value := range agent.networkDB.GetTableByNetwork(table.name, nwID) {
499-
epID, info := d.DecodeTableEntry(table.name, key, value.Value)
500-
if ep, ok := eps[epID]; !ok {
501-
log.G(context.TODO()).Errorf("Inconsistent driver and libnetwork state for endpoint %s", epID)
502-
} else {
503-
ep.info = info
504-
eps[epID] = ep
494+
if d, ok := d.(driverapi.TableWatcher); ok {
495+
for _, table := range n.driverTables {
496+
if table.objType != driverapi.EndpointObject {
497+
continue
498+
}
499+
for key, value := range agent.networkDB.GetTableByNetwork(table.name, nwID) {
500+
epID, info := d.DecodeTableEntry(table.name, key, value.Value)
501+
if ep, ok := eps[epID]; !ok {
502+
log.G(context.TODO()).Errorf("Inconsistent driver and libnetwork state for endpoint %s", epID)
503+
} else {
504+
ep.info = info
505+
eps[epID] = ep
506+
}
505507
}
506508
}
507509
}
@@ -814,6 +816,11 @@ func (n *Network) handleDriverTableEvent(ev events.Event) {
814816
log.G(context.TODO()).Errorf("Could not resolve driver %s while handling driver table event: %v", n.networkType, err)
815817
return
816818
}
819+
ed, ok := d.(driverapi.TableWatcher)
820+
if !ok {
821+
log.G(context.TODO()).Errorf("Could not notify driver %s about table event: driver does not implement TableWatcher interface", n.networkType)
822+
return
823+
}
817824

818825
var (
819826
etype driverapi.EventType
@@ -833,7 +840,7 @@ func (n *Network) handleDriverTableEvent(ev events.Event) {
833840
etype = driverapi.Update
834841
}
835842

836-
d.EventNotify(etype, n.ID(), event.Table, event.Key, value)
843+
ed.EventNotify(etype, n.ID(), event.Table, event.Key, value)
837844
}
838845

839846
func (c *Controller) handleNodeTableEvent(ev events.Event) {

daemon/libnetwork/cnmallocator/manager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ func (d *manager) CreateNetwork(ctx context.Context, id string, option map[strin
3232
return types.NotImplementedErrorf("not implemented")
3333
}
3434

35-
func (d *manager) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
36-
}
37-
38-
func (d *manager) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
39-
return "", nil
40-
}
41-
4235
func (d *manager) DeleteNetwork(nid string) error {
4336
return types.NotImplementedErrorf("not implemented")
4437
}

daemon/libnetwork/driverapi/driverapi.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ type Driver interface {
5656
// Leave method is invoked when a Sandbox detaches from an endpoint.
5757
Leave(nid, eid string) error
5858

59+
// Type returns the type of this driver, the network type this driver manages
60+
Type() string
61+
62+
// IsBuiltIn returns true if it is a built-in driver
63+
IsBuiltIn() bool
64+
}
65+
66+
// TableWatcher is an optional interface for a network driver.
67+
type TableWatcher interface {
5968
// EventNotify notifies the driver when a CRUD operation has
6069
// happened on a table of its interest as soon as this node
6170
// receives such an event in the gossip layer. This method is
@@ -71,12 +80,6 @@ type Driver interface {
7180
// For example: overlay driver returns the VTEP IP of the host that has the endpoint
7281
// which is shown in 'network inspect --verbose'
7382
DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string)
74-
75-
// Type returns the type of this driver, the network type this driver manages
76-
Type() string
77-
78-
// IsBuiltIn returns true if it is a built-in driver
79-
IsBuiltIn() bool
8083
}
8184

8285
// ExtConner is an optional interface for a network driver.

daemon/libnetwork/drivers/bridge/bridge_linux.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,6 @@ func (d *driver) NetworkFree(id string) error {
705705
return types.NotImplementedErrorf("not implemented")
706706
}
707707

708-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
709-
}
710-
711-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
712-
return "", nil
713-
}
714-
715708
func (d *driver) GetSkipGwAlloc(opts options.Generic) (ipv4, ipv6 bool, _ error) {
716709
// The network doesn't exist yet, so use a dummy id that's long enough to be
717710
// truncated to a short-id (12 characters) and used in the bridge device name.

daemon/libnetwork/drivers/bridge/brmanager/brmanager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string
3232
return types.NotImplementedErrorf("not implemented")
3333
}
3434

35-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
36-
}
37-
38-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
39-
return "", nil
40-
}
41-
4235
func (d *driver) DeleteNetwork(nid string) error {
4336
return types.NotImplementedErrorf("not implemented")
4437
}

daemon/libnetwork/drivers/host/host.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ func (d *driver) NetworkFree(id string) error {
3131
return types.NotImplementedErrorf("not implemented")
3232
}
3333

34-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
35-
}
36-
37-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
38-
return "", nil
39-
}
40-
4134
func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
4235
d.Lock()
4336
defer d.Unlock()

daemon/libnetwork/drivers/ipvlan/ipvlan.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,3 @@ func (d *driver) Type() string {
9595
func (d *driver) IsBuiltIn() bool {
9696
return true
9797
}
98-
99-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
100-
}
101-
102-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
103-
return "", nil
104-
}

daemon/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string
3232
return types.NotImplementedErrorf("not implemented")
3333
}
3434

35-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
36-
}
37-
38-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
39-
return "", nil
40-
}
41-
4235
func (d *driver) DeleteNetwork(nid string) error {
4336
return types.NotImplementedErrorf("not implemented")
4437
}

daemon/libnetwork/drivers/macvlan/macvlan.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,3 @@ func (d *driver) Type() string {
8989
func (d *driver) IsBuiltIn() bool {
9090
return true
9191
}
92-
93-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
94-
}
95-
96-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
97-
return "", nil
98-
}

daemon/libnetwork/drivers/macvlan/mvmanager/mvmanager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string
3232
return types.NotImplementedErrorf("not implemented")
3333
}
3434

35-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
36-
}
37-
38-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
39-
return "", nil
40-
}
41-
4235
func (d *driver) DeleteNetwork(nid string) error {
4336
return types.NotImplementedErrorf("not implemented")
4437
}

0 commit comments

Comments
 (0)