mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Improve the implementation for UseLegacyConfig
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
@@ -70,18 +70,20 @@ func (c *ConfigV1) AddRuntime(name string, path string, setAsDefault bool) error
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "runtimes", name, "options", "BinaryName"}, path)
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "runtimes", name, "options", "Runtime"}, path)
|
||||
|
||||
if setAsDefault && c.UseDefaultRuntimeName {
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime_name"}, name)
|
||||
} else if setAsDefault {
|
||||
// Note: This is deprecated in containerd 1.4.0 and will be removed in 1.5.0
|
||||
if config.GetPath([]string{"plugins", "cri", "containerd", "default_runtime"}) == nil {
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "runtime_type"}, c.RuntimeType)
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "runtime_root"}, "")
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "runtime_engine"}, "")
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "privileged_without_host_devices"}, false)
|
||||
if setAsDefault {
|
||||
if !c.UseLegacyConfig {
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime_name"}, name)
|
||||
} else {
|
||||
// Note: This is deprecated in containerd 1.4.0 and will be removed in 1.5.0
|
||||
if config.GetPath([]string{"plugins", "cri", "containerd", "default_runtime"}) == nil {
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "runtime_type"}, c.RuntimeType)
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "runtime_root"}, "")
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "runtime_engine"}, "")
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "privileged_without_host_devices"}, false)
|
||||
}
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "options", "BinaryName"}, path)
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "options", "Runtime"}, path)
|
||||
}
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "options", "BinaryName"}, path)
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime", "options", "Runtime"}, path)
|
||||
}
|
||||
|
||||
*c.Tree = config
|
||||
|
||||
@@ -27,10 +27,15 @@ import (
|
||||
// Config represents the containerd config
|
||||
type Config struct {
|
||||
*toml.Tree
|
||||
Logger logger.Interface
|
||||
RuntimeType string
|
||||
UseDefaultRuntimeName bool
|
||||
ContainerAnnotations []string
|
||||
Logger logger.Interface
|
||||
RuntimeType string
|
||||
ContainerAnnotations []string
|
||||
// UseLegacyConfig indicates whether a config file pre v1.3 should be generated.
|
||||
// For version 1 config prior to containerd v1.4 the default runtime was
|
||||
// specified in a containerd.runtimes.default_runtime section.
|
||||
// This was deprecated in v1.4 in favour of containerd.default_runtime_name.
|
||||
// Support for this section has been removed in v2.0.
|
||||
UseLegacyConfig bool
|
||||
}
|
||||
|
||||
var _ engine.Interface = (*Config)(nil)
|
||||
@@ -73,14 +78,14 @@ func New(opts ...Option) (engine.Interface, error) {
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Tree: tomlConfig,
|
||||
Logger: b.logger,
|
||||
RuntimeType: b.runtimeType,
|
||||
UseDefaultRuntimeName: b.useLegacyConfig,
|
||||
ContainerAnnotations: b.containerAnnotations,
|
||||
Tree: tomlConfig,
|
||||
Logger: b.logger,
|
||||
RuntimeType: b.runtimeType,
|
||||
ContainerAnnotations: b.containerAnnotations,
|
||||
UseLegacyConfig: b.useLegacyConfig,
|
||||
}
|
||||
|
||||
version, err := cfg.parseVersion(b.useLegacyConfig)
|
||||
version, err := cfg.parseVersion()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse config version: %v", err)
|
||||
}
|
||||
@@ -95,9 +100,10 @@ func New(opts ...Option) (engine.Interface, error) {
|
||||
}
|
||||
|
||||
// parseVersion returns the version of the config
|
||||
func (c *Config) parseVersion(useLegacyConfig bool) (int, error) {
|
||||
func (c *Config) parseVersion() (int, error) {
|
||||
defaultVersion := 2
|
||||
if useLegacyConfig {
|
||||
// For legacy configs, we default to v1 configs.
|
||||
if c.UseLegacyConfig {
|
||||
defaultVersion = 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user