Merge pull request #26347 from anusha-ragunathan/plugins-libnetwork
Adding pluginv2 support for libnetwork.
This commit is contained in:
commit
cb6ea5b4f5
|
@ -623,11 +623,12 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.restore(); err != nil {
|
// Plugin system initialization should happen before restore. Dont change order.
|
||||||
|
if err := pluginInit(d, config, containerdRemote); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pluginInit(d, config, containerdRemote); err != nil {
|
if err := d.restore(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,13 @@ package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/libcontainerd"
|
"github.com/docker/docker/libcontainerd"
|
||||||
"github.com/docker/docker/pkg/plugins"
|
|
||||||
"github.com/docker/docker/plugin/store"
|
"github.com/docker/docker/plugin/store"
|
||||||
"github.com/docker/docker/plugin/v2"
|
"github.com/docker/docker/plugin/v2"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
|
@ -21,12 +18,6 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
manager *Manager
|
manager *Manager
|
||||||
|
|
||||||
/* allowV1PluginsFallback determines daemon's support for V1 plugins.
|
|
||||||
* When the time comes to remove support for V1 plugins, flipping
|
|
||||||
* this bool is all that will be needed.
|
|
||||||
*/
|
|
||||||
allowV1PluginsFallback = true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pm *Manager) restorePlugin(p *v2.Plugin) error {
|
func (pm *Manager) restorePlugin(p *v2.Plugin) error {
|
||||||
|
@ -45,7 +36,6 @@ type Manager struct {
|
||||||
libRoot string
|
libRoot string
|
||||||
runRoot string
|
runRoot string
|
||||||
pluginStore *store.PluginStore
|
pluginStore *store.PluginStore
|
||||||
handlers map[string]func(string, *plugins.Client)
|
|
||||||
containerdClient libcontainerd.Client
|
containerdClient libcontainerd.Client
|
||||||
registryService registry.Service
|
registryService registry.Service
|
||||||
liveRestore bool
|
liveRestore bool
|
||||||
|
@ -70,7 +60,6 @@ func Init(root string, remote libcontainerd.Remote, rs registry.Service, liveRes
|
||||||
libRoot: root,
|
libRoot: root,
|
||||||
runRoot: "/run/docker",
|
runRoot: "/run/docker",
|
||||||
pluginStore: store.NewPluginStore(root),
|
pluginStore: store.NewPluginStore(root),
|
||||||
handlers: make(map[string]func(string, *plugins.Client)),
|
|
||||||
registryService: rs,
|
registryService: rs,
|
||||||
liveRestore: liveRestore,
|
liveRestore: liveRestore,
|
||||||
pluginEventLogger: evL,
|
pluginEventLogger: evL,
|
||||||
|
@ -88,16 +77,6 @@ func Init(root string, remote libcontainerd.Remote, rs registry.Service, liveRes
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle sets a callback for a given capability. The callback will be called for every plugin with a given capability.
|
|
||||||
// TODO: append instead of set?
|
|
||||||
func Handle(capability string, callback func(string, *plugins.Client)) {
|
|
||||||
pluginType := fmt.Sprintf("docker.%s/1", strings.ToLower(capability))
|
|
||||||
manager.handlers[pluginType] = callback
|
|
||||||
if allowV1PluginsFallback {
|
|
||||||
plugins.Handle(capability, callback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// StateChanged updates plugin internals using libcontainerd events.
|
// StateChanged updates plugin internals using libcontainerd events.
|
||||||
func (pm *Manager) StateChanged(id string, e libcontainerd.StateInfo) error {
|
func (pm *Manager) StateChanged(id string, e libcontainerd.StateInfo) error {
|
||||||
logrus.Debugf("plugin state changed %s %#v", id, e)
|
logrus.Debugf("plugin state changed %s %#v", id, e)
|
||||||
|
|
|
@ -43,11 +43,7 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
pm.pluginStore.SetState(p, true)
|
pm.pluginStore.SetState(p, true)
|
||||||
for _, typ := range p.GetTypes() {
|
pm.pluginStore.CallHandler(p)
|
||||||
if handler := pm.handlers[typ.String()]; handler != nil {
|
|
||||||
handler(p.Name(), p.Client())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
@ -32,7 +33,11 @@ func (name ErrNotFound) Error() string { return fmt.Sprintf("plugin %q not found
|
||||||
// PluginStore manages the plugin inventory in memory and on-disk
|
// PluginStore manages the plugin inventory in memory and on-disk
|
||||||
type PluginStore struct {
|
type PluginStore struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
plugins map[string]*v2.Plugin
|
plugins map[string]*v2.Plugin
|
||||||
|
/* handlers are necessary for transition path of legacy plugins
|
||||||
|
* to the new model. Legacy plugins use Handle() for registering an
|
||||||
|
* activation callback.*/
|
||||||
|
handlers map[string]func(string, *plugins.Client)
|
||||||
nameToID map[string]string
|
nameToID map[string]string
|
||||||
plugindb string
|
plugindb string
|
||||||
}
|
}
|
||||||
|
@ -41,6 +46,7 @@ type PluginStore struct {
|
||||||
func NewPluginStore(libRoot string) *PluginStore {
|
func NewPluginStore(libRoot string) *PluginStore {
|
||||||
store = &PluginStore{
|
store = &PluginStore{
|
||||||
plugins: make(map[string]*v2.Plugin),
|
plugins: make(map[string]*v2.Plugin),
|
||||||
|
handlers: make(map[string]func(string, *plugins.Client)),
|
||||||
nameToID: make(map[string]string),
|
nameToID: make(map[string]string),
|
||||||
plugindb: filepath.Join(libRoot, "plugins.json"),
|
plugindb: filepath.Join(libRoot, "plugins.json"),
|
||||||
}
|
}
|
||||||
|
@ -222,3 +228,27 @@ func FindWithCapability(capability string) ([]CompatPlugin, error) {
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle sets a callback for a given capability. It is only used by network
|
||||||
|
// and ipam drivers during plugin registration. The callback registers the
|
||||||
|
// driver with the subsystem (network, ipam).
|
||||||
|
func Handle(capability string, callback func(string, *plugins.Client)) {
|
||||||
|
pluginType := fmt.Sprintf("docker.%s/1", strings.ToLower(capability))
|
||||||
|
|
||||||
|
// Register callback with new plugin model.
|
||||||
|
store.handlers[pluginType] = callback
|
||||||
|
|
||||||
|
// Register callback with legacy plugin model.
|
||||||
|
if allowV1PluginsFallback {
|
||||||
|
plugins.Handle(capability, callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallHandler calls the registered callback. It is invoked during plugin enable.
|
||||||
|
func (ps *PluginStore) CallHandler(p *v2.Plugin) {
|
||||||
|
for _, typ := range p.GetTypes() {
|
||||||
|
if handler := ps.handlers[typ.String()]; handler != nil {
|
||||||
|
handler(p.Name(), p.Client())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue