Move plugin registration to separate package
Only compile in plugin support on non-windows 1.8. Re-enable go 1.7.x tests. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
a7cb5a783c
commit
0b44e24c07
8 changed files with 81 additions and 61 deletions
|
@ -4,6 +4,7 @@ sudo: required
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
|
- 1.7.x
|
||||||
- 1.8.x
|
- 1.8.x
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
api "github.com/docker/containerd/api/services/execution"
|
api "github.com/docker/containerd/api/services/execution"
|
||||||
"github.com/docker/containerd/content"
|
"github.com/docker/containerd/content"
|
||||||
"github.com/docker/containerd/log"
|
"github.com/docker/containerd/log"
|
||||||
|
"github.com/docker/containerd/plugin"
|
||||||
"github.com/docker/containerd/utils"
|
"github.com/docker/containerd/utils"
|
||||||
metrics "github.com/docker/go-metrics"
|
metrics "github.com/docker/go-metrics"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -85,7 +86,7 @@ func main() {
|
||||||
log.G(global).Info("starting containerd boot...")
|
log.G(global).Info("starting containerd boot...")
|
||||||
|
|
||||||
// load all plugins into containerd
|
// load all plugins into containerd
|
||||||
if err := containerd.Load(filepath.Join(conf.Root, "plugins")); err != nil {
|
if err := plugin.Load(filepath.Join(conf.Root, "plugins")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// start debug and metrics APIs
|
// start debug and metrics APIs
|
||||||
|
@ -222,12 +223,12 @@ func resolveContentStore() (*content.Store, error) {
|
||||||
|
|
||||||
func loadRuntimes() (map[string]containerd.Runtime, error) {
|
func loadRuntimes() (map[string]containerd.Runtime, error) {
|
||||||
o := make(map[string]containerd.Runtime)
|
o := make(map[string]containerd.Runtime)
|
||||||
for name, rr := range containerd.Registrations() {
|
for name, rr := range plugin.Registrations() {
|
||||||
if rr.Type != containerd.RuntimePlugin {
|
if rr.Type != plugin.RuntimePlugin {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.G(global).Infof("loading runtime plugin %q...", name)
|
log.G(global).Infof("loading runtime plugin %q...", name)
|
||||||
ic := &containerd.InitContext{
|
ic := &plugin.InitContext{
|
||||||
Root: conf.Root,
|
Root: conf.Root,
|
||||||
State: conf.State,
|
State: conf.State,
|
||||||
Context: log.WithModule(global, fmt.Sprintf("runtime-%s", name)),
|
Context: log.WithModule(global, fmt.Sprintf("runtime-%s", name)),
|
||||||
|
@ -252,14 +253,14 @@ func newGRPCServer() *grpc.Server {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadServices(runtimes map[string]containerd.Runtime, store *content.Store) ([]containerd.Service, error) {
|
func loadServices(runtimes map[string]containerd.Runtime, store *content.Store) ([]plugin.Service, error) {
|
||||||
var o []containerd.Service
|
var o []plugin.Service
|
||||||
for name, sr := range containerd.Registrations() {
|
for name, sr := range plugin.Registrations() {
|
||||||
if sr.Type != containerd.GRPCPlugin {
|
if sr.Type != plugin.GRPCPlugin {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.G(global).Infof("loading grpc service plugin %q...", name)
|
log.G(global).Infof("loading grpc service plugin %q...", name)
|
||||||
ic := &containerd.InitContext{
|
ic := &plugin.InitContext{
|
||||||
Root: conf.Root,
|
Root: conf.Root,
|
||||||
State: conf.State,
|
State: conf.State,
|
||||||
Context: log.WithModule(global, fmt.Sprintf("service-%s", name)),
|
Context: log.WithModule(global, fmt.Sprintf("service-%s", name)),
|
||||||
|
@ -276,7 +277,7 @@ func loadServices(runtimes map[string]containerd.Runtime, store *content.Store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
o = append(o, vs.(containerd.Service))
|
o = append(o, vs.(plugin.Service))
|
||||||
}
|
}
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/docker/containerd/api/types/container"
|
"github.com/docker/containerd/api/types/container"
|
||||||
"github.com/docker/containerd/api/types/mount"
|
"github.com/docker/containerd/api/types/mount"
|
||||||
"github.com/docker/containerd/log"
|
"github.com/docker/containerd/log"
|
||||||
|
"github.com/docker/containerd/plugin"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -24,13 +25,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
containerd.Register(runtimeName, &containerd.Registration{
|
plugin.Register(runtimeName, &plugin.Registration{
|
||||||
Type: containerd.RuntimePlugin,
|
Type: plugin.RuntimePlugin,
|
||||||
Init: New,
|
Init: New,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ic *containerd.InitContext) (interface{}, error) {
|
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||||
path := filepath.Join(ic.State, runtimeName)
|
path := filepath.Join(ic.State, runtimeName)
|
||||||
if err := os.MkdirAll(path, 0700); err != nil {
|
if err := os.MkdirAll(path, 0700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package containerd
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"plugin"
|
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/docker/containerd"
|
||||||
"github.com/docker/containerd/content"
|
"github.com/docker/containerd/content"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -29,7 +27,7 @@ type Registration struct {
|
||||||
type InitContext struct {
|
type InitContext struct {
|
||||||
Root string
|
Root string
|
||||||
State string
|
State string
|
||||||
Runtimes map[string]Runtime
|
Runtimes map[string]containerd.Runtime
|
||||||
Store *content.Store
|
Store *content.Store
|
||||||
Config interface{}
|
Config interface{}
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
@ -73,39 +71,3 @@ func Register(name string, r *Registration) error {
|
||||||
func Registrations() map[string]*Registration {
|
func Registrations() map[string]*Registration {
|
||||||
return register.r
|
return register.r
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadPlugins loads all plugins for the OS and Arch
|
|
||||||
// that containerd is built for inside the provided path
|
|
||||||
func loadPlugins(path string) error {
|
|
||||||
abs, err := filepath.Abs(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pattern := filepath.Join(abs, fmt.Sprintf(
|
|
||||||
"*-%s-%s.%s",
|
|
||||||
runtime.GOOS,
|
|
||||||
runtime.GOARCH,
|
|
||||||
getLibExt(),
|
|
||||||
))
|
|
||||||
libs, err := filepath.Glob(pattern)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, lib := range libs {
|
|
||||||
if _, err := plugin.Open(lib); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getLibExt returns a platform specific lib extension for
|
|
||||||
// the platform that containerd is running on
|
|
||||||
func getLibExt() string {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "windows":
|
|
||||||
return "dll"
|
|
||||||
default:
|
|
||||||
return "so"
|
|
||||||
}
|
|
||||||
}
|
|
46
plugin/plugin_go18.go
Normal file
46
plugin/plugin_go18.go
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// +build go1.8,!windows
|
||||||
|
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"plugin"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// loadPlugins loads all plugins for the OS and Arch
|
||||||
|
// that containerd is built for inside the provided path
|
||||||
|
func loadPlugins(path string) error {
|
||||||
|
abs, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pattern := filepath.Join(abs, fmt.Sprintf(
|
||||||
|
"*-%s-%s.%s",
|
||||||
|
runtime.GOOS,
|
||||||
|
runtime.GOARCH,
|
||||||
|
getLibExt(),
|
||||||
|
))
|
||||||
|
libs, err := filepath.Glob(pattern)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, lib := range libs {
|
||||||
|
if _, err := plugin.Open(lib); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getLibExt returns a platform specific lib extension for
|
||||||
|
// the platform that containerd is running on
|
||||||
|
func getLibExt() string {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
return "dll"
|
||||||
|
default:
|
||||||
|
return "so"
|
||||||
|
}
|
||||||
|
}
|
8
plugin/plugin_other.go
Normal file
8
plugin/plugin_other.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// +build !go1.8 windows
|
||||||
|
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
func loadPlugins(path string) error {
|
||||||
|
// plugins not supported until 1.8
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -5,10 +5,10 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/containerd"
|
|
||||||
api "github.com/docker/containerd/api/services/content"
|
api "github.com/docker/containerd/api/services/content"
|
||||||
"github.com/docker/containerd/content"
|
"github.com/docker/containerd/content"
|
||||||
"github.com/docker/containerd/log"
|
"github.com/docker/containerd/log"
|
||||||
|
"github.com/docker/containerd/plugin"
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -30,13 +30,13 @@ var bufPool = sync.Pool{
|
||||||
var _ api.ContentServer = &Service{}
|
var _ api.ContentServer = &Service{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
containerd.Register("content-grpc", &containerd.Registration{
|
plugin.Register("content-grpc", &plugin.Registration{
|
||||||
Type: containerd.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
Init: NewService,
|
Init: NewService,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(ic *containerd.InitContext) (interface{}, error) {
|
func NewService(ic *plugin.InitContext) (interface{}, error) {
|
||||||
return &Service{
|
return &Service{
|
||||||
store: ic.Store,
|
store: ic.Store,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
api "github.com/docker/containerd/api/services/execution"
|
api "github.com/docker/containerd/api/services/execution"
|
||||||
"github.com/docker/containerd/api/types/container"
|
"github.com/docker/containerd/api/types/container"
|
||||||
"github.com/docker/containerd/log"
|
"github.com/docker/containerd/log"
|
||||||
|
"github.com/docker/containerd/plugin"
|
||||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
@ -18,13 +19,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
containerd.Register("runtime-grpc", &containerd.Registration{
|
plugin.Register("runtime-grpc", &plugin.Registration{
|
||||||
Type: containerd.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
Init: New,
|
Init: New,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ic *containerd.InitContext) (interface{}, error) {
|
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||||
c, err := newCollector(ic.Context, ic.Runtimes)
|
c, err := newCollector(ic.Context, ic.Runtimes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue