Merge pull request #1439 from mlaventure/allow-setting-rutime-opts

Allow setting runtime options when using WithRuntime()
This commit is contained in:
Phil Estes 2017-08-30 15:59:14 -04:00 committed by GitHub
commit 0baecaa7cf
3 changed files with 17 additions and 4 deletions

View File

@ -99,7 +99,7 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image)) cOpts = append(cOpts, containerd.WithNewSnapshot(id, image))
} }
} }
cOpts = append(cOpts, containerd.WithRuntime(context.String("runtime"))) cOpts = append(cOpts, containerd.WithRuntime(context.String("runtime"), nil))
opts = append(opts, withEnv(context), withMounts(context)) opts = append(opts, withEnv(context), withMounts(context))
if len(args) > 0 { if len(args) > 0 {

View File

@ -111,7 +111,7 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
return client.NewContainer(ctx, id, return client.NewContainer(ctx, id,
containerd.WithNewSpec(opts...), containerd.WithNewSpec(opts...),
containerd.WithContainerLabels(labels), containerd.WithContainerLabels(labels),
containerd.WithRuntime(context.String("runtime")), containerd.WithRuntime(context.String("runtime"), nil),
// TODO(mlaventure): containerd.WithImage(image), // TODO(mlaventure): containerd.WithImage(image),
) )
} }

View File

@ -5,6 +5,8 @@ import (
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/typeurl"
"github.com/gogo/protobuf/types"
"github.com/opencontainers/image-spec/identity" "github.com/opencontainers/image-spec/identity"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -14,10 +16,21 @@ type NewContainerOpts func(ctx context.Context, client *Client, c *containers.Co
// WithRuntime allows a user to specify the runtime name and additional options that should // WithRuntime allows a user to specify the runtime name and additional options that should
// be used to create tasks for the container // be used to create tasks for the container
func WithRuntime(name string) NewContainerOpts { func WithRuntime(name string, options interface{}) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error { return func(ctx context.Context, client *Client, c *containers.Container) error {
var (
any *types.Any
err error
)
if options != nil {
any, err = typeurl.MarshalAny(options)
if err != nil {
return err
}
}
c.Runtime = containers.RuntimeInfo{ c.Runtime = containers.RuntimeInfo{
Name: name, Name: name,
Options: any,
} }
return nil return nil
} }