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

Function TransformValidatorComponent

controllers/object_controls.go:2434–2546  ·  view source on GitHub ↗

TransformValidatorComponent applies changes to given validator component

(config *gpuv1.ClusterPolicySpec, podSpec *corev1.PodSpec, component string)

Source from the content-addressed store, hash-verified

2432
2433// TransformValidatorComponent applies changes to given validator component
2434func TransformValidatorComponent(config *gpuv1.ClusterPolicySpec, podSpec *corev1.PodSpec, component string) error {
2435 for i, initContainer := range podSpec.InitContainers {
2436 // skip if not component validation initContainer
2437 if !strings.Contains(initContainer.Name, fmt.Sprintf("%s-validation", component)) {
2438 continue
2439 }
2440 // update validation image
2441 image, err := gpuv1.ImagePath(&config.Validator)
2442 if err != nil {
2443 return err
2444 }
2445 podSpec.InitContainers[i].Image = image
2446 // update validation image pull policy
2447 if config.Validator.ImagePullPolicy != "" {
2448 podSpec.InitContainers[i].ImagePullPolicy = gpuv1.ImagePullPolicy(config.Validator.ImagePullPolicy)
2449 }
2450 // update the security context for the validator container
2451 transformValidatorSecurityContext(&podSpec.InitContainers[i])
2452
2453 switch component {
2454 case "cuda":
2455 // set additional env to indicate image, pullSecrets to spin-off cuda validation workload pod.
2456 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorImageEnvName, image)
2457 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorImagePullPolicyEnvName, config.Validator.ImagePullPolicy)
2458 var pullSecrets string
2459 if len(config.Validator.ImagePullSecrets) > 0 {
2460 pullSecrets = strings.Join(config.Validator.ImagePullSecrets, ",")
2461 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorImagePullSecretsEnvName, pullSecrets)
2462 }
2463 if podSpec.RuntimeClassName != nil {
2464 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorRuntimeClassEnvName, *podSpec.RuntimeClassName)
2465 }
2466 // set/append environment variables for cuda-validation container
2467 if len(config.Validator.CUDA.Env) > 0 {
2468 for _, env := range config.Validator.CUDA.Env {
2469 setContainerEnv(&(podSpec.InitContainers[i]), env.Name, env.Value)
2470 }
2471 }
2472 case "plugin":
2473 // remove plugin init container from validator Daemonset if it is not enabled
2474 if !config.DevicePlugin.IsEnabled() {
2475 podSpec.InitContainers = append(podSpec.InitContainers[:i], podSpec.InitContainers[i+1:]...)
2476 return nil
2477 }
2478 // set additional env to indicate image, pullSecrets to spin-off plugin validation workload pod.
2479 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorImageEnvName, image)
2480 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorImagePullPolicyEnvName, config.Validator.ImagePullPolicy)
2481 var pullSecrets string
2482 if len(config.Validator.ImagePullSecrets) > 0 {
2483 pullSecrets = strings.Join(config.Validator.ImagePullSecrets, ",")
2484 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorImagePullSecretsEnvName, pullSecrets)
2485 }
2486 if podSpec.RuntimeClassName != nil {
2487 setContainerEnv(&(podSpec.InitContainers[i]), ValidatorRuntimeClassEnvName, *podSpec.RuntimeClassName)
2488 }
2489 // apply mig-strategy env to spin off plugin-validation workload pod
2490 setContainerEnv(&(podSpec.InitContainers[i]), MigStrategyEnvName, string(config.MIG.Strategy))
2491 // set/append environment variables for plugin-validation container

Callers 3

TransformValidatorFunction · 0.85

Calls 3

setContainerEnvFunction · 0.85
IsEnabledMethod · 0.45

Tested by 1