Search in sources :

Example 1 with KubernetesEnvironment

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");
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.testng.annotations.Test)

Example 2 with KubernetesEnvironment

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);
}
Also used : InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Test(org.testng.annotations.Test)

Example 3 with KubernetesEnvironment

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;
}
Also used : KubernetesObjectUtil.newPVC(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC) Container(io.fabric8.kubernetes.api.model.Container) Collection(java.util.Collection) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Singleton(javax.inject.Singleton) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) Inject(javax.inject.Inject) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Optional(java.util.Optional) Named(javax.inject.Named) KubernetesObjectUtil.newVolumeMount(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Example 4 with KubernetesEnvironment

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);
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Service(io.fabric8.kubernetes.api.model.Service) Test(org.testng.annotations.Test)

Example 5 with 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);
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Aggregations

KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)94 Test (org.testng.annotations.Test)68 Map (java.util.Map)30 HashMap (java.util.HashMap)28 Service (io.fabric8.kubernetes.api.model.Service)26 Container (io.fabric8.kubernetes.api.model.Container)24 Pod (io.fabric8.kubernetes.api.model.Pod)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)20 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)20 ArrayList (java.util.ArrayList)19 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)18 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)18 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)18 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)14 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)14 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)14 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)14