Search in sources :

Example 36 with InternalRecipe

use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.

the class KubernetesEnvironmentFactoryTest 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 = k8sEnvFactory.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) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.testng.annotations.Test)

Example 37 with InternalRecipe

use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.

the class OpenShiftEnvironmentFactoryTest method addConfigMapsWhenRecipeContainsThem.

@Test
public void addConfigMapsWhenRecipeContainsThem() throws Exception {
    ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("test-configmap").endMetadata().build();
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(configMap));
    final KubernetesEnvironment parsed = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    assertEquals(parsed.getConfigMaps().size(), 1);
    assertEquals(parsed.getConfigMaps().values().iterator().next().getMetadata().getName(), configMap.getMetadata().getName());
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 38 with InternalRecipe

use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.

the class OpenShiftEnvironmentFactoryTest method exceptionOnObjectWithNoNameSpecified.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "MyObject name must not be null")
public void exceptionOnObjectWithNoNameSpecified() throws Exception {
    HasMetadata object = mock(HasMetadata.class);
    when(object.getKind()).thenReturn("MyObject");
    when(object.getMetadata()).thenReturn(new ObjectMetaBuilder().withName(null).build());
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(object));
    osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Example 39 with InternalRecipe

use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.

the class OpenShiftEnvironmentFactoryTest method shouldCreateOpenShiftEnvironmentWithPVCsFromRecipe.

@Test
public void shouldCreateOpenShiftEnvironmentWithPVCsFromRecipe() throws Exception {
    // given
    PersistentVolumeClaim pvc1 = new PersistentVolumeClaimBuilder().withNewMetadata().withName("pvc1").endMetadata().build();
    PersistentVolumeClaim pvc2 = new PersistentVolumeClaimBuilder().withNewMetadata().withName("pvc2").endMetadata().build();
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(pvc1, pvc2));
    // when
    OpenShiftEnvironment osEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    // then
    assertEquals(osEnv.getPersistentVolumeClaims().size(), 2);
    assertEquals(osEnv.getPersistentVolumeClaims().get("pvc1"), pvc1);
    assertEquals(osEnv.getPersistentVolumeClaims().get("pvc2"), pvc2);
}
Also used : InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Test(org.testng.annotations.Test)

Example 40 with InternalRecipe

use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.

the class OpenShiftEnvironmentFactoryTest method addPodsWhenRecipeContainsThem.

@Test
public void addPodsWhenRecipeContainsThem() throws Exception {
    // given
    Pod pod = new PodBuilder().withNewMetadata().withName("pod").endMetadata().withSpec(new PodSpec()).build();
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(pod));
    // when
    KubernetesEnvironment osEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    // then
    assertEquals(osEnv.getPodsCopy().size(), 1);
    assertEquals(osEnv.getPodsCopy().get("pod"), pod);
    assertEquals(osEnv.getPodsData().size(), 1);
    assertEquals(osEnv.getPodsData().get("pod").getMetadata(), pod.getMetadata());
    assertEquals(osEnv.getPodsData().get("pod").getSpec(), pod.getSpec());
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Aggregations

InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)60 Test (org.testng.annotations.Test)60 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)20 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)16 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)16 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)16 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)16 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)14 Pod (io.fabric8.kubernetes.api.model.Pod)12 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)12 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)12 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)8 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)8 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)8 PersistentVolumeClaimBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder)8 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)8 Secret (io.fabric8.kubernetes.api.model.Secret)8 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)8 Service (io.fabric8.kubernetes.api.model.Service)8