2021-10-11 14:31:02 +00:00
|
|
|
/**
|
|
|
|
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
*/
|
|
|
|
|
2024-09-27 08:59:01 +00:00
|
|
|
package containerd
|
2021-10-11 14:31:02 +00:00
|
|
|
|
|
|
|
import (
|
2023-02-23 20:01:24 +00:00
|
|
|
"fmt"
|
2021-10-11 14:31:02 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-07-02 08:26:41 +00:00
|
|
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
2021-10-11 14:31:02 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-12-01 01:10:10 +00:00
|
|
|
|
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
|
2024-08-08 14:27:07 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
|
2023-12-01 01:10:10 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/tools/container"
|
2021-10-11 14:31:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
runtimeType = "runtime_type"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpdateV2ConfigDefaultRuntime(t *testing.T) {
|
2024-07-02 08:26:41 +00:00
|
|
|
logger, _ := testlog.NewNullLogger()
|
2021-10-11 14:31:02 +00:00
|
|
|
const runtimeDir = "/test/runtime/dir"
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
setAsDefault bool
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName string
|
2021-10-11 14:31:02 +00:00
|
|
|
expectedDefaultRuntimeName interface{}
|
|
|
|
}{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
setAsDefault: false,
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "nvidia",
|
2021-10-11 14:31:02 +00:00
|
|
|
expectedDefaultRuntimeName: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
setAsDefault: false,
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "NAME",
|
2021-10-11 14:31:02 +00:00
|
|
|
expectedDefaultRuntimeName: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
setAsDefault: true,
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "nvidia",
|
2021-10-11 14:31:02 +00:00
|
|
|
expectedDefaultRuntimeName: "nvidia",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
setAsDefault: true,
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "NAME",
|
2021-10-11 14:31:02 +00:00
|
|
|
expectedDefaultRuntimeName: "NAME",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2023-02-24 09:06:59 +00:00
|
|
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
2024-09-27 08:59:01 +00:00
|
|
|
o := &container.Options{
|
|
|
|
RuntimeName: tc.runtimeName,
|
|
|
|
RuntimeDir: runtimeDir,
|
|
|
|
SetAsDefault: tc.setAsDefault,
|
2023-02-24 09:06:59 +00:00
|
|
|
}
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
cfg, err := toml.LoadMap(map[string]interface{}{})
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-02-24 09:06:59 +00:00
|
|
|
v2 := &containerd.Config{
|
2024-07-02 08:26:41 +00:00
|
|
|
Logger: logger,
|
2024-08-08 14:27:07 +00:00
|
|
|
Tree: cfg,
|
2023-02-24 09:06:59 +00:00
|
|
|
RuntimeType: runtimeType,
|
|
|
|
}
|
2023-02-23 20:01:24 +00:00
|
|
|
|
2023-06-09 15:17:54 +00:00
|
|
|
err = o.UpdateConfig(v2)
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
defaultRuntimeName := cfg.GetPath([]string{"plugins", "io.containerd.grpc.v1.cri", "containerd", "default_runtime_name"})
|
2023-03-01 14:06:28 +00:00
|
|
|
require.EqualValues(t, tc.expectedDefaultRuntimeName, defaultRuntimeName)
|
2023-02-24 09:06:59 +00:00
|
|
|
})
|
2021-10-11 14:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateV2Config(t *testing.T) {
|
2024-07-02 08:26:41 +00:00
|
|
|
logger, _ := testlog.NewNullLogger()
|
2021-10-11 14:31:02 +00:00
|
|
|
const runtimeDir = "/test/runtime/dir"
|
|
|
|
|
|
|
|
testCases := []struct {
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName string
|
2023-03-01 14:06:28 +00:00
|
|
|
expectedConfig map[string]interface{}
|
2021-10-11 14:31:02 +00:00
|
|
|
}{
|
|
|
|
{
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "nvidia",
|
2023-03-01 14:06:28 +00:00
|
|
|
expectedConfig: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
|
|
|
"nvidia": map[string]interface{}{
|
|
|
|
"runtime_type": "runtime_type",
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-cdi": map[string]interface{}{
|
|
|
|
"runtime_type": "runtime_type",
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.cdi",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-legacy": map[string]interface{}{
|
|
|
|
"runtime_type": "runtime_type",
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.legacy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "NAME",
|
2023-03-01 14:06:28 +00:00
|
|
|
expectedConfig: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
|
|
|
"NAME": map[string]interface{}{
|
|
|
|
"runtime_type": "runtime_type",
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-cdi": map[string]interface{}{
|
|
|
|
"runtime_type": "runtime_type",
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.cdi",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-legacy": map[string]interface{}{
|
|
|
|
"runtime_type": "runtime_type",
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.legacy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2023-03-01 14:06:28 +00:00
|
|
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
2024-09-27 08:59:01 +00:00
|
|
|
o := &container.Options{
|
|
|
|
RuntimeName: tc.runtimeName,
|
|
|
|
RuntimeDir: runtimeDir,
|
2023-03-01 14:06:28 +00:00
|
|
|
}
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
cfg, err := toml.LoadMap(map[string]interface{}{})
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-03-01 14:06:28 +00:00
|
|
|
v2 := &containerd.Config{
|
2024-07-02 08:26:41 +00:00
|
|
|
Logger: logger,
|
2024-08-08 14:27:07 +00:00
|
|
|
Tree: cfg,
|
2024-09-27 08:59:01 +00:00
|
|
|
RuntimeType: runtimeType,
|
2023-03-23 19:12:23 +00:00
|
|
|
ContainerAnnotations: []string{"cdi.k8s.io/*"},
|
2023-03-01 14:06:28 +00:00
|
|
|
}
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-06-09 15:17:54 +00:00
|
|
|
err = o.UpdateConfig(v2)
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-03-01 14:06:28 +00:00
|
|
|
expected, err := toml.TreeFromMap(tc.expectedConfig)
|
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
require.Equal(t, expected.String(), cfg.String())
|
2023-03-01 14:06:28 +00:00
|
|
|
})
|
2021-10-11 14:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateV2ConfigWithRuncPresent(t *testing.T) {
|
2024-07-02 08:26:41 +00:00
|
|
|
logger, _ := testlog.NewNullLogger()
|
2021-10-11 14:31:02 +00:00
|
|
|
const runtimeDir = "/test/runtime/dir"
|
|
|
|
|
|
|
|
testCases := []struct {
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName string
|
2023-03-01 14:06:28 +00:00
|
|
|
expectedConfig map[string]interface{}
|
2021-10-11 14:31:02 +00:00
|
|
|
}{
|
|
|
|
{
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "nvidia",
|
2023-03-01 14:06:28 +00:00
|
|
|
expectedConfig: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
|
|
|
"runc": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/runc-binary",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-cdi": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.cdi",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-legacy": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.legacy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-09 15:17:54 +00:00
|
|
|
runtimeName: "NAME",
|
2023-03-01 14:06:28 +00:00
|
|
|
expectedConfig: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
|
|
|
"runc": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/runc-binary",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"NAME": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-cdi": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.cdi",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nvidia-legacy": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"container_annotations": []string{"cdi.k8s.io/*"},
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": "/test/runtime/dir/nvidia-container-runtime.legacy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2023-02-23 20:01:24 +00:00
|
|
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
2024-09-27 08:59:01 +00:00
|
|
|
o := &container.Options{
|
|
|
|
RuntimeName: tc.runtimeName,
|
|
|
|
RuntimeDir: runtimeDir,
|
2023-02-23 20:01:24 +00:00
|
|
|
}
|
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
cfg, err := toml.LoadMap(runcConfigMapV2("/runc-binary"))
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-02-23 20:01:24 +00:00
|
|
|
v2 := &containerd.Config{
|
2024-07-02 08:26:41 +00:00
|
|
|
Logger: logger,
|
2024-08-08 14:27:07 +00:00
|
|
|
Tree: cfg,
|
2023-03-23 19:12:23 +00:00
|
|
|
RuntimeType: runtimeType,
|
|
|
|
ContainerAnnotations: []string{"cdi.k8s.io/*"},
|
2023-02-23 20:01:24 +00:00
|
|
|
}
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-06-09 15:17:54 +00:00
|
|
|
err = o.UpdateConfig(v2)
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-03-01 14:06:28 +00:00
|
|
|
expected, err := toml.TreeFromMap(tc.expectedConfig)
|
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
require.Equal(t, expected.String(), cfg.String())
|
2023-02-23 20:01:24 +00:00
|
|
|
})
|
2021-10-11 14:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRevertV2Config(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
config map[string]interface {
|
|
|
|
}
|
|
|
|
expected map[string]interface{}
|
|
|
|
}{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
config: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
2022-11-07 11:22:30 +00:00
|
|
|
"nvidia": runtimeMapV2("/test/runtime/dir/nvidia-container-runtime"),
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: map[string]interface{}{
|
|
|
|
"version": int64(2),
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
2022-11-07 11:22:30 +00:00
|
|
|
"nvidia": runtimeMapV2("/test/runtime/dir/nvidia-container-runtime"),
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
"default_runtime_name": "nvidia",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2023-02-24 09:06:59 +00:00
|
|
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
2024-09-27 08:59:01 +00:00
|
|
|
o := &container.Options{
|
|
|
|
RuntimeName: "nvidia",
|
2023-02-24 09:06:59 +00:00
|
|
|
}
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
cfg, err := toml.LoadMap(tc.config)
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-02-24 09:06:59 +00:00
|
|
|
expected, err := toml.TreeFromMap(tc.expected)
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-02-24 09:06:59 +00:00
|
|
|
v2 := &containerd.Config{
|
2024-08-08 14:27:07 +00:00
|
|
|
Tree: cfg,
|
2023-02-24 09:06:59 +00:00
|
|
|
RuntimeType: runtimeType,
|
|
|
|
}
|
2023-02-23 20:01:24 +00:00
|
|
|
|
2023-06-09 15:17:54 +00:00
|
|
|
err = o.RevertConfig(v2)
|
2023-03-01 14:06:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2024-08-08 14:27:07 +00:00
|
|
|
configContents, _ := toml.Marshal(cfg)
|
2023-02-24 09:06:59 +00:00
|
|
|
expectedContents, _ := toml.Marshal(expected)
|
2021-10-11 14:31:02 +00:00
|
|
|
|
2023-03-01 14:06:28 +00:00
|
|
|
require.Equal(t, string(expectedContents), string(configContents))
|
2023-02-24 09:06:59 +00:00
|
|
|
})
|
2021-10-11 14:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runtimeMapV2(binary string) map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"runtime_type": runtimeType,
|
|
|
|
"runtime_root": "",
|
|
|
|
"runtime_engine": "",
|
|
|
|
"privileged_without_host_devices": false,
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"BinaryName": binary,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runcConfigMapV2(binary string) map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"plugins": map[string]interface{}{
|
|
|
|
"io.containerd.grpc.v1.cri": map[string]interface{}{
|
|
|
|
"containerd": map[string]interface{}{
|
|
|
|
"runtimes": map[string]interface{}{
|
2023-03-01 14:06:28 +00:00
|
|
|
"runc": map[string]interface{}{
|
|
|
|
"runtime_type": "runc_runtime_type",
|
|
|
|
"runtime_root": "runc_runtime_root",
|
|
|
|
"runtime_engine": "runc_runtime_engine",
|
|
|
|
"privileged_without_host_devices": true,
|
|
|
|
"options": map[string]interface{}{
|
|
|
|
"runc-option": "value",
|
|
|
|
"BinaryName": binary,
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 14:31:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|