@@ -24,6 +24,7 @@ import (
2424 "time"
2525
2626 "github.com/containerd/containerd/log"
27+ "github.com/containerd/containerd/pkg/deprecation"
2728 "github.com/containerd/containerd/plugin"
2829)
2930
@@ -338,7 +339,8 @@ const (
338339)
339340
340341// ValidatePluginConfig validates the given plugin configuration.
341- func ValidatePluginConfig (ctx context.Context , c * PluginConfig ) error {
342+ func ValidatePluginConfig (ctx context.Context , c * PluginConfig ) ([]deprecation.Warning , error ) {
343+ var warnings []deprecation.Warning
342344 if c .ContainerdConfig .Runtimes == nil {
343345 c .ContainerdConfig .Runtimes = make (map [string ]Runtime )
344346 }
@@ -347,7 +349,7 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
347349 if c .ContainerdConfig .UntrustedWorkloadRuntime .Type != "" {
348350 log .G (ctx ).Warning ("`untrusted_workload_runtime` is deprecated, please use `untrusted` runtime in `runtimes` instead" )
349351 if _ , ok := c .ContainerdConfig .Runtimes [RuntimeUntrusted ]; ok {
350- return fmt .Errorf ("conflicting definitions: configuration includes both `untrusted_workload_runtime` and `runtimes[%q]`" , RuntimeUntrusted )
352+ return warnings , fmt .Errorf ("conflicting definitions: configuration includes both `untrusted_workload_runtime` and `runtimes[%q]`" , RuntimeUntrusted )
351353 }
352354 c .ContainerdConfig .Runtimes [RuntimeUntrusted ] = c .ContainerdConfig .UntrustedWorkloadRuntime
353355 }
@@ -361,36 +363,36 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
361363
362364 // Validation for default_runtime_name
363365 if c .ContainerdConfig .DefaultRuntimeName == "" {
364- return errors .New ("`default_runtime_name` is empty" )
366+ return warnings , errors .New ("`default_runtime_name` is empty" )
365367 }
366368 if _ , ok := c .ContainerdConfig .Runtimes [c .ContainerdConfig .DefaultRuntimeName ]; ! ok {
367- return fmt .Errorf ("no corresponding runtime configured in `containerd.runtimes` for `containerd` `default_runtime_name = \" %s\" " , c .ContainerdConfig .DefaultRuntimeName )
369+ return warnings , fmt .Errorf ("no corresponding runtime configured in `containerd.runtimes` for `containerd` `default_runtime_name = \" %s\" " , c .ContainerdConfig .DefaultRuntimeName )
368370 }
369371
370372 // Validation for deprecated runtime options.
371373 if c .SystemdCgroup {
372374 if c .ContainerdConfig .Runtimes [c .ContainerdConfig .DefaultRuntimeName ].Type != plugin .RuntimeLinuxV1 {
373- return fmt .Errorf ("`systemd_cgroup` only works for runtime %s" , plugin .RuntimeLinuxV1 )
375+ return warnings , fmt .Errorf ("`systemd_cgroup` only works for runtime %s" , plugin .RuntimeLinuxV1 )
374376 }
375377 log .G (ctx ).Warning ("`systemd_cgroup` is deprecated, please use runtime `options` instead" )
376378 }
377379 if c .NoPivot {
378380 if c .ContainerdConfig .Runtimes [c .ContainerdConfig .DefaultRuntimeName ].Type != plugin .RuntimeLinuxV1 {
379- return fmt .Errorf ("`no_pivot` only works for runtime %s" , plugin .RuntimeLinuxV1 )
381+ return warnings , fmt .Errorf ("`no_pivot` only works for runtime %s" , plugin .RuntimeLinuxV1 )
380382 }
381383 // NoPivot can't be deprecated yet, because there is no alternative config option
382384 // for `io.containerd.runtime.v1.linux`.
383385 }
384386 for _ , r := range c .ContainerdConfig .Runtimes {
385387 if r .Engine != "" {
386388 if r .Type != plugin .RuntimeLinuxV1 {
387- return fmt .Errorf ("`runtime_engine` only works for runtime %s" , plugin .RuntimeLinuxV1 )
389+ return warnings , fmt .Errorf ("`runtime_engine` only works for runtime %s" , plugin .RuntimeLinuxV1 )
388390 }
389391 log .G (ctx ).Warning ("`runtime_engine` is deprecated, please use runtime `options` instead" )
390392 }
391393 if r .Root != "" {
392394 if r .Type != plugin .RuntimeLinuxV1 {
393- return fmt .Errorf ("`runtime_root` only works for runtime %s" , plugin .RuntimeLinuxV1 )
395+ return warnings , fmt .Errorf ("`runtime_root` only works for runtime %s" , plugin .RuntimeLinuxV1 )
394396 }
395397 log .G (ctx ).Warning ("`runtime_root` is deprecated, please use runtime `options` instead" )
396398 }
@@ -399,7 +401,7 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
399401 useConfigPath := c .Registry .ConfigPath != ""
400402 if len (c .Registry .Mirrors ) > 0 {
401403 if useConfigPath {
402- return errors .New ("`mirrors` cannot be set when `config_path` is provided" )
404+ return warnings , errors .New ("`mirrors` cannot be set when `config_path` is provided" )
403405 }
404406 log .G (ctx ).Warning ("`mirrors` is deprecated, please use `config_path` instead" )
405407 }
@@ -412,7 +414,7 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
412414 }
413415 if hasDeprecatedTLS {
414416 if useConfigPath {
415- return errors .New ("`configs.tls` cannot be set when `config_path` is provided" )
417+ return warnings , errors .New ("`configs.tls` cannot be set when `config_path` is provided" )
416418 }
417419 log .G (ctx ).Warning ("`configs.tls` is deprecated, please use `config_path` instead" )
418420 }
@@ -426,7 +428,7 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
426428 auth := auth
427429 u , err := url .Parse (endpoint )
428430 if err != nil {
429- return fmt .Errorf ("failed to parse registry url %q from `registry.auths`: %w" , endpoint , err )
431+ return warnings , fmt .Errorf ("failed to parse registry url %q from `registry.auths`: %w" , endpoint , err )
430432 }
431433 if u .Scheme != "" {
432434 // Do not include the scheme in the new registry config.
@@ -442,8 +444,8 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
442444 // Validation for stream_idle_timeout
443445 if c .StreamIdleTimeout != "" {
444446 if _ , err := time .ParseDuration (c .StreamIdleTimeout ); err != nil {
445- return fmt .Errorf ("invalid stream idle timeout: %w" , err )
447+ return warnings , fmt .Errorf ("invalid stream idle timeout: %w" , err )
446448 }
447449 }
448- return nil
450+ return warnings , nil
449451}
0 commit comments