Update metadata plugin initialization
Updates metadata plugin to require content and snapshotter plugins be loaded and initializes with those plugins, keeping the metadata database structure static after initialization. Service plugins now only require metadata plugin access snapshotter or content stores through metadata, which was already required behavior of the services. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -39,7 +39,6 @@ func init() {
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "content",
|
||||
Requires: []plugin.Type{
|
||||
plugin.ContentPlugin,
|
||||
plugin.MetadataPlugin,
|
||||
},
|
||||
Init: NewService,
|
||||
@@ -47,19 +46,13 @@ func init() {
|
||||
}
|
||||
|
||||
func NewService(ic *plugin.InitContext) (interface{}, error) {
|
||||
c, err := ic.Get(plugin.ContentPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cs := metadata.NewContentStore(m.(*metadata.DB), c.(content.Store))
|
||||
|
||||
return &Service{
|
||||
store: cs,
|
||||
store: m.(*metadata.DB).ContentStore(),
|
||||
publisher: ic.Events,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
protoempty "github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
@@ -24,7 +23,6 @@ func init() {
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "snapshots",
|
||||
Requires: []plugin.Type{
|
||||
plugin.SnapshotPlugin,
|
||||
plugin.MetadataPlugin,
|
||||
},
|
||||
Init: newService,
|
||||
@@ -34,31 +32,19 @@ func init() {
|
||||
var empty = &protoempty.Empty{}
|
||||
|
||||
type service struct {
|
||||
snapshotters map[string]snapshot.Snapshotter
|
||||
publisher events.Publisher
|
||||
db *metadata.DB
|
||||
publisher events.Publisher
|
||||
}
|
||||
|
||||
func newService(ic *plugin.InitContext) (interface{}, error) {
|
||||
rawSnapshotters, err := ic.GetAll(plugin.SnapshotPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
md, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
snapshotters := make(map[string]snapshot.Snapshotter)
|
||||
for name, sn := range rawSnapshotters {
|
||||
snapshotters[name] = metadata.NewSnapshotter(md.(*metadata.DB), name, sn.(snapshot.Snapshotter))
|
||||
}
|
||||
|
||||
if len(snapshotters) == 0 {
|
||||
return nil, errors.Errorf("failed to create snapshotter service: no snapshotters loaded")
|
||||
}
|
||||
|
||||
return &service{
|
||||
snapshotters: snapshotters,
|
||||
publisher: ic.Events,
|
||||
db: md.(*metadata.DB),
|
||||
publisher: ic.Events,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -67,8 +53,8 @@ func (s *service) getSnapshotter(name string) (snapshot.Snapshotter, error) {
|
||||
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, "snapshotter argument missing")
|
||||
}
|
||||
|
||||
sn, ok := s.snapshotters[name]
|
||||
if !ok {
|
||||
sn := s.db.Snapshotter(name)
|
||||
if sn == nil {
|
||||
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, "snapshotter not loaded: %s", name)
|
||||
}
|
||||
return sn, nil
|
||||
|
||||
@@ -44,7 +44,6 @@ func init() {
|
||||
Requires: []plugin.Type{
|
||||
plugin.RuntimePlugin,
|
||||
plugin.MetadataPlugin,
|
||||
plugin.ContentPlugin,
|
||||
},
|
||||
Init: New,
|
||||
})
|
||||
@@ -59,11 +58,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ct, err := ic.Get(plugin.ContentPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cs := metadata.NewContentStore(m.(*metadata.DB), ct.(content.Store))
|
||||
cs := m.(*metadata.DB).ContentStore()
|
||||
runtimes := make(map[string]runtime.Runtime)
|
||||
for _, rr := range rt {
|
||||
r := rr.(runtime.Runtime)
|
||||
|
||||
Reference in New Issue
Block a user