Skip to content

Commit bcf9c2e

Browse files
committed
Add support for RUNTIME=none to disable runtime config in the nvidia-container-toolkit
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 83cffd9 commit bcf9c2e

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

controllers/object_controls.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,14 +1314,19 @@ func TransformToolkit(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n
13141314
}
13151315
}
13161316

1317-
if len(config.Toolkit.Env) > 0 {
1318-
for _, env := range config.Toolkit.Env {
1319-
setContainerEnv(toolkitMainContainer, env.Name, env.Value)
1317+
// configure runtime
1318+
runtime := n.runtime.String()
1319+
// Update the main container environment from the user-specified values.
1320+
for _, env := range config.Toolkit.Env {
1321+
if env.Name == "RUNTIME" {
1322+
// If the user has specified the runtime, we overide the detected
1323+
// value.
1324+
// TODO: Add logging.
1325+
runtime = env.Value
13201326
}
1327+
setContainerEnv(toolkitMainContainer, env.Name, env.Value)
13211328
}
13221329

1323-
// configure runtime
1324-
runtime := n.runtime.String()
13251330
err = transformForRuntime(obj, config, runtime, toolkitMainContainer)
13261331
if err != nil {
13271332
return fmt.Errorf("error transforming toolkit daemonset : %w", err)
@@ -1332,6 +1337,11 @@ func TransformToolkit(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n
13321337

13331338
func transformForRuntime(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, runtime string, container *corev1.Container) error {
13341339
setContainerEnv(container, "RUNTIME", runtime)
1340+
// If the user has explicitly requested 'none' as a runtime, we make no
1341+
// additional changes to the container.
1342+
if runtime == "none" {
1343+
return nil
1344+
}
13351345

13361346
if runtime == gpuv1.Containerd.String() {
13371347
// Set the runtime class name that is to be configured for containerd

controllers/transforms_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,36 @@ func TestTransformToolkit(t *testing.T) {
10021002
WithHostPathVolume("crio-config", "/etc/crio", ptr.To(corev1.HostPathDirectoryOrCreate)).
10031003
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)),
10041004
},
1005+
{
1006+
description: "transform nvidia-container-toolkit-ctr container with none runtime",
1007+
ds: NewDaemonset().
1008+
WithContainer(corev1.Container{Name: "nvidia-container-toolkit-ctr"}),
1009+
runtime: gpuv1.Containerd,
1010+
cpSpec: &gpuv1.ClusterPolicySpec{
1011+
Toolkit: gpuv1.ToolkitSpec{
1012+
Repository: "nvcr.io/nvidia/cloud-native",
1013+
Image: "nvidia-container-toolkit",
1014+
Version: "v1.0.0",
1015+
Env: []gpuv1.EnvVar{
1016+
{Name: "RUNTIME", Value: "none"},
1017+
},
1018+
},
1019+
},
1020+
expectedDs: NewDaemonset().
1021+
WithContainer(corev1.Container{
1022+
Name: "nvidia-container-toolkit-ctr",
1023+
Image: "nvcr.io/nvidia/cloud-native/nvidia-container-toolkit:v1.0.0",
1024+
ImagePullPolicy: corev1.PullIfNotPresent,
1025+
Env: []corev1.EnvVar{
1026+
{Name: "CDI_ENABLED", Value: "true"},
1027+
{Name: "NVIDIA_RUNTIME_SET_AS_DEFAULT", Value: "false"},
1028+
{Name: "NVIDIA_CONTAINER_RUNTIME_MODE", Value: "cdi"},
1029+
{Name: "CRIO_CONFIG_MODE", Value: "config"},
1030+
{Name: "RUNTIME", Value: "none"},
1031+
},
1032+
VolumeMounts: nil,
1033+
}),
1034+
},
10051035
}
10061036

10071037
for _, tc := range testCases {

0 commit comments

Comments
 (0)