Load runtimes dynamically via go1.8 plugins
Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Add registration for more subsystems via plugins Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Move content service to separate package Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
51
runtime.go
51
runtime.go
@@ -1,53 +1,6 @@
|
||||
package containerd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// NewRuntimeFunc is the runtime's constructor
|
||||
type NewRuntimeFunc func(root string) (Runtime, error)
|
||||
|
||||
var runtimeRegistration = struct {
|
||||
mu sync.Mutex
|
||||
runtimes map[string]NewRuntimeFunc
|
||||
}{
|
||||
runtimes: make(map[string]NewRuntimeFunc),
|
||||
}
|
||||
|
||||
// RegisterRuntime is not external packages registers Runtimes for use with containerd
|
||||
func RegisterRuntime(name string, f NewRuntimeFunc) {
|
||||
runtimeRegistration.mu.Lock()
|
||||
defer runtimeRegistration.mu.Unlock()
|
||||
if _, ok := runtimeRegistration.runtimes[name]; ok {
|
||||
panic(fmt.Errorf("runtime already registered as %q", name))
|
||||
}
|
||||
runtimeRegistration.runtimes[name] = f
|
||||
}
|
||||
|
||||
// Runtimes returns a slice of all registered runtime names for containerd
|
||||
func Runtimes() (o []string) {
|
||||
runtimeRegistration.mu.Lock()
|
||||
defer runtimeRegistration.mu.Unlock()
|
||||
|
||||
for k := range runtimeRegistration.runtimes {
|
||||
o = append(o, k)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// NewRuntime calls the runtime's constructor with the provided root
|
||||
func NewRuntime(name, root string) (Runtime, error) {
|
||||
runtimeRegistration.mu.Lock()
|
||||
defer runtimeRegistration.mu.Unlock()
|
||||
f, ok := runtimeRegistration.runtimes[name]
|
||||
if !ok {
|
||||
return nil, ErrRuntimeNotExist
|
||||
}
|
||||
return f(root)
|
||||
}
|
||||
import "golang.org/x/net/context"
|
||||
|
||||
type IO struct {
|
||||
Stdin string
|
||||
@@ -73,7 +26,7 @@ type Runtime interface {
|
||||
// Containers returns all the current containers for the runtime
|
||||
Containers() ([]Container, error)
|
||||
// Delete removes the container in the runtime
|
||||
Delete(ctx context.Context, c Container) error
|
||||
Delete(context.Context, Container) error
|
||||
// Events returns events for the runtime and all containers created by the runtime
|
||||
Events(context.Context) <-chan *Event
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user