Bläddra i källkod

Merge pull request #30332 from anusha-ragunathan/1.13.x

Cherry pick docker #30145 and vendor corresponding swarmkit #1883
Victor Vieux 8 år sedan
förälder
incheckning
0b27583f82

+ 1 - 0
daemon/cluster/cluster.go

@@ -332,6 +332,7 @@ func (c *Cluster) startNewNode(conf nodeStartConfig) (*node, error) {
 		ElectionTick:       3,
 		ElectionTick:       3,
 		UnlockKey:          conf.lockKey,
 		UnlockKey:          conf.lockKey,
 		AutoLockManagers:   conf.autolock,
 		AutoLockManagers:   conf.autolock,
+		PluginGetter:       c.config.Backend.PluginGetter(),
 	})
 	})
 
 
 	if err != nil {
 	if err != nil {

+ 1 - 0
daemon/cluster/executor/backend.go

@@ -56,4 +56,5 @@ type Backend interface {
 	GetRepository(context.Context, reference.NamedTagged, *types.AuthConfig) (distribution.Repository, bool, error)
 	GetRepository(context.Context, reference.NamedTagged, *types.AuthConfig) (distribution.Repository, bool, error)
 	LookupImage(name string) (*types.ImageInspect, error)
 	LookupImage(name string) (*types.ImageInspect, error)
 	PluginManager() *plugin.Manager
 	PluginManager() *plugin.Manager
+	PluginGetter() *plugin.Store
 }
 }

+ 5 - 0
daemon/daemon.go

@@ -1272,6 +1272,11 @@ func (daemon *Daemon) PluginManager() *plugin.Manager { // set up before daemon
 	return daemon.pluginManager
 	return daemon.pluginManager
 }
 }
 
 
+// PluginGetter returns current pluginStore associated with the daemon
+func (daemon *Daemon) PluginGetter() *plugin.Store {
+	return daemon.PluginStore
+}
+
 // CreateDaemonRoot creates the root for the daemon
 // CreateDaemonRoot creates the root for the daemon
 func CreateDaemonRoot(config *Config) error {
 func CreateDaemonRoot(config *Config) error {
 	// get the canonical path to the Docker root directory
 	// get the canonical path to the Docker root directory

+ 2 - 1
integration-cli/docker_cli_swarm_test.go

@@ -677,8 +677,9 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPlugin(c *check.C) {
 
 
 	d := s.AddDaemon(c, true, true)
 	d := s.AddDaemon(c, true, true)
 
 
-	_, err := d.Cmd("network", "create", "-d", globalNetworkPlugin, "foo")
+	out, err := d.Cmd("network", "create", "-d", globalNetworkPlugin, "foo")
 	c.Assert(err, checker.NotNil)
 	c.Assert(err, checker.NotNil)
+	c.Assert(out, checker.Contains, "not supported in swarm mode")
 }
 }
 
 
 // Test case for #24712
 // Test case for #24712

+ 1 - 1
vendor.conf

@@ -100,7 +100,7 @@ github.com/docker/containerd 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
 github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4
 github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4
 
 
 # cluster
 # cluster
-github.com/docker/swarmkit 296fcfcf1e86a26a3f52aa84d638fbf80f9a8443
+github.com/docker/swarmkit 335561b66a44bf214224afe879e4368204e7fa45
 github.com/golang/mock bd3c8e81be01eef76d4b503f5e687d2d1354d2d9
 github.com/golang/mock bd3c8e81be01eef76d4b503f5e687d2d1354d2d9
 github.com/gogo/protobuf v0.3
 github.com/gogo/protobuf v0.3
 github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a
 github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a

+ 8 - 3
vendor/github.com/docker/swarmkit/manager/allocator/allocator.go

@@ -3,6 +3,7 @@ package allocator
 import (
 import (
 	"sync"
 	"sync"
 
 
+	"github.com/docker/docker/pkg/plugingetter"
 	"github.com/docker/go-events"
 	"github.com/docker/go-events"
 	"github.com/docker/swarmkit/manager/state"
 	"github.com/docker/swarmkit/manager/state"
 	"github.com/docker/swarmkit/manager/state/store"
 	"github.com/docker/swarmkit/manager/state/store"
@@ -27,6 +28,9 @@ type Allocator struct {
 	stopChan chan struct{}
 	stopChan chan struct{}
 	// doneChan is closed when the allocator is finished running.
 	// doneChan is closed when the allocator is finished running.
 	doneChan chan struct{}
 	doneChan chan struct{}
+
+	// pluginGetter provides access to docker's plugin inventory.
+	pluginGetter plugingetter.PluginGetter
 }
 }
 
 
 // taskBallot controls how the voting for task allocation is
 // taskBallot controls how the voting for task allocation is
@@ -67,14 +71,15 @@ type allocActor struct {
 
 
 // New returns a new instance of Allocator for use during allocation
 // New returns a new instance of Allocator for use during allocation
 // stage of the manager.
 // stage of the manager.
-func New(store *store.MemoryStore) (*Allocator, error) {
+func New(store *store.MemoryStore, pg plugingetter.PluginGetter) (*Allocator, error) {
 	a := &Allocator{
 	a := &Allocator{
 		store: store,
 		store: store,
 		taskBallot: &taskBallot{
 		taskBallot: &taskBallot{
 			votes: make(map[string][]string),
 			votes: make(map[string][]string),
 		},
 		},
-		stopChan: make(chan struct{}),
-		doneChan: make(chan struct{}),
+		stopChan:     make(chan struct{}),
+		doneChan:     make(chan struct{}),
+		pluginGetter: pg,
 	}
 	}
 
 
 	return a, nil
 	return a, nil

+ 1 - 1
vendor/github.com/docker/swarmkit/manager/allocator/network.go

@@ -73,7 +73,7 @@ type networkContext struct {
 }
 }
 
 
 func (a *Allocator) doNetworkInit(ctx context.Context) (err error) {
 func (a *Allocator) doNetworkInit(ctx context.Context) (err error) {
-	na, err := networkallocator.New()
+	na, err := networkallocator.New(a.pluginGetter)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 8 - 4
vendor/github.com/docker/swarmkit/manager/allocator/networkallocator/networkallocator.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"fmt"
 	"net"
 	"net"
 
 
-	"github.com/docker/docker/pkg/plugins"
+	"github.com/docker/docker/pkg/plugingetter"
 	"github.com/docker/libnetwork/datastore"
 	"github.com/docker/libnetwork/datastore"
 	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/drvregistry"
 	"github.com/docker/libnetwork/drvregistry"
@@ -69,7 +69,7 @@ type initializer struct {
 }
 }
 
 
 // New returns a new NetworkAllocator handle
 // New returns a new NetworkAllocator handle
-func New() (*NetworkAllocator, error) {
+func New(pg plugingetter.PluginGetter) (*NetworkAllocator, error) {
 	na := &NetworkAllocator{
 	na := &NetworkAllocator{
 		networks: make(map[string]*network),
 		networks: make(map[string]*network),
 		services: make(map[string]struct{}),
 		services: make(map[string]struct{}),
@@ -79,7 +79,7 @@ func New() (*NetworkAllocator, error) {
 
 
 	// There are no driver configurations and notification
 	// There are no driver configurations and notification
 	// functions as of now.
 	// functions as of now.
-	reg, err := drvregistry.New(nil, nil, nil, nil, nil)
+	reg, err := drvregistry.New(nil, nil, nil, nil, pg)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -657,7 +657,11 @@ func (na *NetworkAllocator) resolveDriver(n *api.Network) (driverapi.Driver, str
 }
 }
 
 
 func (na *NetworkAllocator) loadDriver(name string) error {
 func (na *NetworkAllocator) loadDriver(name string) error {
-	_, err := plugins.Get(name, driverapi.NetworkPluginEndpointType)
+	pg := na.drvRegistry.GetPluginGetter()
+	if pg == nil {
+		return fmt.Errorf("plugin store is unintialized")
+	}
+	_, err := pg.Get(name, driverapi.NetworkPluginEndpointType, plugingetter.LOOKUP)
 	return err
 	return err
 }
 }
 
 

+ 16 - 3
vendor/github.com/docker/swarmkit/manager/controlapi/common.go

@@ -4,7 +4,10 @@ import (
 	"regexp"
 	"regexp"
 	"strings"
 	"strings"
 
 
+	"github.com/docker/docker/pkg/plugingetter"
+	"github.com/docker/libnetwork/ipamapi"
 	"github.com/docker/swarmkit/api"
 	"github.com/docker/swarmkit/api"
+	"github.com/docker/swarmkit/manager/allocator/networkallocator"
 	"github.com/docker/swarmkit/manager/state/store"
 	"github.com/docker/swarmkit/manager/state/store"
 	"google.golang.org/grpc"
 	"google.golang.org/grpc"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/codes"
@@ -76,7 +79,7 @@ func validateAnnotations(m api.Annotations) error {
 	return nil
 	return nil
 }
 }
 
 
-func validateDriver(driver *api.Driver, defName string) error {
+func validateDriver(driver *api.Driver, pg plugingetter.PluginGetter, pluginType string) error {
 	if driver == nil {
 	if driver == nil {
 		// It is ok to not specify the driver. We will choose
 		// It is ok to not specify the driver. We will choose
 		// a default driver.
 		// a default driver.
@@ -87,8 +90,18 @@ func validateDriver(driver *api.Driver, defName string) error {
 		return grpc.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
 		return grpc.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
 	}
 	}
 
 
-	if driver.Name != defName {
-		return grpc.Errorf(codes.InvalidArgument, "invalid driver (%s) specified", driver.Name)
+	if strings.ToLower(driver.Name) == networkallocator.DefaultDriver || strings.ToLower(driver.Name) == ipamapi.DefaultIPAM {
+		return nil
+	}
+
+	p, err := pg.Get(driver.Name, pluginType, plugingetter.LOOKUP)
+	if err != nil {
+		return grpc.Errorf(codes.InvalidArgument, "error during lookup of plugin %s", driver.Name)
 	}
 	}
+
+	if p.IsV1() {
+		return grpc.Errorf(codes.InvalidArgument, "legacy plugin %s of type %s is not supported in swarm mode", driver.Name, pluginType)
+	}
+
 	return nil
 	return nil
 }
 }

+ 8 - 7
vendor/github.com/docker/swarmkit/manager/controlapi/network.go

@@ -4,10 +4,11 @@ import (
 	"fmt"
 	"fmt"
 	"net"
 	"net"
 
 
+	"github.com/docker/docker/pkg/plugingetter"
+	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/ipamapi"
 	"github.com/docker/libnetwork/ipamapi"
 	"github.com/docker/swarmkit/api"
 	"github.com/docker/swarmkit/api"
 	"github.com/docker/swarmkit/identity"
 	"github.com/docker/swarmkit/identity"
-	"github.com/docker/swarmkit/manager/allocator/networkallocator"
 	"github.com/docker/swarmkit/manager/state/store"
 	"github.com/docker/swarmkit/manager/state/store"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 	"google.golang.org/grpc"
 	"google.golang.org/grpc"
@@ -49,14 +50,14 @@ func validateIPAMConfiguration(ipamConf *api.IPAMConfig) error {
 	return nil
 	return nil
 }
 }
 
 
-func validateIPAM(ipam *api.IPAMOptions) error {
+func validateIPAM(ipam *api.IPAMOptions, pg plugingetter.PluginGetter) error {
 	if ipam == nil {
 	if ipam == nil {
 		// It is ok to not specify any IPAM configurations. We
 		// It is ok to not specify any IPAM configurations. We
 		// will choose good defaults.
 		// will choose good defaults.
 		return nil
 		return nil
 	}
 	}
 
 
-	if err := validateDriver(ipam.Driver, ipamapi.DefaultIPAM); err != nil {
+	if err := validateDriver(ipam.Driver, pg, ipamapi.PluginEndpointType); err != nil {
 		return err
 		return err
 	}
 	}
 
 
@@ -69,7 +70,7 @@ func validateIPAM(ipam *api.IPAMOptions) error {
 	return nil
 	return nil
 }
 }
 
 
-func validateNetworkSpec(spec *api.NetworkSpec) error {
+func validateNetworkSpec(spec *api.NetworkSpec, pg plugingetter.PluginGetter) error {
 	if spec == nil {
 	if spec == nil {
 		return grpc.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
 		return grpc.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
 	}
 	}
@@ -78,11 +79,11 @@ func validateNetworkSpec(spec *api.NetworkSpec) error {
 		return err
 		return err
 	}
 	}
 
 
-	if err := validateDriver(spec.DriverConfig, networkallocator.DefaultDriver); err != nil {
+	if err := validateDriver(spec.DriverConfig, pg, driverapi.NetworkPluginEndpointType); err != nil {
 		return err
 		return err
 	}
 	}
 
 
-	if err := validateIPAM(spec.IPAM); err != nil {
+	if err := validateIPAM(spec.IPAM, pg); err != nil {
 		return err
 		return err
 	}
 	}
 
 
@@ -95,7 +96,7 @@ func validateNetworkSpec(spec *api.NetworkSpec) error {
 func (s *Server) CreateNetwork(ctx context.Context, request *api.CreateNetworkRequest) (*api.CreateNetworkResponse, error) {
 func (s *Server) CreateNetwork(ctx context.Context, request *api.CreateNetworkRequest) (*api.CreateNetworkResponse, error) {
 	// if you change this function, you have to change createInternalNetwork in
 	// if you change this function, you have to change createInternalNetwork in
 	// the tests to match it (except the part where we check the label).
 	// the tests to match it (except the part where we check the label).
-	if err := validateNetworkSpec(request.Spec); err != nil {
+	if err := validateNetworkSpec(request.Spec, s.pg); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 
 

+ 4 - 1
vendor/github.com/docker/swarmkit/manager/controlapi/server.go

@@ -3,6 +3,7 @@ package controlapi
 import (
 import (
 	"errors"
 	"errors"
 
 
+	"github.com/docker/docker/pkg/plugingetter"
 	"github.com/docker/swarmkit/ca"
 	"github.com/docker/swarmkit/ca"
 	"github.com/docker/swarmkit/manager/state/raft"
 	"github.com/docker/swarmkit/manager/state/raft"
 	"github.com/docker/swarmkit/manager/state/store"
 	"github.com/docker/swarmkit/manager/state/store"
@@ -18,13 +19,15 @@ type Server struct {
 	store  *store.MemoryStore
 	store  *store.MemoryStore
 	raft   *raft.Node
 	raft   *raft.Node
 	rootCA *ca.RootCA
 	rootCA *ca.RootCA
+	pg     plugingetter.PluginGetter
 }
 }
 
 
 // NewServer creates a Cluster API server.
 // NewServer creates a Cluster API server.
-func NewServer(store *store.MemoryStore, raft *raft.Node, rootCA *ca.RootCA) *Server {
+func NewServer(store *store.MemoryStore, raft *raft.Node, rootCA *ca.RootCA, pg plugingetter.PluginGetter) *Server {
 	return &Server{
 	return &Server{
 		store:  store,
 		store:  store,
 		raft:   raft,
 		raft:   raft,
 		rootCA: rootCA,
 		rootCA: rootCA,
+		pg:     pg,
 	}
 	}
 }
 }

+ 6 - 2
vendor/github.com/docker/swarmkit/manager/manager.go

@@ -13,6 +13,7 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
+	"github.com/docker/docker/pkg/plugingetter"
 	"github.com/docker/go-events"
 	"github.com/docker/go-events"
 	"github.com/docker/swarmkit/api"
 	"github.com/docker/swarmkit/api"
 	"github.com/docker/swarmkit/ca"
 	"github.com/docker/swarmkit/ca"
@@ -99,6 +100,9 @@ type Config struct {
 	// bootstrapping a cluster for the first time (it's a cluster-wide setting),
 	// bootstrapping a cluster for the first time (it's a cluster-wide setting),
 	// and also when loading up any raft data on disk (as a KEK for the raft DEK).
 	// and also when loading up any raft data on disk (as a KEK for the raft DEK).
 	UnlockKey []byte
 	UnlockKey []byte
+
+	// PluginGetter provides access to docker's plugin inventory.
+	PluginGetter plugingetter.PluginGetter
 }
 }
 
 
 // Manager is the cluster manager for Swarm.
 // Manager is the cluster manager for Swarm.
@@ -309,7 +313,7 @@ func (m *Manager) Run(parent context.Context) error {
 		return err
 		return err
 	}
 	}
 
 
-	baseControlAPI := controlapi.NewServer(m.raftNode.MemoryStore(), m.raftNode, m.config.SecurityConfig.RootCA())
+	baseControlAPI := controlapi.NewServer(m.raftNode.MemoryStore(), m.raftNode, m.config.SecurityConfig.RootCA(), m.config.PluginGetter)
 	baseResourceAPI := resourceapi.New(m.raftNode.MemoryStore())
 	baseResourceAPI := resourceapi.New(m.raftNode.MemoryStore())
 	healthServer := health.NewHealthServer()
 	healthServer := health.NewHealthServer()
 	localHealthServer := health.NewHealthServer()
 	localHealthServer := health.NewHealthServer()
@@ -780,7 +784,7 @@ func (m *Manager) becomeLeader(ctx context.Context) {
 	// shutdown underlying manager processes when leadership is
 	// shutdown underlying manager processes when leadership is
 	// lost.
 	// lost.
 
 
-	m.allocator, err = allocator.New(s)
+	m.allocator, err = allocator.New(s, m.config.PluginGetter)
 	if err != nil {
 	if err != nil {
 		log.G(ctx).WithError(err).Error("failed to create allocator")
 		log.G(ctx).WithError(err).Error("failed to create allocator")
 		// TODO(stevvooe): It doesn't seem correct here to fail
 		// TODO(stevvooe): It doesn't seem correct here to fail

+ 5 - 0
vendor/github.com/docker/swarmkit/node/node.go

@@ -14,6 +14,7 @@ import (
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
 	"github.com/boltdb/bolt"
 	"github.com/boltdb/bolt"
+	"github.com/docker/docker/pkg/plugingetter"
 	"github.com/docker/swarmkit/agent"
 	"github.com/docker/swarmkit/agent"
 	"github.com/docker/swarmkit/agent/exec"
 	"github.com/docker/swarmkit/agent/exec"
 	"github.com/docker/swarmkit/api"
 	"github.com/docker/swarmkit/api"
@@ -95,6 +96,9 @@ type Config struct {
 	// UnlockKey is the key to unlock a node - used for decrypting at rest.  This
 	// UnlockKey is the key to unlock a node - used for decrypting at rest.  This
 	// only applies to nodes that have already joined a cluster.
 	// only applies to nodes that have already joined a cluster.
 	UnlockKey []byte
 	UnlockKey []byte
+
+	// PluginGetter provides access to docker's plugin inventory.
+	PluginGetter plugingetter.PluginGetter
 }
 }
 
 
 // Node implements the primary node functionality for a member of a swarm
 // Node implements the primary node functionality for a member of a swarm
@@ -681,6 +685,7 @@ func (n *Node) runManager(ctx context.Context, securityConfig *ca.SecurityConfig
 			ElectionTick:     n.config.ElectionTick,
 			ElectionTick:     n.config.ElectionTick,
 			AutoLockManagers: n.config.AutoLockManagers,
 			AutoLockManagers: n.config.AutoLockManagers,
 			UnlockKey:        n.unlockKey,
 			UnlockKey:        n.unlockKey,
+			PluginGetter:     n.config.PluginGetter,
 		})
 		})
 		if err != nil {
 		if err != nil {
 			return err
 			return err