use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class OpenShiftEnvironmentFactoryTest method shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing.
@Test
public void shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewSpec().endSpec().build();
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment-test").endMetadata().withNewSpec().withTemplate(podTemplate).endSpec().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment));
// when
final KubernetesEnvironment k8sEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
Deployment deploymentTest = k8sEnv.getDeploymentsCopy().get("deployment-test");
assertNotNull(deploymentTest);
PodTemplateSpec resultPodTemplate = deploymentTest.getSpec().getTemplate();
assertEquals(resultPodTemplate.getMetadata().getName(), "deployment-test");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class OpenShiftEnvironmentFactoryTest method shouldCreateOpenShiftEnvironmentWithServicesFromRecipe.
@Test
public void shouldCreateOpenShiftEnvironmentWithServicesFromRecipe() throws Exception {
// given
Service service1 = new ServiceBuilder().withNewMetadata().withName("service1").endMetadata().build();
Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(service1, service2));
// when
KubernetesEnvironment osEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
assertEquals(osEnv.getServices().size(), 2);
assertEquals(osEnv.getServices().get("service1"), service1);
assertEquals(osEnv.getServices().get("service2"), service2);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class ChePluginsVolumeApplier method provisionPVCPodVolume.
private io.fabric8.kubernetes.api.model.Volume provisionPVCPodVolume(Volume volume, KubernetesEnvironment.PodData pod, KubernetesEnvironment k8sEnv) {
String pvcName = volume.getName();
if (!k8sEnv.getPersistentVolumeClaims().containsKey(pvcName)) {
final PersistentVolumeClaim pvc = newPVC(pvcName, pvcAccessMode, pvcQuantity, pvcStorageClassName);
k8sEnv.getPersistentVolumeClaims().put(pvcName, pvc);
}
PodSpec podSpec = pod.getSpec();
Optional<io.fabric8.kubernetes.api.model.Volume> volumeOpt = podSpec.getVolumes().stream().filter(vm -> vm.getPersistentVolumeClaim() != null && pvcName.equals(vm.getPersistentVolumeClaim().getClaimName())).findAny();
io.fabric8.kubernetes.api.model.Volume podVolume;
if (volumeOpt.isPresent()) {
podVolume = volumeOpt.get();
} else {
podVolume = newVolume(pvcName, pvcName);
podSpec.getVolumes().add(podVolume);
}
return podVolume;
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class SidecarServicesProvisionerTest method shouldNotDuplicateServicesWhenThereIsConflictingServiceInK8sEnv.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Applying of sidecar tooling failed. Kubernetes service with name '" + CONFLICTING_SERVICE_NAME + "' already exists in the workspace environment.")
public void shouldNotDuplicateServicesWhenThereIsConflictingServiceInK8sEnv() throws Exception {
List<ChePluginEndpoint> actualEndpoints = singletonList(new ChePluginEndpoint().name(CONFLICTING_SERVICE_NAME).targetPort(8080));
endpoints.addAll(actualEndpoints);
KubernetesEnvironment kubernetesEnvironment = KubernetesEnvironment.builder().setServices(singletonMap(CONFLICTING_SERVICE_NAME, new Service())).build();
provisioner.provision(kubernetesEnvironment);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class SidecarServicesProvisionerTest method shouldNotDuplicateServicesWhenThereAreConflictingEndpoints.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Applying of sidecar tooling failed. Kubernetes service with name '" + CONFLICTING_SERVICE_NAME + "' already exists in the workspace environment.")
public void shouldNotDuplicateServicesWhenThereAreConflictingEndpoints() throws Exception {
List<ChePluginEndpoint> actualEndpoints = asList(new ChePluginEndpoint().name(CONFLICTING_SERVICE_NAME).targetPort(8080), new ChePluginEndpoint().name(CONFLICTING_SERVICE_NAME).targetPort(10000));
endpoints.addAll(actualEndpoints);
KubernetesEnvironment kubernetesEnvironment = KubernetesEnvironment.builder().build();
provisioner.provision(kubernetesEnvironment);
}
Aggregations