@@ -332,6 +332,7 @@ func TestTransformForRuntime(t *testing.T) {
332332				WithContainer (corev1.Container {Name : "test-ctr" }),
333333			expectedOutput : NewDaemonset ().
334334				WithHostPathVolume ("containerd-config" , filepath .Dir (DefaultContainerdConfigFile ), newHostPathType (corev1 .HostPathDirectoryOrCreate )).
335+ 				WithHostPathVolume ("containerd-drop-in-config" , "/run/nvidia/toolkit/config" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
335336				WithHostPathVolume ("containerd-socket" , filepath .Dir (DefaultContainerdSocketFile ), nil ).
336337				WithContainer (corev1.Container {
337338					Name : "test-ctr" ,
@@ -340,11 +341,14 @@ func TestTransformForRuntime(t *testing.T) {
340341						{Name : "CONTAINERD_RUNTIME_CLASS" , Value : DefaultRuntimeClass },
341342						{Name : "RUNTIME_CONFIG" , Value : filepath .Join (DefaultRuntimeConfigTargetDir , filepath .Base (DefaultContainerdConfigFile ))},
342343						{Name : "CONTAINERD_CONFIG" , Value : filepath .Join (DefaultRuntimeConfigTargetDir , filepath .Base (DefaultContainerdConfigFile ))},
344+ 						{Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.toml" },
345+ 						{Name : "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , Value : "/run/nvidia/toolkit/config/99-nvidia.toml" },
343346						{Name : "RUNTIME_SOCKET" , Value : filepath .Join (DefaultRuntimeSocketTargetDir , filepath .Base (DefaultContainerdSocketFile ))},
344347						{Name : "CONTAINERD_SOCKET" , Value : filepath .Join (DefaultRuntimeSocketTargetDir , filepath .Base (DefaultContainerdSocketFile ))},
345348					},
346349					VolumeMounts : []corev1.VolumeMount {
347350						{Name : "containerd-config" , MountPath : DefaultRuntimeConfigTargetDir },
351+ 						{Name : "containerd-drop-in-config" , MountPath : "/runtime/config-dir.d/" },
348352						{Name : "containerd-socket" , MountPath : DefaultRuntimeSocketTargetDir },
349353					},
350354				}),
@@ -354,17 +358,21 @@ func TestTransformForRuntime(t *testing.T) {
354358			runtime :     gpuv1 .CRIO ,
355359			input :       NewDaemonset ().WithContainer (corev1.Container {Name : "test-ctr" }),
356360			expectedOutput : NewDaemonset ().
357- 				WithHostPathVolume ("crio-config" , filepath .Dir (DefaultCRIOConfigFile ), newHostPathType (corev1 .HostPathDirectoryOrCreate )).
361+ 				WithHostPathVolume ("crio-config" , "/etc/crio" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
362+ 				WithHostPathVolume ("crio-drop-in-config" , "/etc/crio/crio.conf.d" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
358363				WithContainer (corev1.Container {
359364					Name : "test-ctr" ,
360365					Env : []corev1.EnvVar {
361366						{Name : "RUNTIME" , Value : gpuv1 .CRIO .String ()},
362367						{Name : CRIOConfigModeEnvName , Value : "config" },
363- 						{Name : "RUNTIME_CONFIG" , Value : filepath .Join (DefaultRuntimeConfigTargetDir , filepath .Base (DefaultCRIOConfigFile ))},
364- 						{Name : "CRIO_CONFIG" , Value : filepath .Join (DefaultRuntimeConfigTargetDir , filepath .Base (DefaultCRIOConfigFile ))},
368+ 						{Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
369+ 						{Name : "CRIO_CONFIG" , Value : "/runtime/config-dir/config.toml" },
370+ 						{Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.conf" },
371+ 						{Name : "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , Value : "/etc/crio/crio.conf.d/99-nvidia.conf" },
365372					},
366373					VolumeMounts : []corev1.VolumeMount {
367374						{Name : "crio-config" , MountPath : DefaultRuntimeConfigTargetDir },
375+ 						{Name : "crio-drop-in-config" , MountPath : "/runtime/config-dir.d/" },
368376					},
369377				}),
370378		},
@@ -657,15 +665,19 @@ func TestTransformToolkit(t *testing.T) {
657665						{Name : "CONTAINERD_RUNTIME_CLASS" , Value : "nvidia" },
658666						{Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
659667						{Name : "CONTAINERD_CONFIG" , Value : "/runtime/config-dir/config.toml" },
668+ 						{Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.toml" },
669+ 						{Name : "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , Value : "/run/nvidia/toolkit/config/99-nvidia.toml" },
660670						{Name : "RUNTIME_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
661671						{Name : "CONTAINERD_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
662672					},
663673					VolumeMounts : []corev1.VolumeMount {
664674						{Name : "containerd-config" , MountPath : "/runtime/config-dir/" },
675+ 						{Name : "containerd-drop-in-config" , MountPath : "/runtime/config-dir.d/" },
665676						{Name : "containerd-socket" , MountPath : "/runtime/sock-dir/" },
666677					},
667678				}).
668679				WithHostPathVolume ("containerd-config" , "/etc/containerd" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
680+ 				WithHostPathVolume ("containerd-drop-in-config" , "/run/nvidia/toolkit/config" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
669681				WithHostPathVolume ("containerd-socket" , "/run/containerd" , nil ).
670682				WithPullSecret ("pull-secret" ),
671683		},
@@ -731,14 +743,18 @@ func TestTransformToolkit(t *testing.T) {
731743						{Name : "CONTAINERD_SET_AS_DEFAULT" , Value : "true" },
732744						{Name : "RUNTIME" , Value : "containerd" },
733745						{Name : "RUNTIME_CONFIG" , Value : "/runtime/config-dir/config.toml" },
746+ 						{Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/runtime/config-dir.d/99-nvidia.toml" },
747+ 						{Name : "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , Value : "/run/nvidia/toolkit/config/99-nvidia.toml" },
734748						{Name : "RUNTIME_SOCKET" , Value : "/runtime/sock-dir/containerd.sock" },
735749					},
736750					VolumeMounts : []corev1.VolumeMount {
737751						{Name : "containerd-config" , MountPath : "/runtime/config-dir/" },
752+ 						{Name : "containerd-drop-in-config" , MountPath : "/runtime/config-dir.d/" },
738753						{Name : "containerd-socket" , MountPath : "/runtime/sock-dir/" },
739754					},
740755				}).
741756				WithHostPathVolume ("containerd-config" , "/var/lib/rancher/k3s/agent/etc/containerd" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
757+ 				WithHostPathVolume ("containerd-drop-in-config" , "/run/nvidia/toolkit/config" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
742758				WithHostPathVolume ("containerd-socket" , "/run/k3s/containerd" , nil ).
743759				WithPullSecret ("pull-secret" ),
744760		},
@@ -2261,3 +2277,108 @@ func TestTransformDevicePluginCtrForCDI(t *testing.T) {
22612277		})
22622278	}
22632279}
2280+ 
2281+ func  TestGetRuntimeConfigFiles (t  * testing.T ) {
2282+ 	testCases  :=  []struct  {
2283+ 		description                 string 
2284+ 		container                   corev1.Container 
2285+ 		runtime                     string 
2286+ 		expectedRuntimeConfigFiles  runtimeConfigFiles 
2287+ 		errorExpected               bool 
2288+ 	}{
2289+ 		{
2290+ 			description :                "invalid runtime" ,
2291+ 			container :                  corev1.Container {},
2292+ 			runtime :                    "foo" ,
2293+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {},
2294+ 			errorExpected :              true ,
2295+ 		},
2296+ 		{
2297+ 			description : "docker" ,
2298+ 			container :   corev1.Container {},
2299+ 			runtime :     gpuv1 .Docker .String (),
2300+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {
2301+ 				topLevelConfigFile : DefaultDockerConfigFile ,
2302+ 				dropInConfigFile :   "" ,
2303+ 				envvarName :         "DOCKER_CONFIG" ,
2304+ 			},
2305+ 		},
2306+ 		{
2307+ 			description : "docker, config path overridden" ,
2308+ 			container : corev1.Container {
2309+ 				Env : []corev1.EnvVar {
2310+ 					{Name : "DOCKER_CONFIG" , Value : "/path/to/docker/daemon.json" },
2311+ 				},
2312+ 			},
2313+ 			runtime : gpuv1 .Docker .String (),
2314+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {
2315+ 				topLevelConfigFile : "/path/to/docker/daemon.json" ,
2316+ 				dropInConfigFile :   "" ,
2317+ 				envvarName :         "DOCKER_CONFIG" ,
2318+ 			},
2319+ 		},
2320+ 		{
2321+ 			description : "containerd" ,
2322+ 			container :   corev1.Container {},
2323+ 			runtime :     gpuv1 .Containerd .String (),
2324+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {
2325+ 				topLevelConfigFile : DefaultContainerdConfigFile ,
2326+ 				dropInConfigFile :   DefaultContainerdDropInConfigFile ,
2327+ 				envvarName :         "CONTAINERD_CONFIG" ,
2328+ 			},
2329+ 		},
2330+ 		{
2331+ 			description : "containerd, config path overridden" ,
2332+ 			container : corev1.Container {
2333+ 				Env : []corev1.EnvVar {
2334+ 					{Name : "CONTAINERD_CONFIG" , Value : "/path/to/containerd/config.toml" },
2335+ 					{Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/path/to/containerd/drop-in/config.toml" },
2336+ 				},
2337+ 			},
2338+ 			runtime : gpuv1 .Containerd .String (),
2339+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {
2340+ 				topLevelConfigFile : "/path/to/containerd/config.toml" ,
2341+ 				dropInConfigFile :   "/path/to/containerd/drop-in/config.toml" ,
2342+ 				envvarName :         "CONTAINERD_CONFIG" ,
2343+ 			},
2344+ 		},
2345+ 		{
2346+ 			description : "crio" ,
2347+ 			container :   corev1.Container {},
2348+ 			runtime :     gpuv1 .CRIO .String (),
2349+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {
2350+ 				topLevelConfigFile : DefaultCRIOConfigFile ,
2351+ 				dropInConfigFile :   DefaultCRIODropInConfigFile ,
2352+ 				envvarName :         "CRIO_CONFIG" ,
2353+ 			},
2354+ 		},
2355+ 		{
2356+ 			description : "crio, config path overridden" ,
2357+ 			container : corev1.Container {
2358+ 				Env : []corev1.EnvVar {
2359+ 					{Name : "CRIO_CONFIG" , Value : "/path/to/crio/config.toml" },
2360+ 					{Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/path/to/crio/drop-in/config.toml" },
2361+ 				},
2362+ 			},
2363+ 			runtime : gpuv1 .CRIO .String (),
2364+ 			expectedRuntimeConfigFiles : runtimeConfigFiles {
2365+ 				topLevelConfigFile : "/path/to/crio/config.toml" ,
2366+ 				dropInConfigFile :   "/path/to/crio/drop-in/config.toml" ,
2367+ 				envvarName :         "CRIO_CONFIG" ,
2368+ 			},
2369+ 		},
2370+ 	}
2371+ 
2372+ 	for  _ , tc  :=  range  testCases  {
2373+ 		t .Run (tc .description , func (t  * testing.T ) {
2374+ 			runtimeConfigFiles , err  :=  getRuntimeConfigFiles (& tc .container , tc .runtime )
2375+ 			if  tc .errorExpected  {
2376+ 				require .Error (t , err )
2377+ 				return 
2378+ 			}
2379+ 			require .NoError (t , err )
2380+ 			require .EqualValues (t , tc .expectedRuntimeConfigFiles , runtimeConfigFiles )
2381+ 		})
2382+ 	}
2383+ 
2384+ }
0 commit comments