applyOCPProxySpec applies proxy settings to podSpec
(n ClusterPolicyController, podSpec *corev1.PodSpec)
| 1111 | |
| 1112 | // applyOCPProxySpec applies proxy settings to podSpec |
| 1113 | func applyOCPProxySpec(n ClusterPolicyController, podSpec *corev1.PodSpec) error { |
| 1114 | // Pass HTTPS_PROXY, HTTP_PROXY and NO_PROXY env if set in clusterwide proxy for OCP |
| 1115 | proxy, err := GetClusterWideProxy(n.ctx) |
| 1116 | if err != nil { |
| 1117 | return fmt.Errorf("ERROR: failed to get clusterwide proxy object: %s", err) |
| 1118 | } |
| 1119 | |
| 1120 | if proxy == nil { |
| 1121 | // no clusterwide proxy configured |
| 1122 | return nil |
| 1123 | } |
| 1124 | |
| 1125 | for i, container := range podSpec.Containers { |
| 1126 | // skip if not nvidia-driver container |
| 1127 | if !strings.Contains(container.Name, "nvidia-driver") { |
| 1128 | continue |
| 1129 | } |
| 1130 | |
| 1131 | proxyEnv := getProxyEnv(proxy) |
| 1132 | if len(proxyEnv) != 0 { |
| 1133 | podSpec.Containers[i].Env = append(podSpec.Containers[i].Env, proxyEnv...) |
| 1134 | } |
| 1135 | |
| 1136 | // if user-ca-bundle is setup in proxy, create a trusted-ca configmap and add volume mount |
| 1137 | if proxy.Spec.TrustedCA.Name == "" { |
| 1138 | return nil |
| 1139 | } |
| 1140 | |
| 1141 | // create trusted-ca configmap to inject custom user ca bundle into it |
| 1142 | _, err = getOrCreateTrustedCAConfigMap(n, TrustedCAConfigMapName) |
| 1143 | if err != nil { |
| 1144 | return err |
| 1145 | } |
| 1146 | |
| 1147 | // mount trusted-ca configmap |
| 1148 | podSpec.Containers[i].VolumeMounts = append(podSpec.Containers[i].VolumeMounts, |
| 1149 | corev1.VolumeMount{ |
| 1150 | Name: TrustedCAConfigMapName, |
| 1151 | ReadOnly: true, |
| 1152 | MountPath: TrustedCABundleMountDir, |
| 1153 | }) |
| 1154 | podSpec.Volumes = append(podSpec.Volumes, |
| 1155 | corev1.Volume{ |
| 1156 | Name: TrustedCAConfigMapName, |
| 1157 | VolumeSource: corev1.VolumeSource{ |
| 1158 | ConfigMap: &corev1.ConfigMapVolumeSource{ |
| 1159 | LocalObjectReference: corev1.LocalObjectReference{ |
| 1160 | Name: TrustedCAConfigMapName, |
| 1161 | }, |
| 1162 | Items: []corev1.KeyToPath{ |
| 1163 | { |
| 1164 | Key: TrustedCABundleFileName, |
| 1165 | Path: TrustedCACertificate, |
| 1166 | }, |
| 1167 | }, |
| 1168 | }, |
| 1169 | }, |
| 1170 | }) |
no test coverage detected