Print warning message for deprecated options.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2019-08-02 01:07:22 -07:00
parent f636fb0519
commit b74653b821
6 changed files with 38 additions and 28 deletions

22
cri.go
View File

@ -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`") 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 // Validation for stream_idle_timeout
if c.StreamIdleTimeout != "" { if c.StreamIdleTimeout != "" {
if _, err := time.ParseDuration(c.StreamIdleTimeout); err != nil { if _, err := time.ParseDuration(c.StreamIdleTimeout); err != nil {

View File

@ -40,12 +40,6 @@ version = 2
# stats_collect_period is the period (in seconds) of snapshots stats collection. # stats_collect_period is the period (in seconds) of snapshots stats collection.
stats_collect_period = 10 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. # enable_tls_streaming enables the TLS streaming support.
# It generates a self-sign certificate unless the following x509_key_pair_streaming are both set. # It generates a self-sign certificate unless the following x509_key_pair_streaming are both set.
enable_tls_streaming = false enable_tls_streaming = false

View File

@ -24,6 +24,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
containerdio "github.com/containerd/containerd/cio" containerdio "github.com/containerd/containerd/cio"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/plugin"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -99,7 +100,7 @@ func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContain
var taskOpts []containerd.NewTaskOpts var taskOpts []containerd.NewTaskOpts
// TODO(random-liu): Remove this after shim v1 is deprecated. // 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) taskOpts = append(taskOpts, containerd.WithNoPivotRoot)
} }
task, err := container.NewTask(ctx, ioCreation, taskOpts...) task, err := container.NewTask(ctx, ioCreation, taskOpts...)

View File

@ -27,6 +27,7 @@ import (
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime/linux/runctypes" "github.com/containerd/containerd/runtime/linux/runctypes"
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
@ -116,16 +117,6 @@ const (
networkAttachCount = 2 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 // makeSandboxName generates sandbox name from sandbox metadata. The name
// generated is unique as long as sandbox metadata is unique. // generated is unique as long as sandbox metadata is unique.
func makeSandboxName(s *runtime.PodSandboxMetadata) string { func makeSandboxName(s *runtime.PodSandboxMetadata) string {
@ -416,7 +407,7 @@ func parseImageReferences(refs []string) ([]string, []string) {
// generateRuntimeOptions generates runtime options from cri plugin config. // generateRuntimeOptions generates runtime options from cri plugin config.
func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{}, error) { func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{}, error) {
if r.Options == nil { if r.Options == nil {
if r.Type != linuxRuntime { if r.Type != plugin.RuntimeLinuxV1 {
return nil, nil return nil, nil
} }
// This is a legacy config, generate runctypes.RuncOptions. // 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. // getRuntimeOptionsType gets empty runtime options by the runtime type name.
func getRuntimeOptionsType(t string) interface{} { func getRuntimeOptionsType(t string) interface{} {
switch t { switch t {
case runcRuntimeV1: case plugin.RuntimeRuncV1:
fallthrough fallthrough
case runcRuntimeV2: case plugin.RuntimeRuncV2:
return &runcoptions.Options{} return &runcoptions.Options{}
case linuxRuntime: case plugin.RuntimeLinuxV1:
return &runctypes.RuncOptions{} return &runctypes.RuncOptions{}
default: default:
return &runtimeoptions.Options{} return &runtimeoptions.Options{}

View File

@ -21,6 +21,7 @@ import (
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime/linux/runctypes" "github.com/containerd/containerd/runtime/linux/runctypes"
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
@ -214,11 +215,11 @@ systemd_cgroup = true
no_pivot = true no_pivot = true
default_runtime_name = "default" default_runtime_name = "default"
[containerd.runtimes.legacy] [containerd.runtimes.legacy]
runtime_type = "` + linuxRuntime + `" runtime_type = "` + plugin.RuntimeLinuxV1 + `"
[containerd.runtimes.runc] [containerd.runtimes.runc]
runtime_type = "` + runcRuntimeV1 + `" runtime_type = "` + plugin.RuntimeRuncV1 + `"
[containerd.runtimes.runcv2] [containerd.runtimes.runcv2]
runtime_type = "` + runcRuntimeV2 + `" runtime_type = "` + plugin.RuntimeRuncV2 + `"
` `
nonNilOpts := ` nonNilOpts := `
systemd_cgroup = true systemd_cgroup = true
@ -226,18 +227,18 @@ systemd_cgroup = true
no_pivot = true no_pivot = true
default_runtime_name = "default" default_runtime_name = "default"
[containerd.runtimes.legacy] [containerd.runtimes.legacy]
runtime_type = "` + linuxRuntime + `" runtime_type = "` + plugin.RuntimeLinuxV1 + `"
[containerd.runtimes.legacy.options] [containerd.runtimes.legacy.options]
Runtime = "legacy" Runtime = "legacy"
RuntimeRoot = "/legacy" RuntimeRoot = "/legacy"
[containerd.runtimes.runc] [containerd.runtimes.runc]
runtime_type = "` + runcRuntimeV1 + `" runtime_type = "` + plugin.RuntimeRuncV1 + `"
[containerd.runtimes.runc.options] [containerd.runtimes.runc.options]
BinaryName = "runc" BinaryName = "runc"
Root = "/runc" Root = "/runc"
NoNewKeyring = true NoNewKeyring = true
[containerd.runtimes.runcv2] [containerd.runtimes.runcv2]
runtime_type = "` + runcRuntimeV2 + `" runtime_type = "` + plugin.RuntimeRuncV2 + `"
[containerd.runtimes.runcv2.options] [containerd.runtimes.runcv2.options]
BinaryName = "runc" BinaryName = "runc"
Root = "/runcv2" Root = "/runcv2"

View File

@ -27,6 +27,7 @@ import (
containerdio "github.com/containerd/containerd/cio" containerdio "github.com/containerd/containerd/cio"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
"github.com/containerd/containerd/plugin"
cni "github.com/containerd/go-cni" cni "github.com/containerd/go-cni"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
@ -266,7 +267,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
var taskOpts []containerd.NewTaskOpts var taskOpts []containerd.NewTaskOpts
// TODO(random-liu): Remove this after shim v1 is deprecated. // 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) taskOpts = append(taskOpts, containerd.WithNoPivotRoot)
} }
// We don't need stdio for sandbox container. // We don't need stdio for sandbox container.