Skip to content

Commit 90c6c1a

Browse files
committed
Pass options on shim create for v2
Signed-off-by: Michael Crosby <[email protected]>
1 parent b99a66c commit 90c6c1a

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

runtime/v2/binary.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
client "github.com/containerd/containerd/runtime/v2/shim"
3131
"github.com/containerd/containerd/runtime/v2/task"
3232
"github.com/containerd/ttrpc"
33+
"github.com/gogo/protobuf/types"
3334
"github.com/pkg/errors"
3435
"github.com/sirupsen/logrus"
3536
)
@@ -52,7 +53,7 @@ type binary struct {
5253
rtTasks *runtime.TaskList
5354
}
5455

55-
func (b *binary) Start(ctx context.Context, onClose func()) (_ *shim, err error) {
56+
func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_ *shim, err error) {
5657
args := []string{"-id", b.bundle.ID}
5758
if logrus.GetLevel() == logrus.DebugLevel {
5859
args = append(args, "-debug")
@@ -64,6 +65,7 @@ func (b *binary) Start(ctx context.Context, onClose func()) (_ *shim, err error)
6465
b.runtime,
6566
b.containerdAddress,
6667
b.bundle.Path,
68+
opts,
6769
args...,
6870
)
6971
if err != nil {
@@ -126,6 +128,7 @@ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) {
126128
b.runtime,
127129
b.containerdAddress,
128130
bundlePath,
131+
nil,
129132
"-id", b.bundle.ID,
130133
"-bundle", b.bundle.Path,
131134
"delete")

runtime/v2/manager.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ func (m *TaskManager) Create(ctx context.Context, id string, opts runtime.Create
126126
bundle.Delete()
127127
}
128128
}()
129+
topts := opts.TaskOptions
130+
if topts == nil {
131+
topts = opts.RuntimeOptions
132+
}
133+
129134
b := shimBinary(ctx, bundle, opts.Runtime, m.containerdAddress, m.events, m.tasks)
130-
shim, err := b.Start(ctx, func() {
135+
shim, err := b.Start(ctx, topts, func() {
131136
log.G(ctx).WithField("id", id).Info("shim disconnected")
132137
_, err := m.tasks.Get(ctx, id)
133138
if err != nil {

runtime/v2/shim/util.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package shim
1818

1919
import (
20+
"bytes"
2021
"context"
2122
"fmt"
2223
"io/ioutil"
@@ -29,13 +30,15 @@ import (
2930
"time"
3031

3132
"github.com/containerd/containerd/namespaces"
33+
"github.com/gogo/protobuf/proto"
34+
"github.com/gogo/protobuf/types"
3235
"github.com/pkg/errors"
3336
)
3437

3538
var runtimePaths sync.Map
3639

3740
// Command returns the shim command with the provided args and configuration
38-
func Command(ctx context.Context, runtime, containerdAddress, path string, cmdArgs ...string) (*exec.Cmd, error) {
41+
func Command(ctx context.Context, runtime, containerdAddress, path string, opts *types.Any, cmdArgs ...string) (*exec.Cmd, error) {
3942
ns, err := namespaces.NamespaceRequired(ctx)
4043
if err != nil {
4144
return nil, err
@@ -94,6 +97,13 @@ func Command(ctx context.Context, runtime, containerdAddress, path string, cmdAr
9497
cmd.Dir = path
9598
cmd.Env = append(os.Environ(), "GOMAXPROCS=2")
9699
cmd.SysProcAttr = getSysProcAttr()
100+
if opts != nil {
101+
d, err := proto.Marshal(opts)
102+
if err != nil {
103+
return nil, err
104+
}
105+
cmd.Stdin = bytes.NewReader(d)
106+
}
97107
return cmd, nil
98108
}
99109

0 commit comments

Comments
 (0)