mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Vendor in docker/libnetwork.
Signed-off-by: Anusha Ragunathan <anusha@docker.com>
This commit is contained in:
parent
d89fb40e1c
commit
2b0f0d0d71
14 changed files with 79 additions and 30 deletions
|
@ -70,7 +70,7 @@ clone git github.com/RackSec/srslog 365bf33cd9acc21ae1c355209865f17228ca534e
|
||||||
clone git github.com/imdario/mergo 0.2.1
|
clone git github.com/imdario/mergo 0.2.1
|
||||||
|
|
||||||
#get libnetwork packages
|
#get libnetwork packages
|
||||||
clone git github.com/docker/libnetwork bf3d9ccfb8ebf768843691143c66d137743cc5e9
|
clone git github.com/docker/libnetwork 66764992b5bff765a5aa2318ca3768ad22c4ce95
|
||||||
clone git github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
|
clone git github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
|
||||||
clone git github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
clone git github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
||||||
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
||||||
|
|
|
@ -191,8 +191,7 @@ func (c *controller) agentSetup() error {
|
||||||
|
|
||||||
if remoteAddr != "" {
|
if remoteAddr != "" {
|
||||||
if err := c.agentJoin(remoteAddr); err != nil {
|
if err := c.agentJoin(remoteAddr); err != nil {
|
||||||
logrus.Errorf("Error in agentJoin : %v", err)
|
logrus.Errorf("Error in joining gossip cluster : %v(join will be retried in background)", err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/discovery"
|
"github.com/docker/docker/pkg/discovery"
|
||||||
|
"github.com/docker/docker/plugin/getter"
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
"github.com/docker/libkv/store"
|
"github.com/docker/libkv/store"
|
||||||
"github.com/docker/libnetwork/cluster"
|
"github.com/docker/libnetwork/cluster"
|
||||||
|
@ -20,6 +21,7 @@ type Config struct {
|
||||||
Cluster ClusterCfg
|
Cluster ClusterCfg
|
||||||
Scopes map[string]*datastore.ScopeCfg
|
Scopes map[string]*datastore.ScopeCfg
|
||||||
ActiveSandboxes map[string]interface{}
|
ActiveSandboxes map[string]interface{}
|
||||||
|
PluginGetter getter.PluginGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
// DaemonCfg represents libnetwork core configuration
|
// DaemonCfg represents libnetwork core configuration
|
||||||
|
@ -205,6 +207,13 @@ func OptionExecRoot(execRoot string) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OptionPluginGetter returns a plugingetter for remote drivers.
|
||||||
|
func OptionPluginGetter(pg getter.PluginGetter) Option {
|
||||||
|
return func(c *Config) {
|
||||||
|
c.PluginGetter = pg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessOptions processes options and stores it in config
|
// ProcessOptions processes options and stores it in config
|
||||||
func (c *Config) ProcessOptions(options ...Option) {
|
func (c *Config) ProcessOptions(options ...Option) {
|
||||||
for _, opt := range options {
|
for _, opt := range options {
|
||||||
|
|
|
@ -55,6 +55,7 @@ import (
|
||||||
"github.com/docker/docker/pkg/locker"
|
"github.com/docker/docker/pkg/locker"
|
||||||
"github.com/docker/docker/pkg/plugins"
|
"github.com/docker/docker/pkg/plugins"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
"github.com/docker/docker/plugin/getter"
|
||||||
"github.com/docker/libnetwork/cluster"
|
"github.com/docker/libnetwork/cluster"
|
||||||
"github.com/docker/libnetwork/config"
|
"github.com/docker/libnetwork/config"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
|
@ -178,7 +179,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil)
|
drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil, c.cfg.PluginGetter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -601,6 +602,10 @@ func (c *controller) isDistributedControl() bool {
|
||||||
return !c.isManager() && !c.isAgent()
|
return !c.isManager() && !c.isAgent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *controller) GetPluginGetter() getter.PluginGetter {
|
||||||
|
return c.drvRegistry.GetPluginGetter()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
|
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
hd := c.discovery
|
hd := c.discovery
|
||||||
|
@ -1074,7 +1079,7 @@ func (c *controller) loadDriver(networkType string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) loadIPAMDriver(name string) error {
|
func (c *controller) loadIPAMDriver(name string) error {
|
||||||
if _, err := plugins.Get(name, ipamapi.PluginEndpointType); err != nil {
|
if _, err := c.GetPluginGetter().Get(name, ipamapi.PluginEndpointType, getter.LOOKUP); err != nil {
|
||||||
if err == plugins.ErrNotFound {
|
if err == plugins.ErrNotFound {
|
||||||
return types.NotFoundErrorf(err.Error())
|
return types.NotFoundErrorf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package driverapi
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/docker/docker/plugin/getter"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -139,6 +140,8 @@ type JoinInfo interface {
|
||||||
|
|
||||||
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
||||||
type DriverCallback interface {
|
type DriverCallback interface {
|
||||||
|
// GetPluginGetter returns the pluginv2 getter.
|
||||||
|
GetPluginGetter() getter.PluginGetter
|
||||||
// RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
|
// RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
|
||||||
RegisterDriver(name string, driver Driver, capability Capability) error
|
RegisterDriver(name string, driver Driver, capability Capability) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ type configuration struct {
|
||||||
EnableIPForwarding bool
|
EnableIPForwarding bool
|
||||||
EnableIPTables bool
|
EnableIPTables bool
|
||||||
EnableUserlandProxy bool
|
EnableUserlandProxy bool
|
||||||
|
UserlandProxyPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// networkConfiguration for network specific configuration
|
// networkConfiguration for network specific configuration
|
||||||
|
@ -638,7 +639,7 @@ func (d *driver) createNetwork(config *networkConfiguration) error {
|
||||||
id: config.ID,
|
id: config.ID,
|
||||||
endpoints: make(map[string]*bridgeEndpoint),
|
endpoints: make(map[string]*bridgeEndpoint),
|
||||||
config: config,
|
config: config,
|
||||||
portMapper: portmapper.New(),
|
portMapper: portmapper.New(d.config.UserlandProxyPath),
|
||||||
driver: d,
|
driver: d,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,12 @@ 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 {
|
||||||
plugins.Handle(driverapi.NetworkPluginEndpointType, func(name string, client *plugins.Client) {
|
// 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
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/docker/docker/plugin/getter"
|
||||||
"github.com/docker/libnetwork/driverapi"
|
"github.com/docker/libnetwork/driverapi"
|
||||||
"github.com/docker/libnetwork/ipamapi"
|
"github.com/docker/libnetwork/ipamapi"
|
||||||
"github.com/docker/libnetwork/types"
|
"github.com/docker/libnetwork/types"
|
||||||
|
@ -32,6 +33,7 @@ type DrvRegistry struct {
|
||||||
ipamDrivers ipamTable
|
ipamDrivers ipamTable
|
||||||
dfn DriverNotifyFunc
|
dfn DriverNotifyFunc
|
||||||
ifn IPAMNotifyFunc
|
ifn IPAMNotifyFunc
|
||||||
|
pluginGetter getter.PluginGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functors definition
|
// Functors definition
|
||||||
|
@ -52,12 +54,13 @@ type IPAMNotifyFunc func(name string, driver ipamapi.Ipam, cap *ipamapi.Capabili
|
||||||
type DriverNotifyFunc func(name string, driver driverapi.Driver, capability driverapi.Capability) error
|
type DriverNotifyFunc func(name string, driver driverapi.Driver, capability driverapi.Capability) error
|
||||||
|
|
||||||
// New retruns a new driver registry handle.
|
// New retruns a new driver registry handle.
|
||||||
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc) (*DrvRegistry, error) {
|
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg getter.PluginGetter) (*DrvRegistry, error) {
|
||||||
r := &DrvRegistry{
|
r := &DrvRegistry{
|
||||||
drivers: make(driverTable),
|
drivers: make(driverTable),
|
||||||
ipamDrivers: make(ipamTable),
|
ipamDrivers: make(ipamTable),
|
||||||
dfn: dfn,
|
dfn: dfn,
|
||||||
ifn: ifn,
|
ifn: ifn,
|
||||||
|
pluginGetter: pg,
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
|
@ -149,6 +152,11 @@ func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, err
|
||||||
return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil
|
return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPluginGetter returns the plugingetter
|
||||||
|
func (r *DrvRegistry) GetPluginGetter() getter.PluginGetter {
|
||||||
|
return r.pluginGetter
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterDriver registers the network driver when it gets discovered.
|
// RegisterDriver registers the network driver when it gets discovered.
|
||||||
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error {
|
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error {
|
||||||
if strings.TrimSpace(ntype) == "" {
|
if strings.TrimSpace(ntype) == "" {
|
||||||
|
|
|
@ -4,6 +4,7 @@ package ipamapi
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/docker/docker/plugin/getter"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
"github.com/docker/libnetwork/types"
|
"github.com/docker/libnetwork/types"
|
||||||
)
|
)
|
||||||
|
@ -25,6 +26,8 @@ const (
|
||||||
|
|
||||||
// Callback provides a Callback interface for registering an IPAM instance into LibNetwork
|
// Callback provides a Callback interface for registering an IPAM instance into LibNetwork
|
||||||
type Callback interface {
|
type Callback interface {
|
||||||
|
// GetPluginGetter returns the pluginv2 getter.
|
||||||
|
GetPluginGetter() getter.PluginGetter
|
||||||
// RegisterIpamDriver provides a way for Remote drivers to dynamically register with libnetwork
|
// RegisterIpamDriver provides a way for Remote drivers to dynamically register with libnetwork
|
||||||
RegisterIpamDriver(name string, driver Ipam) error
|
RegisterIpamDriver(name string, driver Ipam) error
|
||||||
// RegisterIpamDriverWithCapabilities provides a way for Remote drivers to dynamically register with libnetwork and specify capabilities
|
// RegisterIpamDriverWithCapabilities provides a way for Remote drivers to dynamically register with libnetwork and specify capabilities
|
||||||
|
|
|
@ -30,7 +30,13 @@ 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 {
|
||||||
plugins.Handle(ipamapi.PluginEndpointType, func(name string, client *plugins.Client) {
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
|
|
@ -161,6 +161,10 @@ func (nDB *NetworkDB) retryJoin(members []string, stop <-chan struct{}) {
|
||||||
logrus.Errorf("Failed to join memberlist %s on retry: %v", members, err)
|
logrus.Errorf("Failed to join memberlist %s on retry: %v", members, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if err := nDB.sendNodeEvent(NodeEventTypeJoin); err != nil {
|
||||||
|
logrus.Errorf("failed to send node join on retry: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
return
|
return
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
|
|
|
@ -38,19 +38,22 @@ type PortMapper struct {
|
||||||
currentMappings map[string]*mapping
|
currentMappings map[string]*mapping
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
|
|
||||||
|
proxyPath string
|
||||||
|
|
||||||
Allocator *portallocator.PortAllocator
|
Allocator *portallocator.PortAllocator
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new instance of PortMapper
|
// New returns a new instance of PortMapper
|
||||||
func New() *PortMapper {
|
func New(proxyPath string) *PortMapper {
|
||||||
return NewWithPortAllocator(portallocator.Get())
|
return NewWithPortAllocator(portallocator.Get(), proxyPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator
|
// NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator
|
||||||
func NewWithPortAllocator(allocator *portallocator.PortAllocator) *PortMapper {
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
|
||||||
return &PortMapper{
|
return &PortMapper{
|
||||||
currentMappings: make(map[string]*mapping),
|
currentMappings: make(map[string]*mapping),
|
||||||
Allocator: allocator,
|
Allocator: allocator,
|
||||||
|
proxyPath: proxyPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +93,7 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
if useProxy {
|
if useProxy {
|
||||||
m.userlandProxy, err = newProxy(proto, hostIP, allocatedHostPort, container.(*net.TCPAddr).IP, container.(*net.TCPAddr).Port)
|
m.userlandProxy, err = newProxy(proto, hostIP, allocatedHostPort, container.(*net.TCPAddr).IP, container.(*net.TCPAddr).Port, pm.proxyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -110,7 +113,7 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
if useProxy {
|
if useProxy {
|
||||||
m.userlandProxy, err = newProxy(proto, hostIP, allocatedHostPort, container.(*net.UDPAddr).IP, container.(*net.UDPAddr).Port)
|
m.userlandProxy, err = newProxy(proto, hostIP, allocatedHostPort, container.(*net.UDPAddr).IP, container.(*net.UDPAddr).Port, pm.proxyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package portmapper
|
||||||
|
|
||||||
import "net"
|
import "net"
|
||||||
|
|
||||||
func newMockProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP net.IP, containerPort int) (userlandProxy, error) {
|
func newMockProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP net.IP, containerPort int, userlandProxyPath string) (userlandProxy, error) {
|
||||||
return &mockProxyCommand{}, nil
|
return &mockProxyCommand{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,15 +25,18 @@ type proxyCommand struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP net.IP, containerPort int) (userlandProxy, error) {
|
func newProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP net.IP, containerPort int, proxyPath string) (userlandProxy, error) {
|
||||||
|
path := proxyPath
|
||||||
|
if proxyPath == "" {
|
||||||
cmd, err := exec.LookPath(userlandProxyCommandName)
|
cmd, err := exec.LookPath(userlandProxyCommandName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
path = cmd
|
||||||
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
cmd,
|
path,
|
||||||
"-proto", proto,
|
"-proto", proto,
|
||||||
"-host-ip", hostIP.String(),
|
"-host-ip", hostIP.String(),
|
||||||
"-host-port", strconv.Itoa(hostPort),
|
"-host-port", strconv.Itoa(hostPort),
|
||||||
|
@ -43,7 +46,7 @@ func newProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP net.
|
||||||
|
|
||||||
return &proxyCommand{
|
return &proxyCommand{
|
||||||
cmd: &exec.Cmd{
|
cmd: &exec.Cmd{
|
||||||
Path: cmd,
|
Path: path,
|
||||||
Args: args,
|
Args: args,
|
||||||
SysProcAttr: &syscall.SysProcAttr{
|
SysProcAttr: &syscall.SysProcAttr{
|
||||||
Pdeathsig: syscall.SIGTERM, // send a sigterm to the proxy if the daemon process dies
|
Pdeathsig: syscall.SIGTERM, // send a sigterm to the proxy if the daemon process dies
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue