1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Vendoring libnetwork to bring in isbuiltin changes

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2017-01-03 11:59:59 -08:00
parent b219698e75
commit 15293063ba
22 changed files with 125 additions and 25 deletions

View file

@ -23,7 +23,7 @@ github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5
github.com/imdario/mergo 0.2.1 github.com/imdario/mergo 0.2.1
#get libnetwork packages #get libnetwork packages
github.com/docker/libnetwork b908488a139e81cb8c4091cd836745aeb4d813a4 github.com/docker/libnetwork ba79e3e43b8773892df745cd9a83b5eefd5b9b90
github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894 github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80 github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec

View file

@ -79,6 +79,9 @@ type NetworkController interface {
// BuiltinDrivers returns list of builtin drivers // BuiltinDrivers returns list of builtin drivers
BuiltinDrivers() []string BuiltinDrivers() []string
// BuiltinIPAMDrivers returns list of builtin ipam drivers
BuiltinIPAMDrivers() []string
// Config method returns the bootup configuration for the controller // Config method returns the bootup configuration for the controller
Config() config.Config Config() config.Config
@ -476,12 +479,23 @@ func (c *controller) ID() string {
func (c *controller) BuiltinDrivers() []string { func (c *controller) BuiltinDrivers() []string {
drivers := []string{} drivers := []string{}
for _, i := range getInitializers(c.cfg.Daemon.Experimental) { c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
if i.ntype == "remote" { if driver.IsBuiltIn() {
continue drivers = append(drivers, name)
} }
drivers = append(drivers, i.ntype) return false
})
return drivers
} }
func (c *controller) BuiltinIPAMDrivers() []string {
drivers := []string{}
c.drvRegistry.WalkIPAMs(func(name string, driver ipamapi.Ipam, cap *ipamapi.Capability) bool {
if driver.IsBuiltIn() {
drivers = append(drivers, name)
}
return false
})
return drivers return drivers
} }

View file

@ -74,6 +74,9 @@ type Driver interface {
// Type returns the the type of this driver, the network type this driver manages // Type returns the the type of this driver, the network type this driver manages
Type() string Type() string
// IsBuiltIn returns true if it is a built-in driver
IsBuiltIn() bool
} }
// NetworkInfo provides a go interface for drivers to provide network // NetworkInfo provides a go interface for drivers to provide network

View file

@ -1424,6 +1424,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil

View file

@ -86,6 +86,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil

View file

@ -84,6 +84,10 @@ func (d *driver) Type() string {
return ipvlanType return ipvlanType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
return nil return nil
} }

View file

@ -86,6 +86,10 @@ func (d *driver) Type() string {
return macvlanType return macvlanType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
return nil return nil
} }

View file

@ -86,6 +86,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil

View file

@ -211,6 +211,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
func validateSelf(node string) error { func validateSelf(node string) error {
advIP := net.ParseIP(node) advIP := net.ParseIP(node)
if advIP == nil { if advIP == nil {

View file

@ -229,6 +229,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
return types.NotImplementedErrorf("not implemented") return types.NotImplementedErrorf("not implemented")

View file

@ -29,12 +29,7 @@ func newDriver(name string, client *plugins.Client) driverapi.Driver {
// Init makes sure a remote driver is registered when a network driver // Init makes sure a remote driver is registered when a network driver
// plugin is activated. // plugin is activated.
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. newPluginHandler := func(name string, client *plugins.Client) {
handleFunc := plugins.Handle
if pg := dc.GetPluginGetter(); pg != nil {
handleFunc = pg.Handle
}
handleFunc(driverapi.NetworkPluginEndpointType, func(name string, client *plugins.Client) {
// negotiate driver capability with client // negotiate driver capability with client
d := newDriver(name, client) d := newDriver(name, client)
c, err := d.(*driver).getCapabilities() c, err := d.(*driver).getCapabilities()
@ -45,7 +40,19 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
if err = dc.RegisterDriver(name, d, *c); err != nil { if err = dc.RegisterDriver(name, d, *c); err != nil {
logrus.Errorf("error registering driver for %s due to %v", name, err) logrus.Errorf("error registering driver for %s due to %v", name, err)
} }
}) }
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
handleFunc := plugins.Handle
if pg := dc.GetPluginGetter(); pg != nil {
handleFunc = pg.Handle
activePlugins := pg.GetAllManagedPluginsByCap(driverapi.NetworkPluginEndpointType)
for _, ap := range activePlugins {
newPluginHandler(ap.Name(), ap.Client())
}
}
handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler)
return nil return nil
} }
@ -305,6 +312,10 @@ func (d *driver) Type() string {
return d.networkType return d.networkType
} }
func (d *driver) IsBuiltIn() bool {
return false
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
if dType != discoverapi.NodeDiscovery { if dType != discoverapi.NodeDiscovery {

View file

@ -916,6 +916,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil

View file

@ -200,6 +200,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
func validateSelf(node string) error { func validateSelf(node string) error {
advIP := net.ParseIP(node) advIP := net.ParseIP(node)
if advIP == nil { if advIP == nil {

View file

@ -176,6 +176,10 @@ func (d *driver) Type() string {
return networkType return networkType
} }
func (d *driver) IsBuiltIn() bool {
return true
}
func validateSelf(node string) error { func validateSelf(node string) error {
advIP := net.ParseIP(node) advIP := net.ParseIP(node)
if advIP == nil { if advIP == nil {

View file

@ -698,6 +698,10 @@ func (d *driver) Type() string {
return d.name return d.name
} }
func (d *driver) IsBuiltIn() bool {
return true
}
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster // 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 { func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil

View file

@ -164,10 +164,10 @@ func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capa
} }
r.Lock() r.Lock()
_, ok := r.drivers[ntype] dd, ok := r.drivers[ntype]
r.Unlock() r.Unlock()
if ok { if ok && dd.driver.IsBuiltIn() {
return driverapi.ErrActiveRegistration(ntype) return driverapi.ErrActiveRegistration(ntype)
} }
@ -192,9 +192,9 @@ func (r *DrvRegistry) registerIpamDriver(name string, driver ipamapi.Ipam, caps
} }
r.Lock() r.Lock()
_, ok := r.ipamDrivers[name] dd, ok := r.ipamDrivers[name]
r.Unlock() r.Unlock()
if ok { if ok && dd.driver.IsBuiltIn() {
return types.ForbiddenErrorf("ipam driver %q already registered", name) return types.ForbiddenErrorf("ipam driver %q already registered", name)
} }

View file

@ -594,3 +594,8 @@ func (a *Allocator) DumpDatabase() string {
return s return s
} }
// IsBuiltIn returns true for builtin drivers
func (a *Allocator) IsBuiltIn() bool {
return true
}

View file

@ -80,6 +80,9 @@ type Ipam interface {
RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error) RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
// Release the address from the specified pool ID // Release the address from the specified pool ID
ReleaseAddress(string, net.IP) error ReleaseAddress(string, net.IP) error
//IsBuiltIn returns true if it is a built-in driver.
IsBuiltIn() bool
} }
// Capability represents the requirements and capabilities of the IPAM driver // Capability represents the requirements and capabilities of the IPAM driver

View file

@ -65,6 +65,10 @@ func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interfa
return nil return nil
} }
func (a *allocator) IsBuiltIn() bool {
return true
}
// Init registers a remote ipam when its plugin is activated // Init registers a remote ipam when its plugin is activated
func Init(ic ipamapi.Callback, l, g interface{}) error { func Init(ic ipamapi.Callback, l, g interface{}) error {
return ic.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{}) return ic.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{})

View file

@ -31,12 +31,7 @@ func newAllocator(name string, client *plugins.Client) ipamapi.Ipam {
// Init registers a remote ipam when its plugin is activated // Init registers a remote ipam when its plugin is activated
func Init(cb ipamapi.Callback, l, g interface{}) error { func Init(cb ipamapi.Callback, l, g interface{}) error {
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. newPluginHandler := func(name string, client *plugins.Client) {
handleFunc := plugins.Handle
if pg := cb.GetPluginGetter(); pg != nil {
handleFunc = pg.Handle
}
handleFunc(ipamapi.PluginEndpointType, func(name string, client *plugins.Client) {
a := newAllocator(name, client) a := newAllocator(name, client)
if cps, err := a.(*allocator).getCapabilities(); err == nil { if cps, err := a.(*allocator).getCapabilities(); err == nil {
if err := cb.RegisterIpamDriverWithCapabilities(name, a, cps); err != nil { if err := cb.RegisterIpamDriverWithCapabilities(name, a, cps); err != nil {
@ -49,7 +44,18 @@ func Init(cb ipamapi.Callback, l, g interface{}) error {
logrus.Errorf("error registering remote ipam driver %s due to %v", name, err) logrus.Errorf("error registering remote ipam driver %s due to %v", name, err)
} }
} }
}) }
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
handleFunc := plugins.Handle
if pg := cb.GetPluginGetter(); pg != nil {
handleFunc = pg.Handle
activePlugins := pg.GetAllManagedPluginsByCap(ipamapi.PluginEndpointType)
for _, ap := range activePlugins {
newPluginHandler(ap.Name(), ap.Client())
}
}
handleFunc(ipamapi.PluginEndpointType, newPluginHandler)
return nil return nil
} }
@ -143,3 +149,7 @@ func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{
func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil
} }
func (a *allocator) IsBuiltIn() bool {
return false
}

View file

@ -101,3 +101,7 @@ func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{
func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
return nil return nil
} }
func (a *allocator) IsBuiltIn() bool {
return true
}

View file

@ -1637,7 +1637,9 @@ func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) {
n.Unlock() n.Unlock()
if ip != nil { if ip != nil {
return ip, false ipLocal := make([]net.IP, len(ip))
copy(ipLocal, ip)
return ipLocal, false
} }
return nil, ipv6Miss return nil, ipv6Miss