getOrCreateTrustedCAConfigMap creates or returns an existing Trusted CA Bundle ConfigMap.
(n ClusterPolicyController, name string)
| 1174 | |
| 1175 | // getOrCreateTrustedCAConfigMap creates or returns an existing Trusted CA Bundle ConfigMap. |
| 1176 | func getOrCreateTrustedCAConfigMap(n ClusterPolicyController, name string) (*corev1.ConfigMap, error) { |
| 1177 | ctx := n.ctx |
| 1178 | configMap := &corev1.ConfigMap{ |
| 1179 | TypeMeta: metav1.TypeMeta{ |
| 1180 | Kind: "ConfigMap", |
| 1181 | APIVersion: corev1.SchemeGroupVersion.String(), |
| 1182 | }, |
| 1183 | ObjectMeta: metav1.ObjectMeta{ |
| 1184 | Name: name, |
| 1185 | Namespace: n.operatorNamespace, |
| 1186 | }, |
| 1187 | Data: map[string]string{ |
| 1188 | TrustedCABundleFileName: "", |
| 1189 | }, |
| 1190 | } |
| 1191 | |
| 1192 | // apply label "config.openshift.io/inject-trusted-cabundle: true", so that cert is automatically filled/updated. |
| 1193 | configMap.Labels = make(map[string]string) |
| 1194 | configMap.Labels["config.openshift.io/inject-trusted-cabundle"] = "true" |
| 1195 | |
| 1196 | logger := n.logger.WithValues("ConfigMap", configMap.Name, "Namespace", configMap.Namespace) |
| 1197 | |
| 1198 | if err := controllerutil.SetControllerReference(n.singleton, configMap, n.scheme); err != nil { |
| 1199 | return nil, err |
| 1200 | } |
| 1201 | |
| 1202 | found := &corev1.ConfigMap{} |
| 1203 | err := n.client.Get(ctx, types.NamespacedName{Namespace: configMap.Namespace, Name: configMap.Name}, found) |
| 1204 | if err != nil && apierrors.IsNotFound(err) { |
| 1205 | logger.Info("Not found, creating") |
| 1206 | err = n.client.Create(ctx, configMap) |
| 1207 | if err != nil { |
| 1208 | logger.Info("Couldn't create") |
| 1209 | return nil, fmt.Errorf("failed to create trusted CA bundle config map %q: %s", name, err) |
| 1210 | } |
| 1211 | return configMap, nil |
| 1212 | } else if err != nil { |
| 1213 | return nil, fmt.Errorf("failed to get trusted CA bundle config map %q: %s", name, err) |
| 1214 | } |
| 1215 | |
| 1216 | return found, nil |
| 1217 | } |
| 1218 | |
| 1219 | // get proxy env variables from cluster wide proxy in OCP |
| 1220 | func getProxyEnv(proxyConfig *apiconfigv1.Proxy) []corev1.EnvVar { |
no test coverage detected