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

Function TransformGPUDiscoveryPlugin

controllers/object_controls.go:910–975  ·  view source on GitHub ↗

TransformGPUDiscoveryPlugin transforms GPU discovery daemonset with required config as per ClusterPolicy

(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController)

Source from the content-addressed store, hash-verified

908
909// TransformGPUDiscoveryPlugin transforms GPU discovery daemonset with required config as per ClusterPolicy
910func TransformGPUDiscoveryPlugin(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error {
911 // update validation container
912 err := transformValidationInitContainer(obj, config)
913 if err != nil {
914 return err
915 }
916
917 // update image
918 img, err := gpuv1.ImagePath(&config.GPUFeatureDiscovery)
919 if err != nil {
920 return err
921 }
922 obj.Spec.Template.Spec.Containers[0].Image = img
923
924 // update image pull policy
925 obj.Spec.Template.Spec.Containers[0].ImagePullPolicy = gpuv1.ImagePullPolicy(config.GPUFeatureDiscovery.ImagePullPolicy)
926
927 // set image pull secrets
928 if len(config.GPUFeatureDiscovery.ImagePullSecrets) > 0 {
929 addPullSecrets(&obj.Spec.Template.Spec, config.GPUFeatureDiscovery.ImagePullSecrets)
930 }
931
932 // set resource limits
933 if config.GPUFeatureDiscovery.Resources != nil {
934 // apply resource limits to all containers
935 for i := range obj.Spec.Template.Spec.Containers {
936 obj.Spec.Template.Spec.Containers[i].Resources.Requests = config.GPUFeatureDiscovery.Resources.Requests
937 obj.Spec.Template.Spec.Containers[i].Resources.Limits = config.GPUFeatureDiscovery.Resources.Limits
938 }
939 }
940
941 // set arguments if specified for driver container
942 if len(config.GPUFeatureDiscovery.Args) > 0 {
943 obj.Spec.Template.Spec.Containers[0].Args = config.GPUFeatureDiscovery.Args
944 }
945
946 // If we are on an OpenShift cluster, we disable the NodeFeature API as a node feature label source
947 // We can remove this once OpenShift's NFD instances start supporting the NodeFeature API
948 if len(n.openshift) > 0 {
949 setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), "USE_NODE_FEATURE_API", "false")
950 }
951
952 // set/append environment variables for exporter container
953 if len(config.GPUFeatureDiscovery.Env) > 0 {
954 for _, env := range config.GPUFeatureDiscovery.Env {
955 setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), env.Name, env.Value)
956 }
957 }
958
959 // apply plugin configuration through ConfigMap if one is provided
960 err = handleDevicePluginConfig(obj, config)
961 if err != nil {
962 return err
963 }
964
965 setRuntimeClassName(&obj.Spec.Template.Spec, config, n.runtime)
966 setNRIPluginAnnotation(&obj.Spec.Template.ObjectMeta, &config.CDI, obj.Spec.Template.Spec.Containers[0].Name)
967

Calls 8

addPullSecretsFunction · 0.85
setContainerEnvFunction · 0.85
handleDevicePluginConfigFunction · 0.85
setRuntimeClassNameFunction · 0.85
setNRIPluginAnnotationFunction · 0.85
applyMIGConfigurationFunction · 0.85
applyHostNetworkConfigFunction · 0.85