Search in sources :

Example 21 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.

the class KubernetesEnvironmentPodsValidatorTest method shouldThrowExceptionWhenPodHasNoSpec.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Pod 'pod1' with missing metadata")
public void shouldThrowExceptionWhenPodHasNoSpec() throws Exception {
    // given
    PodData podData = new PodData(null, new ObjectMetaBuilder().withName("pod1").build());
    when(kubernetesEnvironment.getPodsData()).thenReturn(ImmutableMap.of("pod1", podData));
    // when
    podsValidator.validate(kubernetesEnvironment);
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Example 22 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.

the class KubernetesEnvironmentPodsValidatorTest method shouldThrowExceptionWhenInitContainerHasVolumeMountThatReferencesMissingPodVolume.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Container 'foo' in pod 'pod1' contains volume mount that references missing volume 'non-existing'")
public void shouldThrowExceptionWhenInitContainerHasVolumeMountThatReferencesMissingPodVolume() throws Exception {
    // given
    String podName = "pod1";
    Pod pod = createPod("pod1", "main");
    pod.getSpec().getInitContainers().add(new ContainerBuilder().withName("foo").withVolumeMounts(new VolumeMountBuilder().withName("non-existing").withMountPath("/tmp/data").build()).build());
    PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
    when(kubernetesEnvironment.getPodsData()).thenReturn(ImmutableMap.of(podName, podData));
    when(kubernetesEnvironment.getMachines()).thenReturn(ImmutableMap.of(podName + "/main", mock(InternalMachineConfig.class)));
    // when
    podsValidator.validate(kubernetesEnvironment);
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Test(org.testng.annotations.Test)

Example 23 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.

the class KubernetesEnvironmentPodsValidatorTest method shouldThrowExceptionWhenPodHasNoMetadata.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Environment contains pod with missing metadata")
public void shouldThrowExceptionWhenPodHasNoMetadata() throws Exception {
    // given
    PodData podData = new PodData(new PodSpec(), null);
    when(kubernetesEnvironment.getPodsData()).thenReturn(ImmutableMap.of("", podData));
    // when
    podsValidator.validate(kubernetesEnvironment);
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Test(org.testng.annotations.Test)

Example 24 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.

the class PodMergerTest method shouldThrownAnExceptionIfVolumeNameCollisionHappened.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Pods have to have volumes with unique names but there are multiple `volume` volumes")
public void shouldThrownAnExceptionIfVolumeNameCollisionHappened() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withVolumes(new VolumeBuilder().withName("volume").build()).build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withVolumes(new VolumeBuilder().withName("volume").build()).build();
    podSpec2.setAdditionalProperty("add2", 2L);
    PodData podData2 = new PodData(podSpec2, new ObjectMetaBuilder().build());
    // when
    podMerger.merge(Arrays.asList(podData1, podData2));
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Example 25 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.

the class PodMergerTest method shouldAssignServiceAccountSharedByPods.

@Test
public void shouldAssignServiceAccountSharedByPods() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withServiceAccount("sa").build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withServiceAccount("sa").build();
    podSpec2.setAdditionalProperty("add2", 2L);
    PodData podData2 = new PodData(podSpec2, new ObjectMetaBuilder().build());
    // when
    Deployment merged = podMerger.merge(Arrays.asList(podData1, podData2));
    // then
    PodTemplateSpec podTemplate = merged.getSpec().getTemplate();
    String sa = podTemplate.getSpec().getServiceAccount();
    assertEquals(sa, "sa");
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Aggregations

PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)156 Test (org.testng.annotations.Test)86 Container (io.fabric8.kubernetes.api.model.Container)62 Pod (io.fabric8.kubernetes.api.model.Pod)56 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)52 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)52 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)40 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)36 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)34 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)30 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)28 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)26 Map (java.util.Map)22 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)22 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)20 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)20 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)20 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)16 Volume (io.fabric8.kubernetes.api.model.Volume)16 HashMap (java.util.HashMap)16