Search in sources :

Example 71 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project devspaces-images by redhat-developer.

the class KubernetesEnvironmentPodsValidatorTest method shouldThrowExceptionWhenMachineIsDeclaredButThereIsNotContainerInKubernetesRecipe.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Environment contains machines that are missing in recipe: pod1/db")
public void shouldThrowExceptionWhenMachineIsDeclaredButThereIsNotContainerInKubernetesRecipe() throws Exception {
    // given
    String podName = "pod1";
    Pod pod = createPod("pod1", "main");
    PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
    when(kubernetesEnvironment.getPodsData()).thenReturn(ImmutableMap.of(podName, podData));
    when(kubernetesEnvironment.getMachines()).thenReturn(ImmutableMap.of(podName + "/db", mock(InternalMachineConfig.class)));
    // when
    podsValidator.validate(kubernetesEnvironment);
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.testng.annotations.Test)

Example 72 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project devspaces-images by redhat-developer.

the class KubernetesEnvironmentPodsValidatorTest method shouldThrowExceptionWhenPodHasVolumeThatReferencesMissingPVC.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Pod 'pod1' contains volume 'user-data' with PVC sources that references missing PVC 'non-existing'")
public void shouldThrowExceptionWhenPodHasVolumeThatReferencesMissingPVC() throws Exception {
    // given
    String podName = "pod1";
    Pod pod = createPod("pod1", "main");
    pod.getSpec().getVolumes().add(new VolumeBuilder().withName("user-data").withNewPersistentVolumeClaim().withClaimName("non-existing").endPersistentVolumeClaim().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) Pod(io.fabric8.kubernetes.api.model.Pod) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Test(org.testng.annotations.Test)

Example 73 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project devspaces-images by redhat-developer.

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 74 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project devspaces-images by redhat-developer.

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 75 with PodData

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project devspaces-images by redhat-developer.

the class KubernetesEnvironmentPodsValidatorTest method shouldThrowExceptionWhenContainerHasVolumeMountThatReferencesMissingPodVolume.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Container 'main' in pod 'pod1' contains volume mount that references missing volume 'non-existing'")
public void shouldThrowExceptionWhenContainerHasVolumeMountThatReferencesMissingPodVolume() throws Exception {
    // given
    String podName = "pod1";
    Pod pod = createPod("pod1", "main");
    pod.getSpec().getContainers().get(0).getVolumeMounts().add(new VolumeMountBuilder().withName("non-existing").withMountPath("/tmp/data").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) Pod(io.fabric8.kubernetes.api.model.Pod) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) 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