Pass options on shim create for v2
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
b99a66c267
commit
90c6c1af43
@ -30,6 +30,7 @@ import (
|
|||||||
client "github.com/containerd/containerd/runtime/v2/shim"
|
client "github.com/containerd/containerd/runtime/v2/shim"
|
||||||
"github.com/containerd/containerd/runtime/v2/task"
|
"github.com/containerd/containerd/runtime/v2/task"
|
||||||
"github.com/containerd/ttrpc"
|
"github.com/containerd/ttrpc"
|
||||||
|
"github.com/gogo/protobuf/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -52,7 +53,7 @@ type binary struct {
|
|||||||
rtTasks *runtime.TaskList
|
rtTasks *runtime.TaskList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *binary) Start(ctx context.Context, onClose func()) (_ *shim, err error) {
|
func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_ *shim, err error) {
|
||||||
args := []string{"-id", b.bundle.ID}
|
args := []string{"-id", b.bundle.ID}
|
||||||
if logrus.GetLevel() == logrus.DebugLevel {
|
if logrus.GetLevel() == logrus.DebugLevel {
|
||||||
args = append(args, "-debug")
|
args = append(args, "-debug")
|
||||||
@ -64,6 +65,7 @@ func (b *binary) Start(ctx context.Context, onClose func()) (_ *shim, err error)
|
|||||||
b.runtime,
|
b.runtime,
|
||||||
b.containerdAddress,
|
b.containerdAddress,
|
||||||
b.bundle.Path,
|
b.bundle.Path,
|
||||||
|
opts,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -126,6 +128,7 @@ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) {
|
|||||||
b.runtime,
|
b.runtime,
|
||||||
b.containerdAddress,
|
b.containerdAddress,
|
||||||
bundlePath,
|
bundlePath,
|
||||||
|
nil,
|
||||||
"-id", b.bundle.ID,
|
"-id", b.bundle.ID,
|
||||||
"-bundle", b.bundle.Path,
|
"-bundle", b.bundle.Path,
|
||||||
"delete")
|
"delete")
|
||||||
|
@ -126,8 +126,13 @@ func (m *TaskManager) Create(ctx context.Context, id string, opts runtime.Create
|
|||||||
bundle.Delete()
|
bundle.Delete()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
topts := opts.TaskOptions
|
||||||
|
if topts == nil {
|
||||||
|
topts = opts.RuntimeOptions
|
||||||
|
}
|
||||||
|
|
||||||
b := shimBinary(ctx, bundle, opts.Runtime, m.containerdAddress, m.events, m.tasks)
|
b := shimBinary(ctx, bundle, opts.Runtime, m.containerdAddress, m.events, m.tasks)
|
||||||
shim, err := b.Start(ctx, func() {
|
shim, err := b.Start(ctx, topts, func() {
|
||||||
log.G(ctx).WithField("id", id).Info("shim disconnected")
|
log.G(ctx).WithField("id", id).Info("shim disconnected")
|
||||||
_, err := m.tasks.Get(ctx, id)
|
_, err := m.tasks.Get(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package shim
|
package shim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -29,13 +30,15 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
|
"github.com/gogo/protobuf/proto"
|
||||||
|
"github.com/gogo/protobuf/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var runtimePaths sync.Map
|
var runtimePaths sync.Map
|
||||||
|
|
||||||
// Command returns the shim command with the provided args and configuration
|
// Command returns the shim command with the provided args and configuration
|
||||||
func Command(ctx context.Context, runtime, containerdAddress, path string, cmdArgs ...string) (*exec.Cmd, error) {
|
func Command(ctx context.Context, runtime, containerdAddress, path string, opts *types.Any, cmdArgs ...string) (*exec.Cmd, error) {
|
||||||
ns, err := namespaces.NamespaceRequired(ctx)
|
ns, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -94,6 +97,13 @@ func Command(ctx context.Context, runtime, containerdAddress, path string, cmdAr
|
|||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
cmd.Env = append(os.Environ(), "GOMAXPROCS=2")
|
cmd.Env = append(os.Environ(), "GOMAXPROCS=2")
|
||||||
cmd.SysProcAttr = getSysProcAttr()
|
cmd.SysProcAttr = getSysProcAttr()
|
||||||
|
if opts != nil {
|
||||||
|
d, err := proto.Marshal(opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cmd.Stdin = bytes.NewReader(d)
|
||||||
|
}
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user