MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / transformGDRCopyContainer

Function transformGDRCopyContainer

controllers/object_controls.go:3117–3208  ·  view source on GitHub ↗
(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController)

Source from the content-addressed store, hash-verified

3115}
3116
3117func transformGDRCopyContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error {
3118 for i, container := range obj.Spec.Template.Spec.Containers {
3119 // skip if not nvidia-gdrcopy
3120 if !strings.HasPrefix(container.Name, "nvidia-gdrcopy") {
3121 continue
3122 }
3123 if config.GDRCopy == nil || !config.GDRCopy.IsEnabled() {
3124 n.logger.Info("GDRCopy is disabled")
3125 // remove nvidia-gdrcopy sidecar container from driver Daemonset if gdrcopy is not enabled
3126 obj.Spec.Template.Spec.Containers = append(obj.Spec.Template.Spec.Containers[:i], obj.Spec.Template.Spec.Containers[i+1:]...)
3127 return nil
3128 }
3129 if config.Driver.UsePrecompiledDrivers() {
3130 return fmt.Errorf("GDRCopy is not supported along with pre-compiled NVIDIA drivers")
3131 }
3132
3133 gdrcopyContainer := &obj.Spec.Template.Spec.Containers[i]
3134
3135 // update nvidia-gdrcopy image and pull policy
3136 gdrcopyImage, err := resolveDriverTag(n, config.GDRCopy)
3137 if err != nil {
3138 return err
3139 }
3140 if gdrcopyImage != "" {
3141 gdrcopyContainer.Image = gdrcopyImage
3142 }
3143 if config.GDRCopy.ImagePullPolicy != "" {
3144 gdrcopyContainer.ImagePullPolicy = gpuv1.ImagePullPolicy(config.GDRCopy.ImagePullPolicy)
3145 }
3146
3147 // set image pull secrets
3148 if len(config.GDRCopy.ImagePullSecrets) > 0 {
3149 addPullSecrets(&obj.Spec.Template.Spec, config.GDRCopy.ImagePullSecrets)
3150 }
3151
3152 // set/append environment variables for gdrcopy container
3153 if len(config.GDRCopy.Env) > 0 {
3154 for _, env := range config.GDRCopy.Env {
3155 setContainerEnv(gdrcopyContainer, env.Name, env.Value)
3156 }
3157 }
3158
3159 if config.Driver.RepoConfig != nil && config.Driver.RepoConfig.ConfigMapName != "" {
3160 // note: transformDriverContainer() will have already created a Volume backed by the ConfigMap.
3161 // Only add a VolumeMount for nvidia-gdrcopy-ctr.
3162 destinationDir, err := n.getRepoConfigPath()
3163 if err != nil {
3164 return fmt.Errorf("ERROR: failed to get destination directory for custom repo config: %w", err)
3165 }
3166 volumeMounts, _, err := createConfigMapVolumeMounts(n, config.Driver.RepoConfig.ConfigMapName, destinationDir)
3167 if err != nil {
3168 return fmt.Errorf("ERROR: failed to create ConfigMap VolumeMounts for custom package repo config: %w", err)
3169 }
3170 gdrcopyContainer.VolumeMounts = append(gdrcopyContainer.VolumeMounts, volumeMounts...)
3171 }
3172
3173 // set any custom ssl key/certificate configuration provided
3174 if config.Driver.CertConfig != nil && config.Driver.CertConfig.Name != "" {

Callers 1

TransformDriverFunction · 0.85

Calls 10

resolveDriverTagFunction · 0.85
addPullSecretsFunction · 0.85
setContainerEnvFunction · 0.85
createSecretEnvReferenceFunction · 0.85
getRepoConfigPathMethod · 0.80
getCertConfigPathMethod · 0.80
IsEnabledMethod · 0.45
UsePrecompiledDriversMethod · 0.45

Tested by

no test coverage detected