| 1375 | } |
| 1376 | |
| 1377 | func transformForRuntime(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, runtime string, container *corev1.Container) error { |
| 1378 | setContainerEnv(container, "RUNTIME", runtime) |
| 1379 | |
| 1380 | if runtime == gpuv1.Containerd.String() { |
| 1381 | // Set the runtime class name that is to be configured for containerd |
| 1382 | setContainerEnv(container, "CONTAINERD_RUNTIME_CLASS", getRuntimeClassName(config)) |
| 1383 | } |
| 1384 | |
| 1385 | // For runtime config files we have top-level configs and drop-in files. |
| 1386 | // These are supported as follows: |
| 1387 | // * Docker only supports top-level config files. |
| 1388 | // * Containerd supports drop-in files, but required modification to the top-level config |
| 1389 | // * Crio supports drop-in files at a predefined location. The top-level config may be read |
| 1390 | // but should not be updated. |
| 1391 | |
| 1392 | // setup mounts for runtime config file |
| 1393 | topLevelConfigFile, dropInConfigFile, err := getRuntimeConfigFiles(container, runtime) |
| 1394 | if err != nil { |
| 1395 | return fmt.Errorf("error getting path to runtime config file: %w", err) |
| 1396 | } |
| 1397 | |
| 1398 | var configEnvvarName string |
| 1399 | switch runtime { |
| 1400 | case gpuv1.Containerd.String(): |
| 1401 | configEnvvarName = "CONTAINERD_CONFIG" |
| 1402 | case gpuv1.Docker.String(): |
| 1403 | configEnvvarName = "DOCKER_CONFIG" |
| 1404 | case gpuv1.CRIO.String(): |
| 1405 | configEnvvarName = "CRIO_CONFIG" |
| 1406 | } |
| 1407 | |
| 1408 | // Handle the top-level configs |
| 1409 | if topLevelConfigFile != "" { |
| 1410 | sourceConfigFileName := path.Base(topLevelConfigFile) |
| 1411 | sourceConfigDir := path.Dir(topLevelConfigFile) |
| 1412 | containerConfigDir := DefaultRuntimeConfigTargetDir |
| 1413 | setContainerEnv(container, "RUNTIME_CONFIG", containerConfigDir+sourceConfigFileName) |
| 1414 | setContainerEnv(container, configEnvvarName, containerConfigDir+sourceConfigFileName) |
| 1415 | |
| 1416 | volMountConfigName := fmt.Sprintf("%s-config", runtime) |
| 1417 | volMountConfig := corev1.VolumeMount{Name: volMountConfigName, MountPath: containerConfigDir} |
| 1418 | container.VolumeMounts = append(container.VolumeMounts, volMountConfig) |
| 1419 | |
| 1420 | configVol := corev1.Volume{Name: volMountConfigName, VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: sourceConfigDir, Type: ptr.To(corev1.HostPathDirectoryOrCreate)}}} |
| 1421 | obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, configVol) |
| 1422 | } |
| 1423 | |
| 1424 | // Handle the drop-in configs |
| 1425 | // TODO: It's a bit of a hack to skip the `nvidia-kata-manager` container here. |
| 1426 | // Ideally if the two projects are using the SAME API then this should be |
| 1427 | // captured more rigorously. |
| 1428 | // Note that we probably want to implement drop-in file support in the |
| 1429 | // kata manager in any case -- in which case it will be good to use a |
| 1430 | // similar implementation. |
| 1431 | if dropInConfigFile != "" && container.Name != "nvidia-kata-manager" { |
| 1432 | sourceConfigFileName := path.Base(dropInConfigFile) |
| 1433 | sourceConfigDir := path.Dir(dropInConfigFile) |
| 1434 | containerConfigDir := DefaultRuntimeDropInConfigTargetDir |