Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,14 +1366,29 @@ func TransformToolkit(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n
}
}

if len(config.Toolkit.Env) > 0 {
for _, env := range config.Toolkit.Env {
setContainerEnv(toolkitMainContainer, env.Name, env.Value)
}
}

// configure runtime
runtime := n.runtime.String()
var noRuntimeConfig bool
// Update the main container environment from the user-specified values.
for _, env := range config.Toolkit.Env {
switch env.Name {
case "RUNTIME":
// If the user has specified the runtime, we overide the detected
// value.
// TODO: Add logging.
runtime = env.Value
case "NO_RUNTIME_CONFIG":
noRuntimeConfig = func() bool {
v, _ := strconv.ParseBool(env.Value)
return v
}()
}
setContainerEnv(toolkitMainContainer, env.Name, env.Value)
}

if noRuntimeConfig {
return nil
}
err = transformForRuntime(obj, config, runtime, toolkitMainContainer)
if err != nil {
return fmt.Errorf("error transforming toolkit daemonset : %w", err)
Expand Down
50 changes: 44 additions & 6 deletions controllers/transforms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package controllers

import (
"errors"
"path/filepath"
"testing"

Expand Down Expand Up @@ -777,11 +778,12 @@ func TestApplyCommonDaemonsetMetadata(t *testing.T) {

func TestTransformToolkit(t *testing.T) {
testCases := []struct {
description string
ds Daemonset // Input DaemonSet
cpSpec *gpuv1.ClusterPolicySpec // Input configuration
runtime gpuv1.Runtime
expectedDs Daemonset // Expected output DaemonSet
description string
ds Daemonset // Input DaemonSet
cpSpec *gpuv1.ClusterPolicySpec // Input configuration
runtime gpuv1.Runtime
expectedError error
expectedDs Daemonset // Expected output DaemonSet
}{
{
description: "transform nvidia-container-toolkit-ctr container",
Expand Down Expand Up @@ -1002,6 +1004,42 @@ func TestTransformToolkit(t *testing.T) {
WithHostPathVolume("crio-config", "/etc/crio", ptr.To(corev1.HostPathDirectoryOrCreate)).
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)),
},
{
description: "no nvidia-container-toolkit-ctr container",
ds: NewDaemonset(),
expectedError: errors.New(`failed to find toolkit container "nvidia-container-toolkit-ctr"`),
expectedDs: NewDaemonset(),
},
{
description: "transform nvidia-container-toolkit-ctr container with no-runtime-config",
ds: NewDaemonset().
WithContainer(corev1.Container{Name: "nvidia-container-toolkit-ctr"}),
runtime: gpuv1.Containerd,
cpSpec: &gpuv1.ClusterPolicySpec{
Toolkit: gpuv1.ToolkitSpec{
Repository: "nvcr.io/nvidia/cloud-native",
Image: "nvidia-container-toolkit",
Version: "v1.0.0",
Env: []gpuv1.EnvVar{
{Name: "NO_RUNTIME_CONFIG", Value: "true"},
},
},
},
expectedDs: NewDaemonset().
WithContainer(corev1.Container{
Name: "nvidia-container-toolkit-ctr",
Image: "nvcr.io/nvidia/cloud-native/nvidia-container-toolkit:v1.0.0",
ImagePullPolicy: corev1.PullIfNotPresent,
Env: []corev1.EnvVar{
{Name: "CDI_ENABLED", Value: "true"},
{Name: "NVIDIA_RUNTIME_SET_AS_DEFAULT", Value: "false"},
{Name: "NVIDIA_CONTAINER_RUNTIME_MODE", Value: "cdi"},
{Name: "CRIO_CONFIG_MODE", Value: "config"},
{Name: "NO_RUNTIME_CONFIG", Value: "true"},
},
VolumeMounts: nil,
}),
},
}

for _, tc := range testCases {
Expand All @@ -1012,7 +1050,7 @@ func TestTransformToolkit(t *testing.T) {
}

err := TransformToolkit(tc.ds.DaemonSet, tc.cpSpec, controller)
require.NoError(t, err)
require.EqualValues(t, tc.expectedError, err)
require.EqualValues(t, tc.expectedDs, tc.ds)
})
}
Expand Down