Openshift4TrustedCAProvisioner { public void provision(KubernetesEnvironment k8sEnv, OpenShiftProject project) throws InfrastructureException { if (!trustedStoreInitialized) { return; } if (!project.configMaps().get(configMapName).isPresent()) { k8sEnv .getConfigMaps() .put( configMapName, new ConfigMapBuilder() .withMetadata( new ObjectMetaBuilder() .withName(configMapName) .withLabels(configMapLabelKeyValue) .build()) .build()); } for (PodData pod : k8sEnv.getPodsData().values()) { if (pod.getRole() == PodRole.DEPLOYMENT) { if (pod.getSpec() .getVolumes() .stream() .noneMatch(v -> v.getName().equals(CHE_TRUST_STORE_VOLUME))) { pod.getSpec() .getVolumes() .add( new VolumeBuilder() .withName(CHE_TRUST_STORE_VOLUME) .withConfigMap( new ConfigMapVolumeSourceBuilder().withName(configMapName).build()) .build()); } } for (Container container : pod.getSpec().getInitContainers()) { provisionTrustStoreVolumeMountIfNeeded(container); } for (Container container : pod.getSpec().getContainers()) { provisionTrustStoreVolumeMountIfNeeded(container); } } } @Inject  Openshift4TrustedCAProvisioner(
      @Nullable @Named("che.trusted_ca_bundles_configmap") String caBundleConfigMap,
      @Named("che.infra.openshift.trusted_ca_bundles_config_map") String configMapName,
      @Named("che.infra.openshift.trusted_ca_bundles_config_map_labels") String configMapLabel,
      @Named("che.infra.openshift.trusted_ca_bundles_mount_path") String certificateMountPath); boolean isTrustedStoreInitialized(); void provision(KubernetesEnvironment k8sEnv, OpenShiftProject project); static final String CHE_TRUST_STORE_VOLUME; }
@Test public void shouldDoNothingIfCAStoreIsNotInitialized() throws Exception { Openshift4TrustedCAProvisioner localProvisioner = new Openshift4TrustedCAProvisioner( null, CONFIGMAP_NAME, CONFIGMAP_LABELS, CERTIFICATE_MOUNT_PATH); localProvisioner.provision(k8sEnv, openShiftProject); verifyZeroInteractions(k8sEnv, openShiftProject, clientFactory, openShiftProject); }
@Test public void shouldProvisionTrustStoreMapAndMountIt() throws Exception { Pod pod = newPod(); PodData podData = new PodData(pod.getSpec(), pod.getMetadata()); doReturn(of(POD_NAME, podData)).when(k8sEnv).getPodsData(); trustedCAProvisioner.provision(k8sEnv, openShiftProject); assertEquals(envConfigMaps.size(), 1); assertTrue(envConfigMaps.get(CONFIGMAP_NAME).getMetadata().getLabels().containsKey("foo")); assertEquals(envConfigMaps.get(CONFIGMAP_NAME).getMetadata().getLabels().get("foo"), "bar"); PodSpec podSpec = pod.getSpec(); assertEquals(podSpec.getVolumes().size(), 1); assertEquals(podSpec.getVolumes().get(0).getConfigMap().getName(), CONFIGMAP_NAME); assertTrue( podSpec .getContainers() .stream() .allMatch( c -> c.getVolumeMounts().get(0).getMountPath().equals(CERTIFICATE_MOUNT_PATH))); }