check if running with openshift and add an ENV VAR to the OCP DTK CTR
(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController)
| 3022 | |
| 3023 | // check if running with openshift and add an ENV VAR to the OCP DTK CTR |
| 3024 | func transformGDSContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error { |
| 3025 | for i, container := range obj.Spec.Template.Spec.Containers { |
| 3026 | // skip if not nvidia-fs |
| 3027 | if !strings.Contains(container.Name, "nvidia-fs") { |
| 3028 | continue |
| 3029 | } |
| 3030 | if config.GPUDirectStorage == nil || !config.GPUDirectStorage.IsEnabled() { |
| 3031 | n.logger.Info("GPUDirect Storage is disabled") |
| 3032 | // remove nvidia-fs sidecar container from driver Daemonset if GDS is not enabled |
| 3033 | obj.Spec.Template.Spec.Containers = append(obj.Spec.Template.Spec.Containers[:i], obj.Spec.Template.Spec.Containers[i+1:]...) |
| 3034 | return nil |
| 3035 | } |
| 3036 | if config.Driver.UsePrecompiledDrivers() { |
| 3037 | return fmt.Errorf("GPUDirect Storage driver (nvidia-fs) is not supported along with pre-compiled NVIDIA drivers") |
| 3038 | } |
| 3039 | |
| 3040 | gdsContainer := &obj.Spec.Template.Spec.Containers[i] |
| 3041 | |
| 3042 | // update nvidia-fs(sidecar) image and pull policy |
| 3043 | gdsImage, err := resolveDriverTag(n, config.GPUDirectStorage) |
| 3044 | if err != nil { |
| 3045 | return err |
| 3046 | } |
| 3047 | if gdsImage != "" { |
| 3048 | gdsContainer.Image = gdsImage |
| 3049 | } |
| 3050 | if config.GPUDirectStorage.ImagePullPolicy != "" { |
| 3051 | gdsContainer.ImagePullPolicy = gpuv1.ImagePullPolicy(config.GPUDirectStorage.ImagePullPolicy) |
| 3052 | } |
| 3053 | |
| 3054 | // set image pull secrets |
| 3055 | if len(config.GPUDirectStorage.ImagePullSecrets) > 0 { |
| 3056 | addPullSecrets(&obj.Spec.Template.Spec, config.GPUDirectStorage.ImagePullSecrets) |
| 3057 | } |
| 3058 | |
| 3059 | // set/append environment variables for GDS container |
| 3060 | if len(config.GPUDirectStorage.Env) > 0 { |
| 3061 | for _, env := range config.GPUDirectStorage.Env { |
| 3062 | setContainerEnv(gdsContainer, env.Name, env.Value) |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | if config.Driver.RepoConfig != nil && config.Driver.RepoConfig.ConfigMapName != "" { |
| 3067 | // note: transformDriverContainer() will have already created a Volume backed by the ConfigMap. |
| 3068 | // Only add a VolumeMount for nvidia-fs-ctr. |
| 3069 | destinationDir, err := n.getRepoConfigPath() |
| 3070 | if err != nil { |
| 3071 | return fmt.Errorf("ERROR: failed to get destination directory for custom repo config: %w", err) |
| 3072 | } |
| 3073 | volumeMounts, _, err := createConfigMapVolumeMounts(n, config.Driver.RepoConfig.ConfigMapName, destinationDir) |
| 3074 | if err != nil { |
| 3075 | return fmt.Errorf("ERROR: failed to create ConfigMap VolumeMounts for custom package repo config: %w", err) |
| 3076 | } |
| 3077 | gdsContainer.VolumeMounts = append(gdsContainer.VolumeMounts, volumeMounts...) |
| 3078 | } |
| 3079 | |
| 3080 | // set any custom ssl key/certificate configuration provided |
| 3081 | if config.Driver.CertConfig != nil && config.Driver.CertConfig.Name != "" { |
no test coverage detected