Skip to content

Commit be5904e

Browse files
committed
Add a check for NO_RUNTIME_CONFIG=true to disable runtime config in the nvidia-container-toolkit
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent a7ebf09 commit be5904e

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

controllers/object_controls.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,14 +1366,29 @@ func TransformToolkit(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n
13661366
}
13671367
}
13681368

1369-
if len(config.Toolkit.Env) > 0 {
1370-
for _, env := range config.Toolkit.Env {
1371-
setContainerEnv(toolkitMainContainer, env.Name, env.Value)
1372-
}
1373-
}
1374-
13751369
// configure runtime
13761370
runtime := n.runtime.String()
1371+
var noRuntimeConfig bool
1372+
// Update the main container environment from the user-specified values.
1373+
for _, env := range config.Toolkit.Env {
1374+
switch env.Name {
1375+
case "RUNTIME":
1376+
// If the user has specified the runtime, we overide the detected
1377+
// value.
1378+
// TODO: Add logging.
1379+
runtime = env.Value
1380+
case "NO_RUNTIME_CONFIG":
1381+
noRuntimeConfig = func() bool {
1382+
v, _ := strconv.ParseBool(env.Value)
1383+
return v
1384+
}()
1385+
}
1386+
setContainerEnv(toolkitMainContainer, env.Name, env.Value)
1387+
}
1388+
1389+
if noRuntimeConfig {
1390+
return nil
1391+
}
13771392
err = transformForRuntime(obj, config, runtime, toolkitMainContainer)
13781393
if err != nil {
13791394
return fmt.Errorf("error transforming toolkit daemonset : %w", err)

controllers/transforms_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,36 @@ func TestTransformToolkit(t *testing.T) {
10101010
expectedError: errors.New(`failed to find toolkit container "nvidia-container-toolkit-ctr"`),
10111011
expectedDs: NewDaemonset(),
10121012
},
1013+
{
1014+
description: "transform nvidia-container-toolkit-ctr container with no-runtime-config",
1015+
ds: NewDaemonset().
1016+
WithContainer(corev1.Container{Name: "nvidia-container-toolkit-ctr"}),
1017+
runtime: gpuv1.Containerd,
1018+
cpSpec: &gpuv1.ClusterPolicySpec{
1019+
Toolkit: gpuv1.ToolkitSpec{
1020+
Repository: "nvcr.io/nvidia/cloud-native",
1021+
Image: "nvidia-container-toolkit",
1022+
Version: "v1.0.0",
1023+
Env: []gpuv1.EnvVar{
1024+
{Name: "NO_RUNTIME_CONFIG", Value: "true"},
1025+
},
1026+
},
1027+
},
1028+
expectedDs: NewDaemonset().
1029+
WithContainer(corev1.Container{
1030+
Name: "nvidia-container-toolkit-ctr",
1031+
Image: "nvcr.io/nvidia/cloud-native/nvidia-container-toolkit:v1.0.0",
1032+
ImagePullPolicy: corev1.PullIfNotPresent,
1033+
Env: []corev1.EnvVar{
1034+
{Name: "CDI_ENABLED", Value: "true"},
1035+
{Name: "NVIDIA_RUNTIME_SET_AS_DEFAULT", Value: "false"},
1036+
{Name: "NVIDIA_CONTAINER_RUNTIME_MODE", Value: "cdi"},
1037+
{Name: "CRIO_CONFIG_MODE", Value: "config"},
1038+
{Name: "RUNTIME", Value: "none"},
1039+
},
1040+
VolumeMounts: nil,
1041+
}),
1042+
},
10131043
}
10141044

10151045
for _, tc := range testCases {

0 commit comments

Comments
 (0)