Add linux runtime config

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-03-06 16:26:19 -08:00
parent 27a99400e8
commit e1731d2e5e

View file

@ -22,23 +22,35 @@ import (
const ( const (
runtimeName = "linux" runtimeName = "linux"
configFilename = "config.json" configFilename = "config.json"
defaultRuntime = "runc"
) )
func init() { func init() {
plugin.Register(runtimeName, &plugin.Registration{ plugin.Register(runtimeName, &plugin.Registration{
Type: plugin.RuntimePlugin, Type: plugin.RuntimePlugin,
Init: New, Init: New,
Config: &Config{},
}) })
} }
func New(ic *plugin.InitContext) (interface{}, error) { type Config struct {
// Runtime is a path or name of an OCI runtime used by the shim
Runtime string `toml:"runtime"`
}
func New(ic *containerd.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
} }
cfg := ic.Config.(*Config)
if cfg.Runtime == "" {
cfg.Runtime = defaultRuntime
}
c, cancel := context.WithCancel(ic.Context) c, cancel := context.WithCancel(ic.Context)
return &Runtime{ return &Runtime{
root: path, root: path,
runtime: cfg.Runtime,
events: make(chan *containerd.Event, 2048), events: make(chan *containerd.Event, 2048),
eventsContext: c, eventsContext: c,
eventsCancel: cancel, eventsCancel: cancel,
@ -46,7 +58,8 @@ func New(ic *plugin.InitContext) (interface{}, error) {
} }
type Runtime struct { type Runtime struct {
root string root string
runtime string
events chan *containerd.Event events chan *containerd.Event
eventsContext context.Context eventsContext context.Context
@ -70,7 +83,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateO
sopts := &shim.CreateRequest{ sopts := &shim.CreateRequest{
ID: id, ID: id,
Bundle: path, Bundle: path,
Runtime: "runc", Runtime: r.runtime,
Stdin: opts.IO.Stdin, Stdin: opts.IO.Stdin,
Stdout: opts.IO.Stdout, Stdout: opts.IO.Stdout,
Stderr: opts.IO.Stderr, Stderr: opts.IO.Stderr,