mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-30 00:11:59 +00:00
b8389283d5
This change updates the logic to populate the options for the nvidia runtime configs added to containerd or crio from a default runtime if this is specified and a runc entry is not found. This allows the default runtime values for settings such as SystemdCgroup to be applied correctly. Signed-off-by: Evan Lezar <elezar@nvidia.com>
147 lines
3.6 KiB
Go
147 lines
3.6 KiB
Go
/**
|
|
# Copyright 2024 NVIDIA CORPORATION
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
**/
|
|
|
|
package crio
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pelletier/go-toml"
|
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAddRuntime(t *testing.T) {
|
|
logger, _ := testlog.NewNullLogger()
|
|
testCases := []struct {
|
|
description string
|
|
config string
|
|
setAsDefault bool
|
|
configOverrides []map[string]interface{}
|
|
expectedConfig string
|
|
expectedError error
|
|
}{
|
|
{
|
|
description: "empty config not default runtime",
|
|
expectedConfig: `
|
|
[crio]
|
|
[crio.runtime.runtimes.test]
|
|
runtime_path = "/usr/bin/test"
|
|
runtime_type = "oci"
|
|
`,
|
|
expectedError: nil,
|
|
},
|
|
{
|
|
description: "options from runc are imported",
|
|
config: `
|
|
[crio]
|
|
[crio.runtime.runtimes.runc]
|
|
runtime_path = "/usr/bin/runc"
|
|
runtime_type = "runcoci"
|
|
runc_option = "option"
|
|
`,
|
|
expectedConfig: `
|
|
[crio]
|
|
[crio.runtime.runtimes.runc]
|
|
runtime_path = "/usr/bin/runc"
|
|
runtime_type = "runcoci"
|
|
runc_option = "option"
|
|
[crio.runtime.runtimes.test]
|
|
runtime_path = "/usr/bin/test"
|
|
runtime_type = "oci"
|
|
runc_option = "option"
|
|
`,
|
|
},
|
|
{
|
|
description: "options from default runtime are imported",
|
|
config: `
|
|
[crio]
|
|
[crio.runtime]
|
|
default_runtime = "default"
|
|
[crio.runtime.runtimes.default]
|
|
runtime_path = "/usr/bin/default"
|
|
runtime_type = "defaultoci"
|
|
default_option = "option"
|
|
`,
|
|
expectedConfig: `
|
|
[crio]
|
|
[crio.runtime]
|
|
default_runtime = "default"
|
|
[crio.runtime.runtimes.default]
|
|
runtime_path = "/usr/bin/default"
|
|
runtime_type = "defaultoci"
|
|
default_option = "option"
|
|
[crio.runtime.runtimes.test]
|
|
runtime_path = "/usr/bin/test"
|
|
runtime_type = "oci"
|
|
default_option = "option"
|
|
`,
|
|
},
|
|
{
|
|
description: "options from runc take precedence over default runtime",
|
|
config: `
|
|
[crio]
|
|
[crio.runtime]
|
|
default_runtime = "default"
|
|
[crio.runtime.runtimes.default]
|
|
runtime_path = "/usr/bin/default"
|
|
runtime_type = "defaultoci"
|
|
default_option = "option"
|
|
[crio.runtime.runtimes.runc]
|
|
runtime_path = "/usr/bin/runc"
|
|
runtime_type = "runcoci"
|
|
runc_option = "option"
|
|
`,
|
|
expectedConfig: `
|
|
[crio]
|
|
[crio.runtime]
|
|
default_runtime = "default"
|
|
[crio.runtime.runtimes.default]
|
|
runtime_path = "/usr/bin/default"
|
|
runtime_type = "defaultoci"
|
|
default_option = "option"
|
|
[crio.runtime.runtimes.runc]
|
|
runtime_path = "/usr/bin/runc"
|
|
runtime_type = "runcoci"
|
|
runc_option = "option"
|
|
[crio.runtime.runtimes.test]
|
|
runtime_path = "/usr/bin/test"
|
|
runtime_type = "oci"
|
|
runc_option = "option"
|
|
`,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.description, func(t *testing.T) {
|
|
config, err := toml.Load(tc.config)
|
|
require.NoError(t, err)
|
|
expectedConfig, err := toml.Load(tc.expectedConfig)
|
|
require.NoError(t, err)
|
|
|
|
c := &Config{
|
|
Logger: logger,
|
|
Tree: config,
|
|
}
|
|
|
|
err = c.AddRuntime("test", "/usr/bin/test", tc.setAsDefault, tc.configOverrides...)
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, expectedConfig.String(), config.String())
|
|
})
|
|
}
|
|
}
|