Merge pull request #909 from vburenin/diff-plugin

Make Diff/Apply plugable
This commit is contained in:
Michael Crosby
2017-06-05 11:04:34 -07:00
committed by GitHub
11 changed files with 249 additions and 143 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -12,5 +12,6 @@ func defaultConfig() *config {
Address: "/run/containerd/debug.sock",
},
Snapshotter: "overlay",
Differ: "base",
}
}

View File

@@ -14,5 +14,6 @@ func defaultConfig() *config {
Address: "/run/containerd/debug.sock",
},
Snapshotter: "naive",
Differ: "base",
}
}

View File

@@ -17,5 +17,6 @@ func defaultConfig() *config {
Address: `\\.\pipe\containerd-debug`,
},
Snapshotter: "windows",
Differ: "base",
}
}

View File

@@ -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 {