@@ -1327,12 +1327,18 @@ func transformForRuntime(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec,
13271327 setContainerEnv (mainContainer , "CONTAINERD_RUNTIME_CLASS" , getRuntimeClass (config ))
13281328 }
13291329
1330+ // For runtime config files we have top-level configs and drop-in files.
1331+ // These are supported as follows:
1332+ // * Docker only supports top-level config files.
1333+ // * Containerd supports drop-in files, but required modification to the top-level config
1334+ // * Crio supports drop-in files at a predefined location. The top-level config may be read
1335+ // but should not be updated.
1336+
13301337 // setup mounts for runtime config file
1331- runtimeConfigFile , err := getRuntimeConfigFile (mainContainer , runtime )
1338+ runtimeConfigFiles , err := getRuntimeConfigFiles (mainContainer , runtime )
13321339 if err != nil {
13331340 return fmt .Errorf ("error getting path to runtime config file: %v" , err )
13341341 }
1335- sourceConfigFileName := path .Base (runtimeConfigFile )
13361342
13371343 var configEnvvarName string
13381344 switch runtime {
@@ -1344,15 +1350,38 @@ func transformForRuntime(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec,
13441350 configEnvvarName = "CRIO_CONFIG"
13451351 }
13461352
1347- setContainerEnv (mainContainer , "RUNTIME_CONFIG" , DefaultRuntimeConfigTargetDir + sourceConfigFileName )
1348- setContainerEnv (mainContainer , configEnvvarName , DefaultRuntimeConfigTargetDir + sourceConfigFileName )
1353+ // Handle the top-level configs
1354+ if runtimeConfigFiles .topLevelConfigFile != "" {
1355+ sourceConfigFileName := path .Base (runtimeConfigFiles .topLevelConfigFile )
1356+ sourceConfigDir := path .Dir (runtimeConfigFiles .topLevelConfigFile )
1357+ containerConfigDir := DefaultRuntimeConfigTargetDir
1358+ setContainerEnv (mainContainer , "RUNTIME_CONFIG" , containerConfigDir + sourceConfigFileName )
1359+ setContainerEnv (mainContainer , configEnvvarName , containerConfigDir + sourceConfigFileName )
1360+
1361+ volMountConfigName := fmt .Sprintf ("%s-config" , runtime )
1362+ volMountConfig := corev1.VolumeMount {Name : volMountConfigName , MountPath : containerConfigDir }
1363+ mainContainer .VolumeMounts = append (mainContainer .VolumeMounts , volMountConfig )
1364+
1365+ configVol := corev1.Volume {Name : volMountConfigName , VolumeSource : corev1.VolumeSource {HostPath : & corev1.HostPathVolumeSource {Path : sourceConfigDir , Type : newHostPathType (corev1 .HostPathDirectoryOrCreate )}}}
1366+ obj .Spec .Template .Spec .Volumes = append (obj .Spec .Template .Spec .Volumes , configVol )
1367+ }
1368+
1369+ // Handle the drop-in configs
1370+ if runtimeConfigFiles .dropInConfigFile != "" {
1371+ sourceConfigFileName := path .Base (runtimeConfigFiles .dropInConfigFile )
1372+ sourceConfigDir := path .Dir (runtimeConfigFiles .dropInConfigFile )
1373+ // TODO: This should be a constant.
1374+ containerConfigDir := "/runtime/config-dir.d/"
1375+ setContainerEnv (mainContainer , "RUNTIME_DROP_IN_CONFIG" , containerConfigDir + sourceConfigFileName )
1376+ setContainerEnv (mainContainer , "RUNTIME_DROP_IN_CONFIG_HOST_PATH" , runtimeConfigFiles .dropInConfigFile )
13491377
1350- volMountConfigName := fmt .Sprintf ("%s-config" , runtime )
1351- volMountConfig := corev1.VolumeMount {Name : volMountConfigName , MountPath : DefaultRuntimeConfigTargetDir }
1352- mainContainer .VolumeMounts = append (mainContainer .VolumeMounts , volMountConfig )
1378+ volMountConfigName := fmt .Sprintf ("%s-drop-in -config" , runtime )
1379+ volMountConfig := corev1.VolumeMount {Name : volMountConfigName , MountPath : containerConfigDir }
1380+ mainContainer .VolumeMounts = append (mainContainer .VolumeMounts , volMountConfig )
13531381
1354- configVol := corev1.Volume {Name : volMountConfigName , VolumeSource : corev1.VolumeSource {HostPath : & corev1.HostPathVolumeSource {Path : path .Dir (runtimeConfigFile ), Type : newHostPathType (corev1 .HostPathDirectoryOrCreate )}}}
1355- obj .Spec .Template .Spec .Volumes = append (obj .Spec .Template .Spec .Volumes , configVol )
1382+ configVol := corev1.Volume {Name : volMountConfigName , VolumeSource : corev1.VolumeSource {HostPath : & corev1.HostPathVolumeSource {Path : sourceConfigDir , Type : newHostPathType (corev1 .HostPathDirectoryOrCreate )}}}
1383+ obj .Spec .Template .Spec .Volumes = append (obj .Spec .Template .Spec .Volumes , configVol )
1384+ }
13561385
13571386 // setup mounts for runtime socket file
13581387 runtimeSocketFile , err := getRuntimeSocketFile (mainContainer , runtime )
@@ -2357,30 +2386,62 @@ func TransformNodeStatusExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPol
23572386 return nil
23582387}
23592388
2389+ type runtimeConfigFiles struct {
2390+ // TODO: Add envvarName as a member here so that we don't have to query this
2391+ // again.
2392+ // envvarName string
2393+ topLevelConfigFile string
2394+ dropInConfigFile string
2395+ }
2396+
23602397// get runtime(docker, containerd) config file path based on toolkit container env or default
2361- func getRuntimeConfigFile (c * corev1.Container , runtime string ) (string , error ) {
2362- var runtimeConfigFile string
2398+ func getRuntimeConfigFiles (c * corev1.Container , runtime string ) (runtimeConfigFiles , error ) {
23632399 switch runtime {
23642400 case gpuv1 .Docker .String ():
2365- runtimeConfigFile = DefaultDockerConfigFile
2401+ topLevelConfigFile : = DefaultDockerConfigFile
23662402 if value := getContainerEnv (c , "DOCKER_CONFIG" ); value != "" {
2367- runtimeConfigFile = value
2403+ topLevelConfigFile = value
23682404 }
2405+ return runtimeConfigFiles {
2406+ topLevelConfigFile : topLevelConfigFile ,
2407+ // Docker does not support drop-in files.
2408+ dropInConfigFile : "" ,
2409+ }, nil
23692410 case gpuv1 .Containerd .String ():
2370- runtimeConfigFile = DefaultContainerdConfigFile
2411+ topLevelConfigFile := DefaultContainerdConfigFile
2412+ // TODO: We should also read RUNTIME_CONFIG here
23712413 if value := getContainerEnv (c , "CONTAINERD_CONFIG" ); value != "" {
2372- runtimeConfigFile = value
2414+ topLevelConfigFile = value
2415+ }
2416+ // TODO: This should be a sane default.
2417+ dropInConfigFile := "/run/toolkit/config/99-nvidia.toml"
2418+ if value := getContainerEnv (c , "RUNTIME_DROP_IN_CONFIG" ); value != "" {
2419+ dropInConfigFile = value
23732420 }
2421+ return runtimeConfigFiles {
2422+ topLevelConfigFile : topLevelConfigFile ,
2423+ dropInConfigFile : dropInConfigFile ,
2424+ }, nil
23742425 case gpuv1 .CRIO .String ():
2375- runtimeConfigFile = DefaultCRIOConfigFile
2426+ // TODO: We should still allow the top-level config to be specified
2427+ // TODO: This should be DefaultCRIOConfigFile, but this is not the correct value.
2428+ // TODO: We should also read RUNTIME_CONFIG here
2429+ topLevelConfigFile := "/etc/crio/config.toml"
23762430 if value := getContainerEnv (c , "CRIO_CONFIG" ); value != "" {
2377- runtimeConfigFile = value
2431+ topLevelConfigFile = value
23782432 }
2433+ // TODO: The constant should have a different name (e.g. DefaultCRIODropInFile)
2434+ dropInConfigFile := DefaultCRIOConfigFile
2435+ if value := getContainerEnv (c , "RUNTIME_DROP_IN_CONFIG" ); value != "" {
2436+ dropInConfigFile = value
2437+ }
2438+ return runtimeConfigFiles {
2439+ topLevelConfigFile : topLevelConfigFile ,
2440+ dropInConfigFile : dropInConfigFile ,
2441+ }, nil
23792442 default :
2380- return "" , fmt .Errorf ("invalid runtime: %s" , runtime )
2443+ return runtimeConfigFiles {} , fmt .Errorf ("invalid runtime: %s" , runtime )
23812444 }
2382-
2383- return runtimeConfigFile , nil
23842445}
23852446
23862447// get runtime(docker, containerd) socket file path based on toolkit container env or default
0 commit comments