Merge pull request #3805 from AkihiroSuda/ctr-shim2-runc-flags

ctr: add --runc-binary --runc-systemd-cgroup
This commit is contained in:
Phil Estes 2019-11-08 11:11:39 -05:00 committed by GitHub
commit 1e12854831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,12 +29,22 @@ import (
"github.com/containerd/containerd/contrib/seccomp" "github.com/containerd/containerd/contrib/seccomp"
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
var platformRunFlags []cli.Flag var platformRunFlags = []cli.Flag{
cli.StringFlag{
Name: "runc-binary",
Usage: "specify runc-compatible binary",
},
cli.BoolFlag{
Name: "runc-systemd-cgroup",
Usage: "start runc with systemd cgroup manager",
},
}
// NewContainer creates a new container // NewContainer creates a new container
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) { func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
@ -167,7 +177,26 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
} }
} }
cOpts = append(cOpts, containerd.WithRuntime(context.String("runtime"), nil)) runtimeOpts := &options.Options{}
if runcBinary := context.String("runc-binary"); runcBinary != "" {
if context.String("runtime") == "io.containerd.runc.v2" {
runtimeOpts.BinaryName = runcBinary
} else {
return nil, errors.New("specifying runc-binary is only supported for \"io.containerd.runc.v2\" runtime")
}
}
if context.Bool("runc-systemd-cgroup") {
if context.String("runtime") == "io.containerd.runc.v2" {
if context.String("cgroup") == "" {
// runc maps "machine.slice:foo:deadbeef" to "/machine.slice/foo-deadbeef.scope"
return nil, errors.New("option --runc-systemd-cgroup requires --cgroup to be set, e.g. \"machine.slice:foo:deadbeef\"")
}
runtimeOpts.SystemdCgroup = true
} else {
return nil, errors.New("specifying runc-systemd-cgroup is only supported for \"io.containerd.runc.v2\" runtime")
}
}
cOpts = append(cOpts, containerd.WithRuntime(context.String("runtime"), runtimeOpts))
opts = append(opts, oci.WithAnnotations(commands.LabelArgs(context.StringSlice("label")))) opts = append(opts, oci.WithAnnotations(commands.LabelArgs(context.StringSlice("label"))))
var s specs.Spec var s specs.Spec