mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-02-02 19:15:41 +00:00
Merge branch 'fix-binary-name' into 'main'
Use BinaryName for v1 containerd runtime config See merge request nvidia/container-toolkit/container-toolkit!159
This commit is contained in:
commit
ab23fc52db
@ -28,9 +28,8 @@ type UpdateReverter interface {
|
|||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
*toml.Tree
|
*toml.Tree
|
||||||
version int64
|
version int64
|
||||||
cri string
|
cri string
|
||||||
binaryKey string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update adds the specified runtime class to the the containerd config.
|
// update adds the specified runtime class to the the containerd config.
|
||||||
@ -48,7 +47,10 @@ func (config *config) update(runtimeClass string, runtimeType string, runtimeBin
|
|||||||
config.SetPath(runtimeClassPath, runc)
|
config.SetPath(runtimeClassPath, runc)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.initRuntime(runtimeClassPath, runtimeType, runtimeBinary)
|
config.initRuntime(runtimeClassPath, runtimeType, "BinaryName", runtimeBinary)
|
||||||
|
if config.version == 1 {
|
||||||
|
config.initRuntime(runtimeClassPath, runtimeType, "Runtime", runtimeBinary)
|
||||||
|
}
|
||||||
|
|
||||||
if setAsDefault {
|
if setAsDefault {
|
||||||
defaultRuntimeNamePath := config.defaultRuntimeNamePath()
|
defaultRuntimeNamePath := config.defaultRuntimeNamePath()
|
||||||
@ -83,7 +85,7 @@ func (config *config) revert(runtimeClass string) {
|
|||||||
|
|
||||||
// initRuntime creates a runtime config if it does not exist and ensures that the
|
// initRuntime creates a runtime config if it does not exist and ensures that the
|
||||||
// runtimes binary path is specified.
|
// runtimes binary path is specified.
|
||||||
func (config *config) initRuntime(path []string, runtimeType string, binary string) {
|
func (config *config) initRuntime(path []string, runtimeType string, binaryKey string, binary string) {
|
||||||
if config.GetPath(path) == nil {
|
if config.GetPath(path) == nil {
|
||||||
config.SetPath(append(path, "runtime_type"), runtimeType)
|
config.SetPath(append(path, "runtime_type"), runtimeType)
|
||||||
config.SetPath(append(path, "runtime_root"), "")
|
config.SetPath(append(path, "runtime_root"), "")
|
||||||
@ -91,7 +93,7 @@ func (config *config) initRuntime(path []string, runtimeType string, binary stri
|
|||||||
config.SetPath(append(path, "privileged_without_host_devices"), false)
|
config.SetPath(append(path, "privileged_without_host_devices"), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
binaryPath := append(path, "options", config.binaryKey)
|
binaryPath := append(path, "options", binaryKey)
|
||||||
config.SetPath(binaryPath, binary)
|
config.SetPath(binaryPath, binary)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,10 +101,6 @@ func (config config) runcPath() []string {
|
|||||||
return config.runtimeClassPath("runc")
|
return config.runtimeClassPath("runc")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config config) runtimeClassBinaryPath(runtimeClass string) []string {
|
|
||||||
return append(config.runtimeClassPath(runtimeClass), "options", config.binaryKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config config) runtimeClassPath(runtimeClass string) []string {
|
func (config config) runtimeClassPath(runtimeClass string) []string {
|
||||||
return append(config.containerdPath(), "runtimes", runtimeClass)
|
return append(config.containerdPath(), "runtimes", runtimeClass)
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,9 @@ type configV1 struct {
|
|||||||
func newConfigV1(cfg *toml.Tree) UpdateReverter {
|
func newConfigV1(cfg *toml.Tree) UpdateReverter {
|
||||||
c := configV1{
|
c := configV1{
|
||||||
config: config{
|
config: config{
|
||||||
Tree: cfg,
|
Tree: cfg,
|
||||||
version: 1,
|
version: 1,
|
||||||
cri: "cri",
|
cri: "cri",
|
||||||
binaryKey: "Runtime",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +67,8 @@ func (config *configV1) Update(o *options) error {
|
|||||||
|
|
||||||
log.Warnf("Setting default_runtime is deprecated")
|
log.Warnf("Setting default_runtime is deprecated")
|
||||||
defaultRuntimePath := append(config.containerdPath(), "default_runtime")
|
defaultRuntimePath := append(config.containerdPath(), "default_runtime")
|
||||||
config.initRuntime(defaultRuntimePath, o.runtimeType, runtimeBinary)
|
config.initRuntime(defaultRuntimePath, o.runtimeType, "Runtime", runtimeBinary)
|
||||||
|
config.initRuntime(defaultRuntimePath, o.runtimeType, "BinaryName", runtimeBinary)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -85,6 +85,14 @@ func (config *configV1) Revert(o *options) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if runtime, ok := config.GetPath(append(defaultRuntimeOptionsPath, "BinaryName")).(string); ok {
|
||||||
|
for _, runtimeBinary := range o.getRuntimeBinaries() {
|
||||||
|
if path.Base(runtimeBinary) == path.Base(runtime) {
|
||||||
|
config.DeletePath(append(defaultRuntimeOptionsPath, "BinaryName"))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if options, ok := config.GetPath(defaultRuntimeOptionsPath).(*toml.Tree); ok {
|
if options, ok := config.GetPath(defaultRuntimeOptionsPath).(*toml.Tree); ok {
|
||||||
if len(options.Keys()) == 0 {
|
if len(options.Keys()) == 0 {
|
||||||
|
@ -110,7 +110,7 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
|
|||||||
if tc.expectedDefaultRuntimeBinary == nil {
|
if tc.expectedDefaultRuntimeBinary == nil {
|
||||||
require.Nil(t, defaultRuntime, "%d: %v", i, tc)
|
require.Nil(t, defaultRuntime, "%d: %v", i, tc)
|
||||||
} else {
|
} else {
|
||||||
expected, err := runtimeTomlConfigV1(tc.expectedDefaultRuntimeBinary.(string))
|
expected, err := defaultRuntimeTomlConfigV1(tc.expectedDefaultRuntimeBinary.(string))
|
||||||
require.NoError(t, err, "%d: %v", i, tc)
|
require.NoError(t, err, "%d: %v", i, tc)
|
||||||
|
|
||||||
configContents, _ := toml.Marshal(defaultRuntime.(*toml.Tree))
|
configContents, _ := toml.Marshal(defaultRuntime.(*toml.Tree))
|
||||||
@ -291,7 +291,7 @@ func TestRevertV1Config(t *testing.T) {
|
|||||||
"nvidia": runtimeMapV1("/test/runtime/dir/nvidia-container-runtime"),
|
"nvidia": runtimeMapV1("/test/runtime/dir/nvidia-container-runtime"),
|
||||||
"nvidia-experimental": runtimeMapV1("/test/runtime/dir/nvidia-container-runtime-experimental"),
|
"nvidia-experimental": runtimeMapV1("/test/runtime/dir/nvidia-container-runtime-experimental"),
|
||||||
},
|
},
|
||||||
"default_runtime": runtimeMapV1("/test/runtime/dir/nvidia-container-runtime"),
|
"default_runtime": defaultRuntimeV1("/test/runtime/dir/nvidia-container-runtime"),
|
||||||
"default_runtime_name": "nvidia",
|
"default_runtime_name": "nvidia",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -325,6 +325,23 @@ func runtimeTomlConfigV1(binary string) (*toml.Tree, error) {
|
|||||||
return toml.TreeFromMap(runtimeMapV1(binary))
|
return toml.TreeFromMap(runtimeMapV1(binary))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defaultRuntimeTomlConfigV1(binary string) (*toml.Tree, error) {
|
||||||
|
return toml.TreeFromMap(defaultRuntimeV1(binary))
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultRuntimeV1(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,
|
||||||
|
"Runtime": binary,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runtimeMapV1(binary string) map[string]interface{} {
|
func runtimeMapV1(binary string) map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"runtime_type": runtimeType,
|
"runtime_type": runtimeType,
|
||||||
@ -332,7 +349,8 @@ func runtimeMapV1(binary string) map[string]interface{} {
|
|||||||
"runtime_engine": "",
|
"runtime_engine": "",
|
||||||
"privileged_without_host_devices": false,
|
"privileged_without_host_devices": false,
|
||||||
"options": map[string]interface{}{
|
"options": map[string]interface{}{
|
||||||
"Runtime": binary,
|
"BinaryName": binary,
|
||||||
|
"Runtime": binary,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,6 +377,7 @@ func runcRuntimeConfigMapV1(binary string) map[string]interface{} {
|
|||||||
"privileged_without_host_devices": true,
|
"privileged_without_host_devices": true,
|
||||||
"options": map[string]interface{}{
|
"options": map[string]interface{}{
|
||||||
"runc-option": "value",
|
"runc-option": "value",
|
||||||
|
"BinaryName": binary,
|
||||||
"Runtime": binary,
|
"Runtime": binary,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,9 @@ type configV2 struct {
|
|||||||
func newConfigV2(cfg *toml.Tree) UpdateReverter {
|
func newConfigV2(cfg *toml.Tree) UpdateReverter {
|
||||||
c := configV2{
|
c := configV2{
|
||||||
config: config{
|
config: config{
|
||||||
Tree: cfg,
|
Tree: cfg,
|
||||||
version: 2,
|
version: 2,
|
||||||
cri: "io.containerd.grpc.v1.cri",
|
cri: "io.containerd.grpc.v1.cri",
|
||||||
binaryKey: "BinaryName",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user