Merge pull request #838 from mlaventure/allow-specifying-shim
Allow specifying shim
This commit is contained in:
commit
a622f5e726
@ -26,8 +26,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rwm = "rwm"
|
rwm = "rwm"
|
||||||
rootfsPath = "rootfs"
|
defaultRootfsPath = "rootfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var capabilities = []string{
|
var capabilities = []string{
|
||||||
@ -47,7 +47,7 @@ var capabilities = []string{
|
|||||||
"CAP_AUDIT_WRITE",
|
"CAP_AUDIT_WRITE",
|
||||||
}
|
}
|
||||||
|
|
||||||
func spec(id string, config *ocispec.ImageConfig, context *cli.Context) (*specs.Spec, error) {
|
func spec(id string, config *ocispec.ImageConfig, context *cli.Context, rootfs string) (*specs.Spec, error) {
|
||||||
env := []string{
|
env := []string{
|
||||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
}
|
}
|
||||||
@ -92,6 +92,9 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) (*specs.
|
|||||||
if cwd == "" {
|
if cwd == "" {
|
||||||
cwd = "/"
|
cwd = "/"
|
||||||
}
|
}
|
||||||
|
if rootfs == "" {
|
||||||
|
rootfs = defaultRootfsPath
|
||||||
|
}
|
||||||
s := &specs.Spec{
|
s := &specs.Spec{
|
||||||
Version: specs.Version,
|
Version: specs.Version,
|
||||||
Platform: specs.Platform{
|
Platform: specs.Platform{
|
||||||
@ -99,7 +102,7 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) (*specs.
|
|||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
},
|
},
|
||||||
Root: specs.Root{
|
Root: specs.Root{
|
||||||
Path: rootfsPath,
|
Path: rootfs,
|
||||||
Readonly: context.Bool("readonly"),
|
Readonly: context.Bool("readonly"),
|
||||||
},
|
},
|
||||||
Process: specs.Process{
|
Process: specs.Process{
|
||||||
@ -232,9 +235,9 @@ func customSpec(configPath string, rootfs string) (*specs.Spec, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if rootfs == "" {
|
if rootfs == "" {
|
||||||
if s.Root.Path != rootfsPath {
|
if s.Root.Path != defaultRootfsPath {
|
||||||
logrus.Warnf("ignoring Root.Path %q, setting %q forcibly", s.Root.Path, rootfsPath)
|
logrus.Warnf("ignoring Root.Path %q, setting %q forcibly", s.Root.Path, defaultRootfsPath)
|
||||||
s.Root.Path = rootfsPath
|
s.Root.Path = defaultRootfsPath
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s.Root.Path = rootfs
|
s.Root.Path = rootfs
|
||||||
@ -245,7 +248,7 @@ func customSpec(configPath string, rootfs string) (*specs.Spec, error) {
|
|||||||
func getConfig(context *cli.Context, imageConfig *ocispec.ImageConfig, rootfs string) (*specs.Spec, error) {
|
func getConfig(context *cli.Context, imageConfig *ocispec.ImageConfig, rootfs string) (*specs.Spec, error) {
|
||||||
config := context.String("runtime-config")
|
config := context.String("runtime-config")
|
||||||
if config == "" {
|
if config == "" {
|
||||||
return spec(context.String("id"), imageConfig, context)
|
return spec(context.String("id"), imageConfig, context, rootfs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return customSpec(config, rootfs)
|
return customSpec(config, rootfs)
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
@ -27,23 +28,29 @@ const (
|
|||||||
runtimeName = "linux"
|
runtimeName = "linux"
|
||||||
configFilename = "config.json"
|
configFilename = "config.json"
|
||||||
defaultRuntime = "runc"
|
defaultRuntime = "runc"
|
||||||
|
defaultShim = "containerd-shim"
|
||||||
)
|
)
|
||||||
|
|
||||||
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{},
|
Config: &Config{
|
||||||
|
Shim: defaultShim,
|
||||||
|
Runtime: defaultRuntime,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = (plugin.Runtime)(&Runtime{})
|
var _ = (plugin.Runtime)(&Runtime{})
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Shim is a path or name of binary implementing the Shim GRPC API
|
||||||
|
Shim string `toml:"shim,omitempty"`
|
||||||
// Runtime is a path or name of an OCI runtime used by the shim
|
// Runtime is a path or name of an OCI runtime used by the shim
|
||||||
Runtime string `toml:"runtime"`
|
Runtime string `toml:"runtime,omitempty"`
|
||||||
// NoShim calls runc directly from within the pkg
|
// NoShim calls runc directly from within the pkg
|
||||||
NoShim bool `toml:"no_shim"`
|
NoShim bool `toml:"no_shim,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||||
@ -52,13 +59,11 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cfg := ic.Config.(*Config)
|
cfg := ic.Config.(*Config)
|
||||||
if cfg.Runtime == "" {
|
|
||||||
cfg.Runtime = defaultRuntime
|
|
||||||
}
|
|
||||||
c, cancel := context.WithCancel(ic.Context)
|
c, cancel := context.WithCancel(ic.Context)
|
||||||
r := &Runtime{
|
r := &Runtime{
|
||||||
root: path,
|
root: path,
|
||||||
remote: !cfg.NoShim,
|
remote: !cfg.NoShim,
|
||||||
|
shim: cfg.Shim,
|
||||||
runtime: cfg.Runtime,
|
runtime: cfg.Runtime,
|
||||||
events: make(chan *containerd.Event, 2048),
|
events: make(chan *containerd.Event, 2048),
|
||||||
eventsContext: c,
|
eventsContext: c,
|
||||||
@ -72,6 +77,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
root string
|
root string
|
||||||
|
shim string
|
||||||
runtime string
|
runtime string
|
||||||
remote bool
|
remote bool
|
||||||
|
|
||||||
@ -86,7 +92,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s, err := newShim(path, r.remote)
|
s, err := newShim(r.shim, path, r.remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(path)
|
os.RemoveAll(path)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -187,7 +193,9 @@ func (r *Runtime) forward(events shim.Shim_EventsClient) {
|
|||||||
for {
|
for {
|
||||||
e, err := events.Recv()
|
e, err := events.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(r.eventsContext).WithError(err).Error("get event from shim")
|
if !strings.HasSuffix(err.Error(), "transport is closing") {
|
||||||
|
log.G(r.eventsContext).WithError(err).Error("get event from shim")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var et containerd.EventType
|
var et containerd.EventType
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newShim(path string, remote bool) (shim.ShimClient, error) {
|
func newShim(shimName string, path string, remote bool) (shim.ShimClient, error) {
|
||||||
if !remote {
|
if !remote {
|
||||||
return localShim.Client(path)
|
return localShim.Client(path)
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ func newShim(path string, remote bool) (shim.ShimClient, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cmd := exec.Command("containerd-shim")
|
cmd := exec.Command(shimName)
|
||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
f, err := l.(*net.UnixListener).File()
|
f, err := l.(*net.UnixListener).File()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user