Search in sources :

Example 21 with InternalRecipe

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

the class KubernetesEnvironmentFactoryTest method shouldCreateK8sEnvironmentWithServicesFromRecipe.

@Test
public void shouldCreateK8sEnvironmentWithServicesFromRecipe() 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 k8sEnv = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    // then
    assertEquals(k8sEnv.getServices().size(), 2);
    assertEquals(k8sEnv.getServices().get("service1"), service1);
    assertEquals(k8sEnv.getServices().get("service2"), service2);
}
Also used : InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Test(org.testng.annotations.Test)

Example 22 with InternalRecipe

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

the class KubernetesEnvironmentFactoryTest method exceptionOnObjectWithNoKindSpecified.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Environment contains object without specified kind field")
public void exceptionOnObjectWithNoKindSpecified() throws Exception {
    HasMetadata object = mock(HasMetadata.class);
    when(object.getKind()).thenReturn(null);
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(object));
    k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) Test(org.testng.annotations.Test)

Example 23 with InternalRecipe

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

the class KubernetesEnvironmentFactoryTest 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));
    k8sEnvFactory.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 24 with InternalRecipe

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

the class KubernetesEnvironmentFactoryTest method shouldReconfigureServiceToMatchMergedDeployment.

@Test
public void shouldReconfigureServiceToMatchMergedDeployment() throws Exception {
    // given
    Pod pod1 = new PodBuilder().withNewMetadata().withName("bare-pod1").withLabels(ImmutableMap.of("name", "pod1")).endMetadata().withNewSpec().endSpec().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName("bare-pod2").withLabels(ImmutableMap.of("name", "pod2")).endMetadata().withNewSpec().endSpec().build();
    Service service1 = new ServiceBuilder().withNewMetadata().withName("pod1-service").endMetadata().withNewSpec().withSelector(ImmutableMap.of("name", "pod1")).endSpec().build();
    Service service2 = new ServiceBuilder().withNewMetadata().withName("pod2-service").endMetadata().withNewSpec().withSelector(ImmutableMap.of("name", "pod2")).endSpec().build();
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(pod1, pod2, service1, service2));
    Deployment merged = createEmptyDeployment("merged");
    when(podMerger.merge(any())).thenReturn(merged);
    // when
    final KubernetesEnvironment k8sEnv = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    // then
    verify(podMerger).merge(asList(new PodData(pod1), new PodData(pod2)));
    PodData mergedPodData = k8sEnv.getPodsData().get("merged");
    assertEquals(mergedPodData.getMetadata().getLabels().get(DEPLOYMENT_NAME_LABEL), "merged");
    assertTrue(k8sEnv.getServices().values().stream().allMatch(s -> ImmutableMap.of(DEPLOYMENT_NAME_LABEL, "merged").equals(s.getSpec().getSelector())));
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) Listeners(org.testng.annotations.Listeners) Test(org.testng.annotations.Test) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Collections.singletonList(java.util.Collections.singletonList) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Arrays.asList(java.util.Arrays.asList) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Secret(io.fabric8.kubernetes.api.model.Secret) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Container(io.fabric8.kubernetes.api.model.Container) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) INGRESSES_IGNORED_WARNING_MESSAGE(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings.INGRESSES_IGNORED_WARNING_MESSAGE) Mockito.lenient(org.mockito.Mockito.lenient) ValidationException(org.eclipse.che.api.core.ValidationException) ImmutableList(com.google.common.collect.ImmutableList) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) INGRESSES_IGNORED_WARNING_CODE(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings.INGRESSES_IGNORED_WARNING_CODE) Service(io.fabric8.kubernetes.api.model.Service) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) Collections.emptyMap(java.util.Collections.emptyMap) DEPLOYMENT_NAME_LABEL(org.eclipse.che.workspace.infrastructure.kubernetes.environment.PodMerger.DEPLOYMENT_NAME_LABEL) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Mockito.verify(org.mockito.Mockito.verify) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Pod(io.fabric8.kubernetes.api.model.Pod) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Test(org.testng.annotations.Test)

Example 25 with InternalRecipe

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

the class KubernetesEnvironmentFactoryTest 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 k8sEnv = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    // then
    assertEquals(k8sEnv.getPodsCopy().size(), 1);
    assertEquals(k8sEnv.getPodsCopy().get("pod"), pod);
    assertEquals(k8sEnv.getPodsData().size(), 1);
    assertEquals(k8sEnv.getPodsData().get("pod").getMetadata(), pod.getMetadata());
    assertEquals(k8sEnv.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) 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