Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,6 @@ func (c *controller) loadDriver(networkType string) error {
}

if err != nil {
if err == plugins.ErrNotFound {
return types.NotFoundErrorf(err.Error())
}
return err
}

Expand Down
31 changes: 29 additions & 2 deletions drivers/remote/driver.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package remote

import (
"errors"
"fmt"
"net"

"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/docker/pkg/plugins"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/discoverapi"
"github.com/docker/libnetwork/driverapi"
"github.com/docker/libnetwork/drivers/remote/api"
"github.com/docker/libnetwork/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -49,14 +50,40 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
handleFunc = pg.Handle
activePlugins := pg.GetAllManagedPluginsByCap(driverapi.NetworkPluginEndpointType)
for _, ap := range activePlugins {
newPluginHandler(ap.Name(), ap.Client())
client, err := getPluginClient(ap)
if err != nil {
return err
}
newPluginHandler(ap.Name(), client)
}
}
handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler)

return nil
}

func getPluginClient(p plugingetter.CompatPlugin) (*plugins.Client, error) {
if v1, ok := p.(plugingetter.PluginWithV1Client); ok {
return v1.Client(), nil
}

pa, ok := p.(plugingetter.PluginAddr)
if !ok {
return nil, errors.Errorf("unknown plugin type %T", p)
}

if pa.Protocol() != plugins.ProtocolSchemeHTTPV1 {
return nil, errors.Errorf("unsupported plugin protocol %s", pa.Protocol())
}

addr := pa.Addr()
client, err := plugins.NewClientWithTimeout(addr.Network()+"://"+addr.String(), nil, pa.Timeout())
if err != nil {
return nil, errors.Wrap(err, "error creating plugin client")
}
return client, nil
}

// Get capability from client
func (d *driver) getCapabilities() (*driverapi.Capability, error) {
var capResp api.GetCapabilityResponse
Expand Down
44 changes: 37 additions & 7 deletions drivers/remote/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ func TestGetEmptyCapabilities(t *testing.T) {
t.Fatal(err)
}

d := newDriver(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newDriver(plugin, client)
if d.Type() != plugin {
t.Fatal("Driver type does not match that given")
}
Expand Down Expand Up @@ -249,7 +253,11 @@ func TestGetExtraCapabilities(t *testing.T) {
t.Fatal(err)
}

d := newDriver(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newDriver(plugin, client)
if d.Type() != plugin {
t.Fatal("Driver type does not match that given")
}
Expand Down Expand Up @@ -281,7 +289,11 @@ func TestGetInvalidCapabilities(t *testing.T) {
t.Fatal(err)
}

d := newDriver(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newDriver(plugin, client)
if d.Type() != plugin {
t.Fatal("Driver type does not match that given")
}
Expand Down Expand Up @@ -395,7 +407,11 @@ func TestRemoteDriver(t *testing.T) {
t.Fatal(err)
}

d := newDriver(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newDriver(plugin, client)
if d.Type() != plugin {
t.Fatal("Driver type does not match that given")
}
Expand Down Expand Up @@ -473,7 +489,11 @@ func TestDriverError(t *testing.T) {
t.Fatal(err)
}

driver := newDriver(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
driver := newDriver(plugin, client)

if err := driver.CreateEndpoint("dummy", "dummy", &testEndpoint{t: t}, map[string]interface{}{}); err == nil {
t.Fatal("Expected error from driver")
Expand Down Expand Up @@ -505,7 +525,12 @@ func TestMissingValues(t *testing.T) {
if err != nil {
t.Fatal(err)
}
driver := newDriver(plugin, p.Client())

client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
driver := newDriver(plugin, client)

if err := driver.CreateEndpoint("dummy", "dummy", ep, map[string]interface{}{}); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -566,7 +591,12 @@ func TestRollback(t *testing.T) {
if err != nil {
t.Fatal(err)
}
driver := newDriver(plugin, p.Client())

client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
driver := newDriver(plugin, client)

ep := &rollbackEndpoint{}

Expand Down
30 changes: 29 additions & 1 deletion ipams/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"net"

"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/docker/pkg/plugins"
"github.com/docker/libnetwork/discoverapi"
"github.com/docker/libnetwork/ipamapi"
"github.com/docker/libnetwork/ipams/remote/api"
"github.com/docker/libnetwork/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -52,13 +54,39 @@ func Init(cb ipamapi.Callback, l, g interface{}) error {
handleFunc = pg.Handle
activePlugins := pg.GetAllManagedPluginsByCap(ipamapi.PluginEndpointType)
for _, ap := range activePlugins {
newPluginHandler(ap.Name(), ap.Client())
client, err := getPluginClient(ap)
if err != nil {
return err
}
newPluginHandler(ap.Name(), client)
}
}
handleFunc(ipamapi.PluginEndpointType, newPluginHandler)
return nil
}

func getPluginClient(p plugingetter.CompatPlugin) (*plugins.Client, error) {
if v1, ok := p.(plugingetter.PluginWithV1Client); ok {
return v1.Client(), nil
}

pa, ok := p.(plugingetter.PluginAddr)
if !ok {
return nil, errors.Errorf("unknown plugin type %T", p)
}

if pa.Protocol() != plugins.ProtocolSchemeHTTPV1 {
return nil, errors.Errorf("unsupported plugin protocol %s", pa.Protocol())
}

addr := pa.Addr()
client, err := plugins.NewClientWithTimeout(addr.Network()+"://"+addr.String(), nil, pa.Timeout())
if err != nil {
return nil, errors.Wrap(err, "error creating plugin client")
}
return client, nil
}

func (a *allocator) call(methodName string, arg interface{}, retVal PluginResponse) error {
method := ipamapi.PluginEndpointType + "." + methodName
err := a.endpoint.Call(method, arg, retVal)
Expand Down
25 changes: 21 additions & 4 deletions ipams/remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func TestGetCapabilities(t *testing.T) {
t.Fatal(err)
}

d := newAllocator(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newAllocator(plugin, client)

caps, err := d.(*allocator).getCapabilities()
if err != nil {
Expand All @@ -102,7 +106,12 @@ func TestGetCapabilitiesFromLegacyDriver(t *testing.T) {
t.Fatal(err)
}

d := newAllocator(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}

d := newAllocator(plugin, client)

if _, err := d.(*allocator).getCapabilities(); err == nil {
t.Fatalf("Expected error, but got Success %v", err)
Expand All @@ -127,7 +136,11 @@ func TestGetDefaultAddressSpaces(t *testing.T) {
t.Fatal(err)
}

d := newAllocator(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newAllocator(plugin, client)

l, g, err := d.(*allocator).GetDefaultAddressSpaces()
if err != nil {
Expand Down Expand Up @@ -217,7 +230,11 @@ func TestRemoteDriver(t *testing.T) {
t.Fatal(err)
}

d := newAllocator(plugin, p.Client())
client, err := getPluginClient(p)
if err != nil {
t.Fatal(err)
}
d := newAllocator(plugin, client)

l, g, err := d.(*allocator).GetDefaultAddressSpaces()
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions libnetwork_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/docker/libnetwork/osl"
"github.com/docker/libnetwork/testutils"
"github.com/docker/libnetwork/types"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"github.com/vishvananda/netns"
Expand Down Expand Up @@ -521,14 +519,17 @@ func externalKeyTest(t *testing.T, reexec bool) {
}

func reexecSetKey(key string, containerID string, controllerID string) error {
type libcontainerState struct {
NamespacePaths map[string]string
}
var (
state libcontainer.State
state libcontainerState
b []byte
err error
)

state.NamespacePaths = make(map[configs.NamespaceType]string)
state.NamespacePaths[configs.NamespaceType("NEWNET")] = key
state.NamespacePaths = make(map[string]string)
state.NamespacePaths["NEWNET"] = key
if b, err = json.Marshal(state); err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions libnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"testing"

"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/plugins"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/libnetwork"
Expand Down Expand Up @@ -209,7 +210,7 @@ func TestUnknownDriver(t *testing.T) {
t.Fatal("Expected to fail. But instead succeeded")
}

if _, ok := err.(types.NotFoundError); !ok {
if !errdefs.IsNotFound(err) {
t.Fatalf("Did not fail with expected error. Actual error: %v", err)
}
}
Expand All @@ -221,7 +222,7 @@ func TestNilRemoteDriver(t *testing.T) {
t.Fatal("Expected to fail. But instead succeeded")
}

if _, ok := err.(types.NotFoundError); !ok {
if !errdefs.IsNotFound(err) {
t.Fatalf("Did not fail with expected error. Actual error: %v", err)
}
}
Expand Down Expand Up @@ -1396,7 +1397,7 @@ func TestValidRemoteDriver(t *testing.T) {
libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
if err != nil {
// Only fail if we could not find the plugin driver
if _, ok := err.(types.NotFoundError); ok {
if errdefs.IsNotFound(err) {
t.Fatal(err)
}
return
Expand Down
4 changes: 2 additions & 2 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/coreos/go-semver v0.2.0
github.com/coreos/go-systemd v4
github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d

github.com/docker/docker a3efe9722f34af5cf4443fe3a5c4e4e3e0457b54
github.com/docker/docker 71cd53e4a197b303c6ba086bd584ffd67a884281
github.com/docker/go-connections 3ede32e2033de7505e6500d6c868c2b9ed9f169d
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1
Expand Down Expand Up @@ -49,7 +49,7 @@ github.com/vishvananda/netlink b2de5d10e38ecce8607e6b438b6d174f389a004e
github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
golang.org/x/crypto 558b6879de74bc843225cde5686419267ff707ca
golang.org/x/net b3756b4b77d7b13260a0a2ec658753cf48922eac
golang.org/x/sys 07c182904dbd53199946ba614a412c61d3c548f5
golang.org/x/sys 37707fdb30a5b38865cfb95e5aab41707daec7f5
golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5
github.com/pkg/errors 839d9e913e063e28dfd0e6c7b7512793e0a48be9
github.com/ishidawataru/sctp 07191f837fedd2f13d1ec7b5f885f0f3ec54b1cb
Loading