apply spec changes to make custom configurations provided via a ConfigMap available to all containers
(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec)
| 2824 | |
| 2825 | // apply spec changes to make custom configurations provided via a ConfigMap available to all containers |
| 2826 | func handleDevicePluginConfig(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec) error { |
| 2827 | if !isCustomPluginConfigSet(config.DevicePlugin.Config) { |
| 2828 | // remove config-manager-init container |
| 2829 | for i, initContainer := range obj.Spec.Template.Spec.InitContainers { |
| 2830 | if initContainer.Name != "config-manager-init" { |
| 2831 | continue |
| 2832 | } |
| 2833 | obj.Spec.Template.Spec.InitContainers = append(obj.Spec.Template.Spec.InitContainers[:i], obj.Spec.Template.Spec.InitContainers[i+1:]...) |
| 2834 | } |
| 2835 | // remove config-manager sidecar container |
| 2836 | for i, container := range obj.Spec.Template.Spec.Containers { |
| 2837 | if container.Name != "config-manager" { |
| 2838 | continue |
| 2839 | } |
| 2840 | obj.Spec.Template.Spec.Containers = append(obj.Spec.Template.Spec.Containers[:i], obj.Spec.Template.Spec.Containers[i+1:]...) |
| 2841 | } |
| 2842 | return nil |
| 2843 | } |
| 2844 | |
| 2845 | // Apply custom configuration provided through ConfigMap |
| 2846 | // setup env for main container |
| 2847 | for i, container := range obj.Spec.Template.Spec.Containers { |
| 2848 | switch container.Name { |
| 2849 | case "nvidia-device-plugin": |
| 2850 | case "gpu-feature-discovery": |
| 2851 | case "mps-control-daemon-ctr": |
| 2852 | default: |
| 2853 | // skip if not the main container |
| 2854 | continue |
| 2855 | } |
| 2856 | setContainerEnv(&obj.Spec.Template.Spec.Containers[i], "CONFIG_FILE", "/config/config.yaml") |
| 2857 | // setup sharedvolume(emptydir) for main container |
| 2858 | addSharedMountsForPluginConfig(&obj.Spec.Template.Spec.Containers[i], config.DevicePlugin.Config) |
| 2859 | } |
| 2860 | |
| 2861 | // if hostPID is already set, we skip setting the shareProcessNamespace field |
| 2862 | // for context, go to https://github.com/kubernetes-client/go/blob/master/kubernetes/docs/V1PodSpec.md |
| 2863 | if !obj.Spec.Template.Spec.HostPID { |
| 2864 | // Enable process ns sharing for PID access |
| 2865 | shareProcessNamespace := true |
| 2866 | obj.Spec.Template.Spec.ShareProcessNamespace = &shareProcessNamespace |
| 2867 | } |
| 2868 | // setup volumes from configmap and shared emptyDir |
| 2869 | obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, createConfigMapVolume(config.DevicePlugin.Config.Name, nil)) |
| 2870 | obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, createEmptyDirVolume("config")) |
| 2871 | |
| 2872 | // apply env/volume changes to initContainer |
| 2873 | err := transformConfigManagerInitContainer(obj, config) |
| 2874 | if err != nil { |
| 2875 | return err |
| 2876 | } |
| 2877 | // apply env/volume changes to sidecarContainer |
| 2878 | err = transformConfigManagerSidecarContainer(obj, config) |
| 2879 | if err != nil { |
| 2880 | return err |
| 2881 | } |
| 2882 | return nil |
| 2883 | } |
no test coverage detected