ctr: do not assume runc options by default
If runtime is not runc, it doesn't make sense to send runc Options as container create options, which will confuse other runtimes and it actually causes kata shimv2 to fail to unmarshal the requset. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
e2e40e19d7
commit
ebd745f91a
@ -205,24 +205,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeOpts := &options.Options{}
|
runtimeOpts, err := getRuntimeOptions(context)
|
||||||
if runcBinary := context.String("runc-binary"); runcBinary != "" {
|
if err != nil {
|
||||||
if context.String("runtime") == "io.containerd.runc.v2" {
|
return nil, err
|
||||||
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))
|
cOpts = append(cOpts, containerd.WithRuntime(context.String("runtime"), runtimeOpts))
|
||||||
|
|
||||||
@ -237,6 +222,36 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
return client.NewContainer(ctx, id, cOpts...)
|
return client.NewContainer(ctx, id, cOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRuncOptions(context *cli.Context) (*options.Options, error) {
|
||||||
|
runtimeOpts := &options.Options{}
|
||||||
|
if runcBinary := context.String("runc-binary"); runcBinary != "" {
|
||||||
|
runtimeOpts.BinaryName = runcBinary
|
||||||
|
}
|
||||||
|
if context.Bool("runc-systemd-cgroup") {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtimeOpts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRuntimeOptions(context *cli.Context) (interface{}, error) {
|
||||||
|
// validate first
|
||||||
|
if (context.String("runc-binary") != "" || context.Bool("runc-systemd-cgroup")) &&
|
||||||
|
context.String("runtime") != "io.containerd.runc.v2" {
|
||||||
|
return nil, errors.New("specifying runc-binary and runc-systemd-cgroup is only supported for \"io.containerd.runc.v2\" runtime")
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.String("runtime") == "io.containerd.runc.v2" {
|
||||||
|
return getRuncOptions(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func getNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
|
func getNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
|
||||||
var (
|
var (
|
||||||
tOpts []containerd.NewTaskOpts
|
tOpts []containerd.NewTaskOpts
|
||||||
|
Loading…
Reference in New Issue
Block a user