mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Moby imports Swarmkit; Swarmkit no longer imports Moby. In order to accomplish this feat, Swarmkit has introduced a new plugin.Getter interface so it could stop importing our pkg/plugingetter package. This new interface is not entirely compatible with our plugingetter.PluginGetter interface, necessitating a thin adapter. Swarmkit had to jettison the CNM network allocator to stop having to import libnetwork as the cnmallocator package is deeply tied to libnetwork. Move the CNM network allocator into libnetwork, where it belongs. The package had a short an uninteresting Git history in the Swarmkit repository so no effort was made to retain history. Signed-off-by: Cory Snider <csnider@mirantis.com> (cherry-picked from commit7b0ab1011c) d/cluster/convert: expose Addr() on plugins The swarmPlugin type does not implement the Swarm plugin.AddrPlugin interface because it embeds an interface value which does not include that method in its method set. (You can type-assert an interface value to another interface which the concrete type implements, but a struct embedding an interface value is not itself an interface value.) Wrap the plugin with a different adapter type which exposes the Addr() method if the concrete plugin implements it. Signed-off-by: Cory Snider <csnider@mirantis.com> (cherry picked from commit8b6d6b9ad5) libnetwork/cnmallocator: fix non-constant format string in call (govet) libnetwork/cnmallocator/drivers_ipam.go:43:31: printf: non-constant format string in call to (*github.com/docker/docker/vendor/github.com/sirupsen/logrus.Entry).Infof (govet) log.G(context.TODO()).Infof("Swarm initialized global default address pool to: " + str.String()) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit7b60a7047d) Signed-off-by: Cory Snider <csnider@mirantis.com>
92 lines
2.7 KiB
Go
92 lines
2.7 KiB
Go
package cnmallocator
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/docker/docker/libnetwork/driverapi"
|
|
"github.com/docker/docker/libnetwork/drivers/overlay/overlayutils"
|
|
"github.com/docker/docker/libnetwork/ipamapi"
|
|
"github.com/docker/docker/pkg/plugingetter"
|
|
"github.com/moby/swarmkit/v2/api"
|
|
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type Provider struct {
|
|
pg plugingetter.PluginGetter
|
|
}
|
|
|
|
var _ networkallocator.Provider = &Provider{}
|
|
|
|
// NewProvider returns a new cnmallocator provider.
|
|
func NewProvider(pg plugingetter.PluginGetter) *Provider {
|
|
return &Provider{pg: pg}
|
|
}
|
|
|
|
// ValidateIPAMDriver implements networkallocator.NetworkProvider.
|
|
func (p *Provider) ValidateIPAMDriver(driver *api.Driver) error {
|
|
if driver == nil {
|
|
// It is ok to not specify the driver. We will choose
|
|
// a default driver.
|
|
return nil
|
|
}
|
|
|
|
if driver.Name == "" {
|
|
return status.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
|
|
}
|
|
if strings.ToLower(driver.Name) == ipamapi.DefaultIPAM {
|
|
return nil
|
|
}
|
|
return p.validatePluginDriver(driver, ipamapi.PluginEndpointType)
|
|
}
|
|
|
|
// ValidateIngressNetworkDriver implements networkallocator.NetworkProvider.
|
|
func (p *Provider) ValidateIngressNetworkDriver(driver *api.Driver) error {
|
|
if driver != nil && driver.Name != "overlay" {
|
|
return status.Errorf(codes.Unimplemented, "only overlay driver is currently supported for ingress network")
|
|
}
|
|
return p.ValidateNetworkDriver(driver)
|
|
}
|
|
|
|
// ValidateNetworkDriver implements networkallocator.NetworkProvider.
|
|
func (p *Provider) ValidateNetworkDriver(driver *api.Driver) error {
|
|
if driver == nil {
|
|
// It is ok to not specify the driver. We will choose
|
|
// a default driver.
|
|
return nil
|
|
}
|
|
|
|
if driver.Name == "" {
|
|
return status.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
|
|
}
|
|
|
|
// First check against the known drivers
|
|
if IsBuiltInDriver(driver.Name) {
|
|
return nil
|
|
}
|
|
|
|
return p.validatePluginDriver(driver, driverapi.NetworkPluginEndpointType)
|
|
}
|
|
|
|
func (p *Provider) validatePluginDriver(driver *api.Driver, pluginType string) error {
|
|
if p.pg == nil {
|
|
return status.Errorf(codes.InvalidArgument, "plugin %s not supported", driver.Name)
|
|
}
|
|
|
|
plug, err := p.pg.Get(driver.Name, pluginType, plugingetter.Lookup)
|
|
if err != nil {
|
|
return status.Errorf(codes.InvalidArgument, "error during lookup of plugin %s", driver.Name)
|
|
}
|
|
|
|
if plug.IsV1() {
|
|
return status.Errorf(codes.InvalidArgument, "legacy plugin %s of type %s is not supported in swarm mode", driver.Name, pluginType)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *Provider) SetDefaultVXLANUDPPort(port uint32) error {
|
|
return overlayutils.ConfigVXLANUDPPort(port)
|
|
}
|