Skip to content

Commit

Permalink
Merge pull request #3805 from AkihiroSuda/ctr-shim2-runc-flags
Browse files Browse the repository at this point in the history
ctr: add --runc-binary --runc-systemd-cgroup
  • Loading branch information
estesp committed Nov 8, 2019
2 parents c038a7c + 8f74de9 commit 1e12854
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions cmd/ctr/commands/run/run_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ import (
"github.com/containerd/containerd/contrib/seccomp"
"github.com/containerd/containerd/oci"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"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
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
Expand Down Expand Up @@ -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"))))
var s specs.Spec
Expand Down

0 comments on commit 1e12854

Please sign in to comment.