Update plugin load and snapshot service

Allow plugins to be mapped and returned by their ID.
Add skip plugin to allow plugins to decide whether they should
be loaded.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-06-27 16:55:50 -07:00
parent 5b105f86ce
commit 3db8adc5d7
11 changed files with 82 additions and 47 deletions

View File

@@ -0,0 +1,5 @@
package snapshot
const (
defaultSnapshotter = "overlayfs"
)

View File

@@ -0,0 +1,7 @@
// +build darwin freebsd
package snapshot
const (
defaultSnapshotter = "naive"
)

View File

@@ -0,0 +1,5 @@
package snapshot
const (
defaultSnapshotter = "windows"
)

View File

@@ -3,36 +3,40 @@ package snapshot
import (
gocontext "context"
"github.com/boltdb/bolt"
eventsapi "github.com/containerd/containerd/api/services/events/v1"
snapshotapi "github.com/containerd/containerd/api/services/snapshot/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/metadata"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/namespaced"
protoempty "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
type config struct {
// Default is the default snapshotter to use for the service
Default string `toml:"default,omitempty"`
}
func init() {
plugin.Register(&plugin.Registration{
Type: plugin.GRPCPlugin,
ID: "snapshots",
Requires: []plugin.PluginType{
plugin.SnapshotPlugin,
plugin.MetadataPlugin,
},
Init: func(ic *plugin.InitContext) (interface{}, error) {
e := events.GetPoster(ic.Context)
s, err := ic.Get(plugin.SnapshotPlugin)
if err != nil {
return nil, err
}
return newService(s.(snapshot.Snapshotter), e)
Config: &config{
Default: defaultSnapshotter,
},
Init: newService,
})
}
@@ -43,9 +47,26 @@ type service struct {
emitter events.Poster
}
func newService(snapshotter snapshot.Snapshotter, evts events.Poster) (*service, error) {
func newService(ic *plugin.InitContext) (interface{}, error) {
evts := events.GetPoster(ic.Context)
snapshotters, err := ic.GetAll(plugin.SnapshotPlugin)
if err != nil {
return nil, err
}
cfg := ic.Config.(*config)
sn, ok := snapshotters[cfg.Default]
if !ok {
return nil, errors.Errorf("default snapshotter not loaded: %s", cfg.Default)
}
md, err := ic.Get(plugin.MetadataPlugin)
if err != nil {
return nil, err
}
return &service{
snapshotter: namespaced.NewSnapshotter(snapshotter),
snapshotter: metadata.NewSnapshotter(md.(*bolt.DB), cfg.Default, sn.(snapshot.Snapshotter)),
emitter: evts,
}, nil
}