libnetwork/driverapi: make discoverAPI an optional part of the interface
Most drivers do not implement this, so detect if a driver implements the discoverAPI, and remove the implementation from drivers that do not support it. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
70e620f791
commit
fca38bcd0a
17 changed files with 28 additions and 140 deletions
|
@ -182,8 +182,11 @@ func (c *Controller) handleKeyChange(keys []*types.EncryptionKey) error {
|
|||
}
|
||||
|
||||
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
|
||||
err := driver.DiscoverNew(discoverapi.EncryptionKeysUpdate, drvEnc)
|
||||
if err != nil {
|
||||
dr, ok := driver.(discoverapi.Discover)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if err := dr.DiscoverNew(discoverapi.EncryptionKeysUpdate, drvEnc); err != nil {
|
||||
log.G(context.TODO()).Warnf("Failed to update datapath keys in driver %s: %v", name, err)
|
||||
// Attempt to reconfigure keys in case of a update failure
|
||||
// which can arise due to a mismatch of keys
|
||||
|
@ -191,7 +194,7 @@ func (c *Controller) handleKeyChange(keys []*types.EncryptionKey) error {
|
|||
log.G(context.TODO()).Warnf("Reconfiguring datapath keys for %s", name)
|
||||
drvCfgEnc := discoverapi.DriverEncryptionConfig{}
|
||||
drvCfgEnc.Keys, drvCfgEnc.Tags = c.getKeys(subsysIPSec)
|
||||
err = driver.DiscoverNew(discoverapi.EncryptionKeysConfig, drvCfgEnc)
|
||||
err = dr.DiscoverNew(discoverapi.EncryptionKeysConfig, drvCfgEnc)
|
||||
if err != nil {
|
||||
log.G(context.TODO()).Warnf("Failed to reset datapath keys in driver %s: %v", name, err)
|
||||
}
|
||||
|
@ -232,7 +235,9 @@ func (c *Controller) agentSetup(clusterProvider cluster.Provider) error {
|
|||
}
|
||||
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
|
||||
if capability.ConnectivityScope == datastore.GlobalScope {
|
||||
c.agentDriverNotify(driver)
|
||||
if d, ok := driver.(discoverapi.Discover); ok {
|
||||
c.agentDriverNotify(d)
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
@ -337,9 +342,10 @@ func (c *Controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
|
|||
drvEnc.Tags = tags
|
||||
|
||||
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
|
||||
err := driver.DiscoverNew(discoverapi.EncryptionKeysConfig, drvEnc)
|
||||
if err != nil {
|
||||
log.G(context.TODO()).Warnf("Failed to set datapath keys in driver %s: %v", name, err)
|
||||
if dr, ok := driver.(discoverapi.Discover); ok {
|
||||
if err := dr.DiscoverNew(discoverapi.EncryptionKeysConfig, drvEnc); err != nil {
|
||||
log.G(context.TODO()).Warnf("Failed to set datapath keys in driver %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
@ -357,7 +363,7 @@ func (c *Controller) agentJoin(remoteAddrList []string) error {
|
|||
return agent.networkDB.Join(remoteAddrList)
|
||||
}
|
||||
|
||||
func (c *Controller) agentDriverNotify(d driverapi.Driver) {
|
||||
func (c *Controller) agentDriverNotify(d discoverapi.Discover) {
|
||||
agent := c.getAgent()
|
||||
if agent == nil {
|
||||
return
|
||||
|
|
|
@ -385,12 +385,14 @@ func (c *Controller) BuiltinIPAMDrivers() []string {
|
|||
|
||||
func (c *Controller) processNodeDiscovery(nodes []net.IP, add bool) {
|
||||
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
|
||||
c.pushNodeDiscovery(driver, capability, nodes, add)
|
||||
if d, ok := driver.(discoverapi.Discover); ok {
|
||||
c.pushNodeDiscovery(d, capability, nodes, add)
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capability, nodes []net.IP, add bool) {
|
||||
func (c *Controller) pushNodeDiscovery(d discoverapi.Discover, cap driverapi.Capability, nodes []net.IP, add bool) {
|
||||
var self net.IP
|
||||
// try swarm-mode config
|
||||
if agent := c.getAgent(); agent != nil {
|
||||
|
@ -452,7 +454,9 @@ func (c *Controller) GetPluginGetter() plugingetter.PluginGetter {
|
|||
}
|
||||
|
||||
func (c *Controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
|
||||
c.agentDriverNotify(driver)
|
||||
if d, ok := driver.(discoverapi.Discover); ok {
|
||||
c.agentDriverNotify(d)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
package driverapi
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
)
|
||||
import "net"
|
||||
|
||||
// NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
|
||||
const NetworkPluginEndpointType = "NetworkDriver"
|
||||
|
||||
// Driver is an interface that every plugin driver needs to implement.
|
||||
type Driver interface {
|
||||
discoverapi.Discover
|
||||
|
||||
// NetworkAllocate invokes the driver method to allocate network
|
||||
// specific resources passing network id and network specific config.
|
||||
// It returns a key,value pair of network specific driver allocations
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/iptables"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
|
@ -1435,16 +1434,6 @@ func (d *driver) IsBuiltIn() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseEndpointOptions(epOptions map[string]interface{}) (*endpointConfiguration, error) {
|
||||
if epOptions == nil {
|
||||
return nil, nil
|
||||
|
|
|
@ -2,7 +2,6 @@ package brmanager
|
|||
|
||||
import (
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -70,14 +69,6 @@ func (d *driver) IsBuiltIn() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -92,13 +91,3 @@ func (d *driver) Type() string {
|
|||
func (d *driver) IsBuiltIn() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -104,16 +103,6 @@ func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event.
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event.
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package ivmanager
|
|||
|
||||
import (
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -70,14 +69,6 @@ func (d *driver) IsBuiltIn() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -98,16 +97,6 @@ func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package mvmanager
|
|||
|
||||
import (
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -70,14 +69,6 @@ func (d *driver) IsBuiltIn() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -92,13 +91,3 @@ func (d *driver) Type() string {
|
|||
func (d *driver) IsBuiltIn() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ const (
|
|||
secureOption = "encrypted"
|
||||
)
|
||||
|
||||
// overlay driver must implement the discover-API.
|
||||
var _ discoverapi.Discover = (*driver)(nil)
|
||||
|
||||
type driver struct {
|
||||
bindAddress string
|
||||
advertiseAddress string
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/containerd/containerd/log"
|
||||
"github.com/docker/docker/libnetwork/bitmap"
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/drivers/overlay/overlayutils"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
|
@ -208,16 +207,6 @@ func (d *driver) IsBuiltIn() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
|
||||
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
|
||||
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
||||
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
|
||||
return types.NotImplementedErrorf("not implemented")
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// remote driver must implement the discover-API.
|
||||
var _ discoverapi.Discover = (*driver)(nil)
|
||||
|
||||
type driver struct {
|
||||
endpoint *plugins.Client
|
||||
networkType string
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -57,14 +56,6 @@ func (a *allocator) ReleaseAddress(poolID string, ip net.IP) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *allocator) IsBuiltIn() bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"net"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/remote/api"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
|
@ -168,16 +167,6 @@ func (a *allocator) ReleaseAddress(poolID string, address net.IP) error {
|
|||
return a.call("ReleaseAddress", req, res)
|
||||
}
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event, such as a new global datastore
|
||||
func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
|
||||
func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *allocator) IsBuiltIn() bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
"github.com/docker/docker/internal/testutils/netnsutils"
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
|
@ -674,14 +673,6 @@ func (b *badDriver) Leave(nid, eid string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *badDriver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *badDriver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *badDriver) Type() string {
|
||||
return badDriverName
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue