| 1612 | } |
| 1613 | |
| 1614 | func TransformMPSControlDaemon(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error { |
| 1615 | // update validation container |
| 1616 | err := transformValidationInitContainer(obj, config) |
| 1617 | if err != nil { |
| 1618 | return err |
| 1619 | } |
| 1620 | |
| 1621 | image, err := gpuv1.ImagePath(&config.DevicePlugin) |
| 1622 | if err != nil { |
| 1623 | return err |
| 1624 | } |
| 1625 | imagePullPolicy := gpuv1.ImagePullPolicy(config.DevicePlugin.ImagePullPolicy) |
| 1626 | |
| 1627 | // update image path and imagePullPolicy for 'mps-control-daemon-mounts' initContainer |
| 1628 | if initCtr := findContainerByName(obj.Spec.Template.Spec.InitContainers, "mps-control-daemon-mounts"); initCtr != nil { |
| 1629 | initCtr.Image = image |
| 1630 | initCtr.ImagePullPolicy = imagePullPolicy |
| 1631 | } |
| 1632 | |
| 1633 | // update image path and imagePullPolicy for main container |
| 1634 | mpsControlMainContainer := findContainerByName(obj.Spec.Template.Spec.Containers, "mps-control-daemon-ctr") |
| 1635 | if mpsControlMainContainer == nil { |
| 1636 | return fmt.Errorf("failed to find main container 'mps-control-daemon-ctr'") |
| 1637 | } |
| 1638 | mpsControlMainContainer.Image = image |
| 1639 | mpsControlMainContainer.ImagePullPolicy = imagePullPolicy |
| 1640 | |
| 1641 | // set image pull secrets |
| 1642 | if len(config.DevicePlugin.ImagePullSecrets) > 0 { |
| 1643 | addPullSecrets(&obj.Spec.Template.Spec, config.DevicePlugin.ImagePullSecrets) |
| 1644 | } |
| 1645 | |
| 1646 | // set resource limits |
| 1647 | if config.DevicePlugin.Resources != nil { |
| 1648 | // apply resource limits to all containers |
| 1649 | for i := range obj.Spec.Template.Spec.Containers { |
| 1650 | obj.Spec.Template.Spec.Containers[i].Resources.Requests = config.DevicePlugin.Resources.Requests |
| 1651 | obj.Spec.Template.Spec.Containers[i].Resources.Limits = config.DevicePlugin.Resources.Limits |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | // apply plugin configuration through ConfigMap if one is provided |
| 1656 | err = handleDevicePluginConfig(obj, config) |
| 1657 | if err != nil { |
| 1658 | return err |
| 1659 | } |
| 1660 | |
| 1661 | setRuntimeClassName(&obj.Spec.Template.Spec, config, n.runtime) |
| 1662 | setNRIPluginAnnotation(&obj.Spec.Template.ObjectMeta, &config.CDI, mpsControlMainContainer.Name) |
| 1663 | |
| 1664 | // update env required for MIG support |
| 1665 | applyMIGConfiguration(mpsControlMainContainer, config.MIG.Strategy) |
| 1666 | |
| 1667 | // update MPS volumes if a custom MPS root is configured |
| 1668 | if config.DevicePlugin.MPS != nil && config.DevicePlugin.MPS.Root != "" && |
| 1669 | config.DevicePlugin.MPS.Root != DefaultMPSRoot { |
| 1670 | for i, volume := range obj.Spec.Template.Spec.Volumes { |
| 1671 | switch volume.Name { |