Skip to content

Commit 7b26d7e

Browse files
Make libnetwork understand pluginv2.
As part of daemon init, network and ipam drivers are passed a pluginstore object that implements the plugin/getter interface. Use this interface methods in libnetwork to interact with network plugins. This interface provides the new and improved pluginv2 functionality and falls back to pluginv1 (legacy) if necessary. Signed-off-by: Anusha Ragunathan <[email protected]>
1 parent 25df221 commit 7b26d7e

File tree

12 files changed

+73
-14
lines changed

12 files changed

+73
-14
lines changed

cmd/ovrouter/ovrouter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/signal"
88

99
"github.com/docker/docker/pkg/reexec"
10+
"github.com/docker/docker/plugin/getter"
1011
"github.com/docker/libnetwork/driverapi"
1112
"github.com/docker/libnetwork/drivers/overlay"
1213
"github.com/docker/libnetwork/netlabel"
@@ -24,6 +25,10 @@ type endpoint struct {
2425
name string
2526
}
2627

28+
func (r *router) GetPluginGetter() getter.PluginGetter {
29+
return nil
30+
}
31+
2732
func (r *router) RegisterDriver(name string, driver driverapi.Driver, c driverapi.Capability) error {
2833
r.d = driver
2934
return nil

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/BurntSushi/toml"
77
log "github.com/Sirupsen/logrus"
88
"github.com/docker/docker/pkg/discovery"
9+
"github.com/docker/docker/plugin/getter"
910
"github.com/docker/go-connections/tlsconfig"
1011
"github.com/docker/libkv/store"
1112
"github.com/docker/libnetwork/cluster"
@@ -20,6 +21,7 @@ type Config struct {
2021
Cluster ClusterCfg
2122
Scopes map[string]*datastore.ScopeCfg
2223
ActiveSandboxes map[string]interface{}
24+
PluginGetter getter.PluginGetter
2325
}
2426

2527
// DaemonCfg represents libnetwork core configuration
@@ -205,6 +207,13 @@ func OptionExecRoot(execRoot string) Option {
205207
}
206208
}
207209

210+
// OptionPluginGetter returns a plugingetter for remote drivers.
211+
func OptionPluginGetter(pg getter.PluginGetter) Option {
212+
return func(c *Config) {
213+
c.PluginGetter = pg
214+
}
215+
}
216+
208217
// ProcessOptions processes options and stores it in config
209218
func (c *Config) ProcessOptions(options ...Option) {
210219
for _, opt := range options {

controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"github.com/docker/docker/pkg/locker"
5656
"github.com/docker/docker/pkg/plugins"
5757
"github.com/docker/docker/pkg/stringid"
58+
"github.com/docker/docker/plugin/getter"
5859
"github.com/docker/libnetwork/cluster"
5960
"github.com/docker/libnetwork/config"
6061
"github.com/docker/libnetwork/datastore"
@@ -178,7 +179,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
178179
return nil, err
179180
}
180181

181-
drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil)
182+
drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil, c.cfg.PluginGetter)
182183
if err != nil {
183184
return nil, err
184185
}
@@ -601,6 +602,10 @@ func (c *controller) isDistributedControl() bool {
601602
return !c.isManager() && !c.isAgent()
602603
}
603604

605+
func (c *controller) GetPluginGetter() getter.PluginGetter {
606+
return c.drvRegistry.GetPluginGetter()
607+
}
608+
604609
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
605610
c.Lock()
606611
hd := c.discovery
@@ -1074,7 +1079,7 @@ func (c *controller) loadDriver(networkType string) error {
10741079
}
10751080

10761081
func (c *controller) loadIPAMDriver(name string) error {
1077-
if _, err := plugins.Get(name, ipamapi.PluginEndpointType); err != nil {
1082+
if _, err := c.GetPluginGetter().Get(name, ipamapi.PluginEndpointType, getter.LOOKUP); err != nil {
10781083
if err == plugins.ErrNotFound {
10791084
return types.NotFoundErrorf(err.Error())
10801085
}

driverapi/driverapi.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package driverapi
33
import (
44
"net"
55

6+
"github.com/docker/docker/plugin/getter"
67
"github.com/docker/libnetwork/discoverapi"
78
)
89

@@ -139,6 +140,8 @@ type JoinInfo interface {
139140

140141
// DriverCallback provides a Callback interface for Drivers into LibNetwork
141142
type DriverCallback interface {
143+
// GetPluginGetter returns the pluginv2 getter.
144+
GetPluginGetter() getter.PluginGetter
142145
// RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
143146
RegisterDriver(name string, driver Driver, capability Capability) error
144147
}

drivers/ipvlan/ipvlan_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ipvlan
33
import (
44
"testing"
55

6+
"github.com/docker/docker/plugin/getter"
67
"github.com/docker/libnetwork/driverapi"
78
_ "github.com/docker/libnetwork/testutils"
89
)
@@ -14,6 +15,10 @@ type driverTester struct {
1415
d *driver
1516
}
1617

18+
func (dt *driverTester) GetPluginGetter() getter.PluginGetter {
19+
return nil
20+
}
21+
1722
func (dt *driverTester) RegisterDriver(name string, drv driverapi.Driver,
1823
cap driverapi.Capability) error {
1924
if name != testNetworkType {

drivers/macvlan/macvlan_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package macvlan
33
import (
44
"testing"
55

6+
"github.com/docker/docker/plugin/getter"
67
"github.com/docker/libnetwork/driverapi"
78
_ "github.com/docker/libnetwork/testutils"
89
)
@@ -14,6 +15,10 @@ type driverTester struct {
1415
d *driver
1516
}
1617

18+
func (dt *driverTester) GetPluginGetter() getter.PluginGetter {
19+
return nil
20+
}
21+
1722
func (dt *driverTester) RegisterDriver(name string, drv driverapi.Driver,
1823
cap driverapi.Capability) error {
1924
if name != testNetworkType {

drivers/overlay/overlay_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/docker/docker/plugin/getter"
89
"github.com/docker/libkv/store/consul"
910
"github.com/docker/libnetwork/datastore"
1011
"github.com/docker/libnetwork/discoverapi"
@@ -67,6 +68,10 @@ func cleanupDriver(t *testing.T, dt *driverTester) {
6768
}
6869
}
6970

71+
func (dt *driverTester) GetPluginGetter() getter.PluginGetter {
72+
return nil
73+
}
74+
7075
func (dt *driverTester) RegisterDriver(name string, drv driverapi.Driver,
7176
cap driverapi.Capability) error {
7277
if name != testNetworkType {

drivers/remote/driver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ func newDriver(name string, client *plugins.Client) driverapi.Driver {
2929
// Init makes sure a remote driver is registered when a network driver
3030
// plugin is activated.
3131
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
32-
plugins.Handle(driverapi.NetworkPluginEndpointType, func(name string, client *plugins.Client) {
32+
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
33+
handleFunc := plugins.Handle
34+
if pg := dc.GetPluginGetter(); pg != nil {
35+
handleFunc = pg.Handle
36+
}
37+
handleFunc(driverapi.NetworkPluginEndpointType, func(name string, client *plugins.Client) {
3338
// negotiate driver capability with client
3439
d := newDriver(name, client)
3540
c, err := d.(*driver).getCapabilities()

drvregistry/drvregistry.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"sync"
77

8+
"github.com/docker/docker/plugin/getter"
89
"github.com/docker/libnetwork/driverapi"
910
"github.com/docker/libnetwork/ipamapi"
1011
"github.com/docker/libnetwork/types"
@@ -28,10 +29,11 @@ type ipamTable map[string]*ipamData
2829
// DrvRegistry holds the registry of all network drivers and IPAM drivers that it knows about.
2930
type DrvRegistry struct {
3031
sync.Mutex
31-
drivers driverTable
32-
ipamDrivers ipamTable
33-
dfn DriverNotifyFunc
34-
ifn IPAMNotifyFunc
32+
drivers driverTable
33+
ipamDrivers ipamTable
34+
dfn DriverNotifyFunc
35+
ifn IPAMNotifyFunc
36+
pluginGetter getter.PluginGetter
3537
}
3638

3739
// Functors definition
@@ -52,12 +54,13 @@ type IPAMNotifyFunc func(name string, driver ipamapi.Ipam, cap *ipamapi.Capabili
5254
type DriverNotifyFunc func(name string, driver driverapi.Driver, capability driverapi.Capability) error
5355

5456
// New retruns a new driver registry handle.
55-
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc) (*DrvRegistry, error) {
57+
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg getter.PluginGetter) (*DrvRegistry, error) {
5658
r := &DrvRegistry{
57-
drivers: make(driverTable),
58-
ipamDrivers: make(ipamTable),
59-
dfn: dfn,
60-
ifn: ifn,
59+
drivers: make(driverTable),
60+
ipamDrivers: make(ipamTable),
61+
dfn: dfn,
62+
ifn: ifn,
63+
pluginGetter: pg,
6164
}
6265

6366
return r, nil
@@ -149,6 +152,11 @@ func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, err
149152
return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil
150153
}
151154

155+
// GetPluginGetter returns the plugingetter
156+
func (r *DrvRegistry) GetPluginGetter() getter.PluginGetter {
157+
return r.pluginGetter
158+
}
159+
152160
// RegisterDriver registers the network driver when it gets discovered.
153161
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error {
154162
if strings.TrimSpace(ntype) == "" {

drvregistry/drvregistry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (m *mockDriver) EventNotify(etype driverapi.EventType, nid, tableName, key
8888
}
8989

9090
func getNew(t *testing.T) *DrvRegistry {
91-
reg, err := New(nil, nil, nil, nil)
91+
reg, err := New(nil, nil, nil, nil, nil)
9292
if err != nil {
9393
t.Fatal(err)
9494
}

0 commit comments

Comments
 (0)