@@ -478,7 +478,6 @@ func TestTransformForRuntime(t *testing.T) {
478478 Name : "test-ctr" ,
479479 Env : []corev1.EnvVar {
480480 {Name : "RUNTIME" , Value : gpuv1 .CRIO .String ()},
481- {Name : CRIOConfigModeEnvName , Value : "config" },
482481 {Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
483482 {Name : "CRIO_CONFIG" , Value : "/runtime/config-dir/config.toml" },
484483 {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.conf" },
@@ -775,12 +774,14 @@ func TestTransformToolkit(t *testing.T) {
775774 description string
776775 ds Daemonset // Input DaemonSet
777776 cpSpec * gpuv1.ClusterPolicySpec // Input configuration
778- expectedDs Daemonset // Expected output DaemonSet
777+ runtime gpuv1.Runtime
778+ expectedDs Daemonset // Expected output DaemonSet
779779 }{
780780 {
781781 description : "transform nvidia-container-toolkit-ctr container" ,
782782 ds : NewDaemonset ().
783783 WithContainer (corev1.Container {Name : "nvidia-container-toolkit-ctr" }),
784+ runtime : gpuv1 .Containerd ,
784785 cpSpec : & gpuv1.ClusterPolicySpec {
785786 Toolkit : gpuv1.ToolkitSpec {
786787 Repository : "nvcr.io/nvidia/cloud-native" ,
@@ -822,6 +823,7 @@ func TestTransformToolkit(t *testing.T) {
822823 {Name : CDIEnabledEnvName , Value : "true" },
823824 {Name : NvidiaRuntimeSetAsDefaultEnvName , Value : "false" },
824825 {Name : NvidiaCtrRuntimeModeEnvName , Value : "cdi" },
826+ {Name : CRIOConfigModeEnvName , Value : "config" },
825827 {Name : "foo" , Value : "bar" },
826828 {Name : "RUNTIME" , Value : "containerd" },
827829 {Name : "CONTAINERD_RUNTIME_CLASS" , Value : "nvidia" },
@@ -847,6 +849,7 @@ func TestTransformToolkit(t *testing.T) {
847849 description : "transform nvidia-container-toolkit-ctr container with custom ctr runtime socket" ,
848850 ds : NewDaemonset ().
849851 WithContainer (corev1.Container {Name : "nvidia-container-toolkit-ctr" }),
852+ runtime : gpuv1 .Containerd ,
850853 cpSpec : & gpuv1.ClusterPolicySpec {
851854 Toolkit : gpuv1.ToolkitSpec {
852855 Repository : "nvcr.io/nvidia/cloud-native" ,
@@ -899,6 +902,7 @@ func TestTransformToolkit(t *testing.T) {
899902 {Name : CDIEnabledEnvName , Value : "true" },
900903 {Name : NvidiaRuntimeSetAsDefaultEnvName , Value : "false" },
901904 {Name : NvidiaCtrRuntimeModeEnvName , Value : "cdi" },
905+ {Name : CRIOConfigModeEnvName , Value : "config" },
902906 {Name : "CONTAINERD_CONFIG" , Value : "/runtime/config-dir/config.toml" },
903907 {Name : "CONTAINERD_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
904908 {Name : "CONTAINERD_RUNTIME_CLASS" , Value : "nvidia" },
@@ -920,12 +924,84 @@ func TestTransformToolkit(t *testing.T) {
920924 WithHostPathVolume ("containerd-socket" , "/run/k3s/containerd" , nil ).
921925 WithPullSecret ("pull-secret" ),
922926 },
927+ {
928+ description : "transform nvidia-container-toolkit-ctr container, cri-o runtime, cdi enabled" ,
929+ ds : NewDaemonset ().
930+ WithContainer (corev1.Container {Name : "nvidia-container-toolkit-ctr" }),
931+ runtime : gpuv1 .CRIO ,
932+ cpSpec : & gpuv1.ClusterPolicySpec {
933+ Toolkit : gpuv1.ToolkitSpec {
934+ Repository : "nvcr.io/nvidia/cloud-native" ,
935+ Image : "nvidia-container-toolkit" ,
936+ Version : "v1.0.0" ,
937+ },
938+ },
939+ expectedDs : NewDaemonset ().
940+ WithContainer (corev1.Container {
941+ Name : "nvidia-container-toolkit-ctr" ,
942+ Image : "nvcr.io/nvidia/cloud-native/nvidia-container-toolkit:v1.0.0" ,
943+ ImagePullPolicy : corev1 .PullIfNotPresent ,
944+ Env : []corev1.EnvVar {
945+ {Name : CDIEnabledEnvName , Value : "true" },
946+ {Name : NvidiaRuntimeSetAsDefaultEnvName , Value : "false" },
947+ {Name : NvidiaCtrRuntimeModeEnvName , Value : "cdi" },
948+ {Name : CRIOConfigModeEnvName , Value : "config" },
949+ {Name : "RUNTIME" , Value : gpuv1 .CRIO .String ()},
950+ {Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
951+ {Name : "CRIO_CONFIG" , Value : "/runtime/config-dir/config.toml" },
952+ {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.conf" },
953+ {Name : "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , Value : "/etc/crio/crio.conf.d/99-nvidia.conf" },
954+ },
955+ VolumeMounts : []corev1.VolumeMount {
956+ {Name : "crio-config" , MountPath : DefaultRuntimeConfigTargetDir },
957+ {Name : "crio-drop-in-config" , MountPath : "/runtime/config-dir.d/" },
958+ },
959+ }).
960+ WithHostPathVolume ("crio-config" , "/etc/crio" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
961+ WithHostPathVolume ("crio-drop-in-config" , "/etc/crio/crio.conf.d" , newHostPathType (corev1 .HostPathDirectoryOrCreate )),
962+ },
963+ {
964+ description : "transform nvidia-container-toolkit-ctr container, cri-o runtime, cdi disabled" ,
965+ ds : NewDaemonset ().
966+ WithContainer (corev1.Container {Name : "nvidia-container-toolkit-ctr" }),
967+ runtime : gpuv1 .CRIO ,
968+ cpSpec : & gpuv1.ClusterPolicySpec {
969+ Toolkit : gpuv1.ToolkitSpec {
970+ Repository : "nvcr.io/nvidia/cloud-native" ,
971+ Image : "nvidia-container-toolkit" ,
972+ Version : "v1.0.0" ,
973+ },
974+ CDI : gpuv1.CDIConfigSpec {
975+ Enabled : newBoolPtr (false ),
976+ },
977+ },
978+ expectedDs : NewDaemonset ().
979+ WithContainer (corev1.Container {
980+ Name : "nvidia-container-toolkit-ctr" ,
981+ Image : "nvcr.io/nvidia/cloud-native/nvidia-container-toolkit:v1.0.0" ,
982+ ImagePullPolicy : corev1 .PullIfNotPresent ,
983+ Env : []corev1.EnvVar {
984+ {Name : CRIOConfigModeEnvName , Value : "hook" },
985+ {Name : "RUNTIME" , Value : gpuv1 .CRIO .String ()},
986+ {Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
987+ {Name : "CRIO_CONFIG" , Value : "/runtime/config-dir/config.toml" },
988+ {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.conf" },
989+ {Name : "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , Value : "/etc/crio/crio.conf.d/99-nvidia.conf" },
990+ },
991+ VolumeMounts : []corev1.VolumeMount {
992+ {Name : "crio-config" , MountPath : DefaultRuntimeConfigTargetDir },
993+ {Name : "crio-drop-in-config" , MountPath : "/runtime/config-dir.d/" },
994+ },
995+ }).
996+ WithHostPathVolume ("crio-config" , "/etc/crio" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
997+ WithHostPathVolume ("crio-drop-in-config" , "/etc/crio/crio.conf.d" , newHostPathType (corev1 .HostPathDirectoryOrCreate )),
998+ },
923999 }
9241000
9251001 for _ , tc := range testCases {
9261002 t .Run (tc .description , func (t * testing.T ) {
9271003 controller := ClusterPolicyController {
928- runtime : gpuv1 . Containerd ,
1004+ runtime : tc . runtime ,
9291005 logger : ctrl .Log .WithName ("test" ),
9301006 }
9311007
@@ -2587,6 +2663,7 @@ func TestTransformToolkitCtrForCDI(t *testing.T) {
25872663 {Name : CDIEnabledEnvName , Value : "true" },
25882664 {Name : NvidiaRuntimeSetAsDefaultEnvName , Value : "false" },
25892665 {Name : NvidiaCtrRuntimeModeEnvName , Value : "cdi" },
2666+ {Name : CRIOConfigModeEnvName , Value : "config" },
25902667 },
25912668 }),
25922669 },
0 commit comments