
The split between provider and ingester was a long standing division reflecting the client-side use cases. For the most part, we were differentiating these for the algorithms that operate them, but it made instantation and use of the types challenging. On the server-side, this distinction is generally less important. This change unifies these types and in the process we get a few benefits. The first is that we now completely access the content store over GRPC. This was the initial intent and we have now satisfied this goal completely. There are a few issues around listing content and getting status, but we resolve these with simple streaming and regexp filters. More can probably be done to polish this but the result is clean. Several other content-oriented methods were polished in the process of unification. We have now properly seperated out the `Abort` method to cancel ongoing or stalled ingest processes. We have also replaced the `Active` method with a single status method. The transition went extremely smoothly. Once the clients were updated to use the new methods, every thing worked as expected on the first compile. Signed-off-by: Stephen J Day <stephen.day@docker.com>
82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"github.com/boltdb/bolt"
|
|
"github.com/containerd/containerd"
|
|
"github.com/containerd/containerd/content"
|
|
"github.com/containerd/containerd/snapshot"
|
|
|
|
"golang.org/x/net/context"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type PluginType int
|
|
|
|
const (
|
|
RuntimePlugin PluginType = iota + 1
|
|
GRPCPlugin
|
|
SnapshotPlugin
|
|
ContainerMonitorPlugin
|
|
)
|
|
|
|
type Registration struct {
|
|
Type PluginType
|
|
Config interface{}
|
|
Init func(*InitContext) (interface{}, error)
|
|
}
|
|
|
|
// TODO(@crosbymichael): how to we keep this struct from growing but support dependency injection for loaded plugins?
|
|
type InitContext struct {
|
|
Root string
|
|
State string
|
|
Runtimes map[string]containerd.Runtime
|
|
Content content.Store
|
|
Meta *bolt.DB
|
|
Snapshotter snapshot.Snapshotter
|
|
Config interface{}
|
|
Context context.Context
|
|
Monitor ContainerMonitor
|
|
}
|
|
|
|
type Service interface {
|
|
Register(*grpc.Server) error
|
|
}
|
|
|
|
var register = struct {
|
|
sync.Mutex
|
|
r map[string]*Registration
|
|
}{
|
|
r: make(map[string]*Registration),
|
|
}
|
|
|
|
// Load loads all plugins at the provided path into containerd
|
|
func Load(path string) (err error) {
|
|
defer func() {
|
|
if v := recover(); v != nil {
|
|
rerr, ok := v.(error)
|
|
if !ok {
|
|
rerr = fmt.Errorf("%s", v)
|
|
}
|
|
err = rerr
|
|
}
|
|
}()
|
|
return loadPlugins(path)
|
|
}
|
|
|
|
func Register(name string, r *Registration) error {
|
|
register.Lock()
|
|
defer register.Unlock()
|
|
if _, ok := register.r[name]; ok {
|
|
return fmt.Errorf("plugin already registered as %q", name)
|
|
}
|
|
register.r[name] = r
|
|
return nil
|
|
}
|
|
|
|
func Registrations() map[string]*Registration {
|
|
return register.r
|
|
}
|