Skip to content

Commit b22872a

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]> (cherry picked from commit 844023f) Signed-off-by: Cory Snider <[email protected]>
1 parent c7e17ae commit b22872a

17 files changed

Lines changed: 34 additions & 111 deletions

File tree

libnetwork/agent.go

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

817824
var (
818825
etype driverapi.EventType
@@ -832,7 +839,7 @@ func (n *Network) handleDriverTableEvent(ev events.Event) {
832839
etype = driverapi.Update
833840
}
834841

835-
d.EventNotify(etype, n.ID(), event.Table, event.Key, value)
842+
ed.EventNotify(etype, n.ID(), event.Table, event.Key, value)
836843
}
837844

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

libnetwork/cnmallocator/manager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ func (d *manager) CreateNetwork(id string, option map[string]interface{}, nInfo
3030
return types.NotImplementedErrorf("not implemented")
3131
}
3232

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

libnetwork/driverapi/driverapi.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ type Driver interface {
5959
// programming that was done so far
6060
RevokeExternalConnectivity(nid, eid string) error
6161

62+
// Type returns the type of this driver, the network type this driver manages
63+
Type() string
64+
65+
// IsBuiltIn returns true if it is a built-in driver
66+
IsBuiltIn() bool
67+
}
68+
69+
// TableWatcher is an optional interface for a network driver.
70+
type TableWatcher interface {
6271
// EventNotify notifies the driver when a CRUD operation has
6372
// happened on a table of its interest as soon as this node
6473
// receives such an event in the gossip layer. This method is
@@ -74,12 +83,6 @@ type Driver interface {
7483
// For example: overlay driver returns the VTEP IP of the host that has the endpoint
7584
// which is shown in 'network inspect --verbose'
7685
DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string)
77-
78-
// Type returns the type of this driver, the network type this driver manages
79-
Type() string
80-
81-
// IsBuiltIn returns true if it is a built-in driver
82-
IsBuiltIn() bool
8386
}
8487

8588
// NetworkInfo provides a go interface for drivers to provide network

libnetwork/drivers/bridge/bridge_linux.go

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

628-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
629-
}
630-
631-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
632-
return "", nil
633-
}
634-
635628
// Create a new network using bridge plugin
636629
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
637630
if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {

libnetwork/drivers/bridge/brmanager/brmanager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
3030
return types.NotImplementedErrorf("not implemented")
3131
}
3232

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

libnetwork/drivers/host/host.go

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

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

libnetwork/drivers/ipvlan/ipvlan.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,3 @@ func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string
102102
func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
103103
return nil
104104
}
105-
106-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
107-
}
108-
109-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
110-
return "", nil
111-
}

libnetwork/drivers/ipvlan/ivmanager/ivmanager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
3030
return types.NotImplementedErrorf("not implemented")
3131
}
3232

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

libnetwork/drivers/macvlan/macvlan.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,3 @@ func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string
9696
func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
9797
return nil
9898
}
99-
100-
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
101-
}
102-
103-
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
104-
return "", nil
105-
}

libnetwork/drivers/macvlan/mvmanager/mvmanager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
3030
return types.NotImplementedErrorf("not implemented")
3131
}
3232

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

0 commit comments

Comments
 (0)