mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-01-22 10:35:38 +00:00
Improve the implementation for UseLegacyConfig
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
4b352e6bac
commit
7598fe14bc
@ -70,9 +70,10 @@ 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 {
|
||||
if setAsDefault {
|
||||
if !c.UseLegacyConfig {
|
||||
config.SetPath([]string{"plugins", "cri", "containerd", "default_runtime_name"}, name)
|
||||
} else if setAsDefault {
|
||||
} 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)
|
||||
@ -83,6 +84,7 @@ func (c *ConfigV1) AddRuntime(name string, path string, setAsDefault bool) error
|
||||
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
|
||||
return nil
|
||||
|
@ -29,8 +29,13 @@ type Config struct {
|
||||
*toml.Tree
|
||||
Logger logger.Interface
|
||||
RuntimeType string
|
||||
UseDefaultRuntimeName bool
|
||||
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)
|
||||
@ -76,11 +81,11 @@ func New(opts ...Option) (engine.Interface, error) {
|
||||
Tree: tomlConfig,
|
||||
Logger: b.logger,
|
||||
RuntimeType: b.runtimeType,
|
||||
UseDefaultRuntimeName: b.useLegacyConfig,
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
|
||||
v1 := &containerd.ConfigV1{
|
||||
Logger: logger,
|
||||
Tree: cfg,
|
||||
UseDefaultRuntimeName: !tc.legacyConfig,
|
||||
UseLegacyConfig: tc.legacyConfig,
|
||||
RuntimeType: runtimeType,
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ func TestUpdateV1Config(t *testing.T) {
|
||||
v1 := &containerd.ConfigV1{
|
||||
Logger: logger,
|
||||
Tree: cfg,
|
||||
UseDefaultRuntimeName: true,
|
||||
UseLegacyConfig: true,
|
||||
RuntimeType: runtimeType,
|
||||
ContainerAnnotations: []string{"cdi.k8s.io/*"},
|
||||
}
|
||||
@ -399,7 +399,7 @@ func TestUpdateV1ConfigWithRuncPresent(t *testing.T) {
|
||||
v1 := &containerd.ConfigV1{
|
||||
Logger: logger,
|
||||
Tree: cfg,
|
||||
UseDefaultRuntimeName: true,
|
||||
UseLegacyConfig: true,
|
||||
RuntimeType: runtimeType,
|
||||
ContainerAnnotations: []string{"cdi.k8s.io/*"},
|
||||
}
|
||||
@ -477,7 +477,7 @@ func TestRevertV1Config(t *testing.T) {
|
||||
|
||||
v1 := &containerd.ConfigV1{
|
||||
Tree: cfg,
|
||||
UseDefaultRuntimeName: true,
|
||||
UseLegacyConfig: true,
|
||||
RuntimeType: runtimeType,
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,10 @@ func Flags(opts *Options) []cli.Flag {
|
||||
flags := []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "use-legacy-config",
|
||||
Usage: "Specify whether a legacy (pre v1.3) config should be used",
|
||||
Usage: "Specify whether a legacy (pre v1.3) config should be used. " +
|
||||
"This ensures that a version 1 container config is created by default and that the " +
|
||||
"containerd.runtimes.default_runtime config section is used to define the default " +
|
||||
"runtime instead of container.default_runtime_name.",
|
||||
Destination: &opts.useLegacyConfig,
|
||||
EnvVars: []string{"CONTAINERD_USE_LEGACY_CONFIG"},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user