Merge pull request #909 from vburenin/diff-plugin
Make Diff/Apply plugable
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
// register containerd builtins here
|
||||
import (
|
||||
_ "github.com/containerd/containerd/differ"
|
||||
_ "github.com/containerd/containerd/services/containers"
|
||||
_ "github.com/containerd/containerd/services/content"
|
||||
_ "github.com/containerd/containerd/services/diff"
|
||||
|
||||
@@ -49,6 +49,9 @@ type config struct {
|
||||
Metrics metricsConfig `toml:"metrics"`
|
||||
// Snapshotter specifies which snapshot driver to use
|
||||
Snapshotter string `toml:"snapshotter"`
|
||||
// Differ specifies which differ to use. Differ is tightly coupled with the snapshotter
|
||||
// so not all combinations may work.
|
||||
Differ string `toml:"differ"`
|
||||
// Plugins provides plugin specific configuration for the initialization of a plugin
|
||||
Plugins map[string]toml.Primitive `toml:"plugins"`
|
||||
// Enable containerd as a subreaper
|
||||
|
||||
@@ -12,5 +12,6 @@ func defaultConfig() *config {
|
||||
Address: "/run/containerd/debug.sock",
|
||||
},
|
||||
Snapshotter: "overlay",
|
||||
Differ: "base",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,6 @@ func defaultConfig() *config {
|
||||
Address: "/run/containerd/debug.sock",
|
||||
},
|
||||
Snapshotter: "naive",
|
||||
Differ: "base",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ func defaultConfig() *config {
|
||||
Address: `\\.\pipe\containerd-debug`,
|
||||
},
|
||||
Snapshotter: "windows",
|
||||
Differ: "base",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,13 @@ func main() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
services, err := loadServices(runtimes, store, snapshotter, meta)
|
||||
|
||||
differ, err := loadDiffer(snapshotter, store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
services, err := loadServices(runtimes, store, snapshotter, meta, differ)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -351,6 +357,40 @@ func loadSnapshotter(store content.Store) (snapshot.Snapshotter, error) {
|
||||
return nil, fmt.Errorf("snapshotter not loaded: %v", conf.Snapshotter)
|
||||
}
|
||||
|
||||
func loadDiffer(snapshotter snapshot.Snapshotter, store content.Store) (plugin.Differ, error) {
|
||||
for name, sr := range plugin.Registrations() {
|
||||
if sr.Type != plugin.DiffPlugin {
|
||||
continue
|
||||
}
|
||||
moduleName := fmt.Sprintf("diff-%s", conf.Differ)
|
||||
if name != moduleName {
|
||||
continue
|
||||
}
|
||||
|
||||
log.G(global).Infof("loading differ plugin %q...", name)
|
||||
ic := &plugin.InitContext{
|
||||
Root: conf.Root,
|
||||
State: conf.State,
|
||||
Content: store,
|
||||
Snapshotter: snapshotter,
|
||||
Context: log.WithModule(global, moduleName),
|
||||
}
|
||||
if sr.Config != nil {
|
||||
if err := conf.decodePlugin(name, sr.Config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ic.Config = sr.Config
|
||||
}
|
||||
sn, err := sr.Init(ic)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sn.(plugin.Differ), nil
|
||||
}
|
||||
return nil, fmt.Errorf("differ not loaded: %v", conf.Differ)
|
||||
}
|
||||
|
||||
func newGRPCServer() *grpc.Server {
|
||||
s := grpc.NewServer(
|
||||
grpc.UnaryInterceptor(interceptor),
|
||||
@@ -359,7 +399,9 @@ func newGRPCServer() *grpc.Server {
|
||||
return s
|
||||
}
|
||||
|
||||
func loadServices(runtimes map[string]plugin.Runtime, store content.Store, sn snapshot.Snapshotter, meta *bolt.DB) ([]plugin.Service, error) {
|
||||
func loadServices(runtimes map[string]plugin.Runtime,
|
||||
store content.Store, sn snapshot.Snapshotter,
|
||||
meta *bolt.DB, differ plugin.Differ) ([]plugin.Service, error) {
|
||||
var o []plugin.Service
|
||||
for name, sr := range plugin.Registrations() {
|
||||
if sr.Type != plugin.GRPCPlugin {
|
||||
@@ -374,6 +416,7 @@ func loadServices(runtimes map[string]plugin.Runtime, store content.Store, sn sn
|
||||
Content: store,
|
||||
Meta: meta,
|
||||
Snapshotter: sn,
|
||||
Differ: differ,
|
||||
}
|
||||
if sr.Config != nil {
|
||||
if err := conf.decodePlugin(name, sr.Config); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user