@@ -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" , "/etc/containerd/conf.d" , 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 : "/etc/containerd/conf.d/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 : "/etc/containerd/conf.d/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" , "/etc/containerd/conf.d" , 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 : "/etc/containerd/conf.d/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" , "/etc/containerd/conf.d" , newHostPathType (corev1 .HostPathDirectoryOrCreate )).
742758 WithHostPathVolume ("containerd-socket" , "/run/k3s/containerd" , nil ).
743759 WithPullSecret ("pull-secret" ),
744760 },
@@ -2261,3 +2277,129 @@ 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+ expectedTopLevelConfigFile string
2287+ expectedDropInConfigFile string
2288+ errorExpected bool
2289+ }{
2290+ {
2291+ description : "invalid runtime" ,
2292+ container : corev1.Container {},
2293+ runtime : "foo" ,
2294+ errorExpected : true ,
2295+ },
2296+ {
2297+ description : "docker" ,
2298+ container : corev1.Container {},
2299+ runtime : gpuv1 .Docker .String (),
2300+ expectedTopLevelConfigFile : DefaultDockerConfigFile ,
2301+ expectedDropInConfigFile : "" ,
2302+ },
2303+ {
2304+ description : "docker, config path overridden" ,
2305+ container : corev1.Container {
2306+ Env : []corev1.EnvVar {
2307+ {Name : "RUNTIME_CONFIG" , Value : "/path/to/docker/daemon.json" },
2308+ },
2309+ },
2310+ runtime : gpuv1 .Docker .String (),
2311+ expectedTopLevelConfigFile : "/path/to/docker/daemon.json" ,
2312+ expectedDropInConfigFile : "" ,
2313+ },
2314+ {
2315+ description : "docker, config path overridden, DOCKER_CONFIG envvar has highest precedence" ,
2316+ container : corev1.Container {
2317+ Env : []corev1.EnvVar {
2318+ {Name : "RUNTIME_CONFIG" , Value : "/path/to/docker/daemon.json" },
2319+ {Name : "DOCKER_CONFIG" , Value : "/another/path/to/docker/daemon.json" },
2320+ },
2321+ },
2322+ runtime : gpuv1 .Docker .String (),
2323+ expectedTopLevelConfigFile : "/another/path/to/docker/daemon.json" ,
2324+ expectedDropInConfigFile : "" ,
2325+ },
2326+ {
2327+ description : "containerd" ,
2328+ container : corev1.Container {},
2329+ runtime : gpuv1 .Containerd .String (),
2330+ expectedTopLevelConfigFile : DefaultContainerdConfigFile ,
2331+ expectedDropInConfigFile : DefaultContainerdDropInConfigFile ,
2332+ },
2333+ {
2334+ description : "containerd, config path overridden" ,
2335+ container : corev1.Container {
2336+ Env : []corev1.EnvVar {
2337+ {Name : "RUNTIME_CONFIG" , Value : "/path/to/containerd/config.toml" },
2338+ {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/path/to/containerd/drop-in/config.toml" },
2339+ },
2340+ },
2341+ runtime : gpuv1 .Containerd .String (),
2342+ expectedTopLevelConfigFile : "/path/to/containerd/config.toml" ,
2343+ expectedDropInConfigFile : "/path/to/containerd/drop-in/config.toml" ,
2344+ },
2345+ {
2346+ description : "containerd, config path overridden, CONTAINERD_CONFIG envvar has highest precedence" ,
2347+ container : corev1.Container {
2348+ Env : []corev1.EnvVar {
2349+ {Name : "RUNTIME_CONFIG" , Value : "/path/to/containerd/config.toml" },
2350+ {Name : "CONTAINERD_CONFIG" , Value : "/another/path/to/containerd/config.toml" },
2351+ {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/path/to/containerd/drop-in/config.toml" },
2352+ },
2353+ },
2354+ runtime : gpuv1 .Containerd .String (),
2355+ expectedTopLevelConfigFile : "/another/path/to/containerd/config.toml" ,
2356+ expectedDropInConfigFile : "/path/to/containerd/drop-in/config.toml" ,
2357+ },
2358+ {
2359+ description : "crio" ,
2360+ container : corev1.Container {},
2361+ runtime : gpuv1 .CRIO .String (),
2362+ expectedTopLevelConfigFile : DefaultCRIOConfigFile ,
2363+ expectedDropInConfigFile : DefaultCRIODropInConfigFile ,
2364+ },
2365+ {
2366+ description : "crio, config path overridden" ,
2367+ container : corev1.Container {
2368+ Env : []corev1.EnvVar {
2369+ {Name : "RUNTIME_CONFIG" , Value : "/path/to/crio/config.toml" },
2370+ {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/path/to/crio/drop-in/config.toml" },
2371+ },
2372+ },
2373+ runtime : gpuv1 .CRIO .String (),
2374+ expectedTopLevelConfigFile : "/path/to/crio/config.toml" ,
2375+ expectedDropInConfigFile : "/path/to/crio/drop-in/config.toml" ,
2376+ },
2377+ {
2378+ description : "crio, config path overridden, CRIO_CONFIG envvar has highest precedence" ,
2379+ container : corev1.Container {
2380+ Env : []corev1.EnvVar {
2381+ {Name : "RUNTIME_CONFIG" , Value : "/path/to/crio/config.toml" },
2382+ {Name : "CRIO_CONFIG" , Value : "/another/path/to/crio/config.toml" },
2383+ {Name : "RUNTIME_DROP_IN_CONFIG" , Value : "/path/to/crio/drop-in/config.toml" },
2384+ },
2385+ },
2386+ runtime : gpuv1 .CRIO .String (),
2387+ expectedTopLevelConfigFile : "/another/path/to/crio/config.toml" ,
2388+ expectedDropInConfigFile : "/path/to/crio/drop-in/config.toml" ,
2389+ },
2390+ }
2391+
2392+ for _ , tc := range testCases {
2393+ t .Run (tc .description , func (t * testing.T ) {
2394+ topLevelConfigFile , dropInConfigFile , err := getRuntimeConfigFiles (& tc .container , tc .runtime )
2395+ if tc .errorExpected {
2396+ require .Error (t , err )
2397+ return
2398+ }
2399+ require .NoError (t , err )
2400+ require .EqualValues (t , tc .expectedTopLevelConfigFile , topLevelConfigFile )
2401+ require .EqualValues (t , tc .expectedDropInConfigFile , dropInConfigFile )
2402+ })
2403+ }
2404+
2405+ }
0 commit comments