diff --git a/cri.go b/cri.go index 95084bdf3..455ef736e 100644 --- a/cri.go +++ b/cri.go @@ -141,6 +141,28 @@ func validateConfig(ctx context.Context, c *criconfig.Config) error { return errors.New("no corresponding runtime configured in `runtimes` for `default_runtime_name`") } + // Validation for deprecated runtime options. + if c.SystemdCgroup { + if c.ContainerdConfig.Runtimes[c.ContainerdConfig.DefaultRuntimeName].Type != plugin.RuntimeLinuxV1 { + return errors.Errorf("`systemd_cgroup` only works for runtime %s", plugin.RuntimeLinuxV1) + } + log.G(ctx).Warning("`systemd_cgroup` is deprecated, please use runtime `options` instead") + } + for _, r := range c.ContainerdConfig.Runtimes { + if r.Engine != "" { + if r.Type != plugin.RuntimeLinuxV1 { + return errors.Errorf("`runtime_engine` only works for runtime %s", plugin.RuntimeLinuxV1) + } + log.G(ctx).Warning("`runtime_engine` is deprecated, please use runtime `options` instead") + } + if r.Root != "" { + if r.Type != plugin.RuntimeLinuxV1 { + return errors.Errorf("`runtime_root` only works for runtime %s", plugin.RuntimeLinuxV1) + } + log.G(ctx).Warning("`runtime_root` is deprecated, please use runtime `options` instead") + } + } + // Validation for stream_idle_timeout if c.StreamIdleTimeout != "" { if _, err := time.ParseDuration(c.StreamIdleTimeout); err != nil { diff --git a/docs/config.md b/docs/config.md index eafd19864..f095b45d5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -40,12 +40,6 @@ version = 2 # stats_collect_period is the period (in seconds) of snapshots stats collection. stats_collect_period = 10 - # systemd_cgroup enables systemd cgroup support. This only works for runtime - # type "io.containerd.runtime.v1.linux". - # DEPRECATED: use Runtime.Options for runtime specific config for shim v2 runtimes. - # For runtime "io.containerd.runc.v1", use the option `SystemdCgroup`. - systemd_cgroup = false - # enable_tls_streaming enables the TLS streaming support. # It generates a self-sign certificate unless the following x509_key_pair_streaming are both set. enable_tls_streaming = false diff --git a/pkg/server/container_start.go b/pkg/server/container_start.go index 7927c534f..79922f6dd 100644 --- a/pkg/server/container_start.go +++ b/pkg/server/container_start.go @@ -24,6 +24,7 @@ import ( "github.com/containerd/containerd" containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" + "github.com/containerd/containerd/plugin" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" @@ -99,7 +100,7 @@ func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContain var taskOpts []containerd.NewTaskOpts // TODO(random-liu): Remove this after shim v1 is deprecated. - if c.config.NoPivot && ctrInfo.Runtime.Name == linuxRuntime { + if c.config.NoPivot && ctrInfo.Runtime.Name == plugin.RuntimeLinuxV1 { taskOpts = append(taskOpts, containerd.WithNoPivotRoot) } task, err := container.NewTask(ctx, ioCreation, taskOpts...) diff --git a/pkg/server/helpers.go b/pkg/server/helpers.go index 67ada57f4..6890415d8 100644 --- a/pkg/server/helpers.go +++ b/pkg/server/helpers.go @@ -27,6 +27,7 @@ import ( "github.com/BurntSushi/toml" "github.com/containerd/containerd" "github.com/containerd/containerd/containers" + "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime/linux/runctypes" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" "github.com/containerd/typeurl" @@ -116,16 +117,6 @@ const ( networkAttachCount = 2 ) -// Runtime type strings for various runtimes. -const ( - // linuxRuntime is the legacy linux runtime for shim v1. - linuxRuntime = "io.containerd.runtime.v1.linux" - // runcRuntimeV1 is the runc v1 runtime for shim v2. - runcRuntimeV1 = "io.containerd.runc.v1" - // runcRuntimeV2 is the runc v2 runtime for shim v2. - runcRuntimeV2 = "io.containerd.runc.v2" -) - // makeSandboxName generates sandbox name from sandbox metadata. The name // generated is unique as long as sandbox metadata is unique. func makeSandboxName(s *runtime.PodSandboxMetadata) string { @@ -416,7 +407,7 @@ func parseImageReferences(refs []string) ([]string, []string) { // generateRuntimeOptions generates runtime options from cri plugin config. func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{}, error) { if r.Options == nil { - if r.Type != linuxRuntime { + if r.Type != plugin.RuntimeLinuxV1 { return nil, nil } // This is a legacy config, generate runctypes.RuncOptions. @@ -436,11 +427,11 @@ func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{ // getRuntimeOptionsType gets empty runtime options by the runtime type name. func getRuntimeOptionsType(t string) interface{} { switch t { - case runcRuntimeV1: + case plugin.RuntimeRuncV1: fallthrough - case runcRuntimeV2: + case plugin.RuntimeRuncV2: return &runcoptions.Options{} - case linuxRuntime: + case plugin.RuntimeLinuxV1: return &runctypes.RuncOptions{} default: return &runtimeoptions.Options{} diff --git a/pkg/server/helpers_test.go b/pkg/server/helpers_test.go index 18a3a95c1..03d9acaed 100644 --- a/pkg/server/helpers_test.go +++ b/pkg/server/helpers_test.go @@ -21,6 +21,7 @@ import ( "github.com/BurntSushi/toml" "github.com/containerd/containerd/oci" + "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime/linux/runctypes" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" "github.com/docker/distribution/reference" @@ -214,11 +215,11 @@ systemd_cgroup = true no_pivot = true default_runtime_name = "default" [containerd.runtimes.legacy] - runtime_type = "` + linuxRuntime + `" + runtime_type = "` + plugin.RuntimeLinuxV1 + `" [containerd.runtimes.runc] - runtime_type = "` + runcRuntimeV1 + `" + runtime_type = "` + plugin.RuntimeRuncV1 + `" [containerd.runtimes.runcv2] - runtime_type = "` + runcRuntimeV2 + `" + runtime_type = "` + plugin.RuntimeRuncV2 + `" ` nonNilOpts := ` systemd_cgroup = true @@ -226,18 +227,18 @@ systemd_cgroup = true no_pivot = true default_runtime_name = "default" [containerd.runtimes.legacy] - runtime_type = "` + linuxRuntime + `" + runtime_type = "` + plugin.RuntimeLinuxV1 + `" [containerd.runtimes.legacy.options] Runtime = "legacy" RuntimeRoot = "/legacy" [containerd.runtimes.runc] - runtime_type = "` + runcRuntimeV1 + `" + runtime_type = "` + plugin.RuntimeRuncV1 + `" [containerd.runtimes.runc.options] BinaryName = "runc" Root = "/runc" NoNewKeyring = true [containerd.runtimes.runcv2] - runtime_type = "` + runcRuntimeV2 + `" + runtime_type = "` + plugin.RuntimeRuncV2 + `" [containerd.runtimes.runcv2.options] BinaryName = "runc" Root = "/runcv2" diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index 99cfe5c6a..0718dbc6f 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -27,6 +27,7 @@ import ( containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/oci" + "github.com/containerd/containerd/plugin" cni "github.com/containerd/go-cni" "github.com/containerd/typeurl" "github.com/davecgh/go-spew/spew" @@ -266,7 +267,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox var taskOpts []containerd.NewTaskOpts // TODO(random-liu): Remove this after shim v1 is deprecated. - if c.config.NoPivot && ociRuntime.Type == linuxRuntime { + if c.config.NoPivot && ociRuntime.Type == plugin.RuntimeRuncV1 { taskOpts = append(taskOpts, containerd.WithNoPivotRoot) } // We don't need stdio for sandbox container.