Search in sources :

Example 31 with PodData

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

the class PodMergerTest method shouldFailServiceAccountDiffersInPods.

@Test(expectedExceptions = ValidationException.class)
public void shouldFailServiceAccountDiffersInPods() 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("sb").build();
    podSpec2.setAdditionalProperty("add2", 2L);
    PodData podData2 = new PodData(podSpec2, new ObjectMetaBuilder().build());
    // when
    Deployment merged = podMerger.merge(Arrays.asList(podData1, podData2));
// then
// exception is thrown
}
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) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Example 32 with PodData

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

the class PodMergerTest method shouldMatchMergedPodTemplateLabelsWithDeploymentSelector.

@Test
public void shouldMatchMergedPodTemplateLabelsWithDeploymentSelector() throws Exception {
    // given
    ObjectMeta podMeta1 = new ObjectMetaBuilder().withName("ignored-1").withAnnotations(ImmutableMap.of("ann1", "v1")).withLabels(ImmutableMap.of("label1", "v1")).build();
    podMeta1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(new PodSpecBuilder().build(), podMeta1);
    // when
    Deployment merged = podMerger.merge(Collections.singletonList(podData1));
    // then
    PodTemplateSpec podTemplate = merged.getSpec().getTemplate();
    ObjectMeta podMeta = podTemplate.getMetadata();
    Map<String, String> deploymentSelector = merged.getSpec().getSelector().getMatchLabels();
    assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet()));
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Example 33 with PodData

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

the class PodMergerTest method shouldGenerateInitContainerNamesIfCollisionHappened.

@Test
public void shouldGenerateInitContainerNamesIfCollisionHappened() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withInitContainers(new ContainerBuilder().withName("initC").build()).build();
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withInitContainers(new ContainerBuilder().withName("initC").build()).build();
    PodData podData2 = new PodData(podSpec2, new ObjectMetaBuilder().build());
    // when
    Deployment merged = podMerger.merge(Arrays.asList(podData1, podData2));
    // then
    PodTemplateSpec podTemplate = merged.getSpec().getTemplate();
    List<Container> initContainers = podTemplate.getSpec().getInitContainers();
    assertEquals(initContainers.size(), 2);
    Container container1 = initContainers.get(0);
    assertEquals(container1.getName(), "initC");
    Container container2 = initContainers.get(1);
    assertNotEquals(container2.getName(), "initC");
    assertTrue(container2.getName().startsWith("initC"));
}
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) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) 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)

Example 34 with PodData

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

the class PodMergerTest method shouldMergeSpecsOfPodsData.

@Test
public void shouldMergeSpecsOfPodsData() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withContainers(new ContainerBuilder().withName("c1").build()).withInitContainers(new ContainerBuilder().withName("initC1").build()).withVolumes(new VolumeBuilder().withName("v1").build()).withNodeSelector(Map.of("foo1", "bar1")).withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret1").build()).withTolerations(new Toleration("Effect", "key", "operator", 0L, "value1")).build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withContainers(new ContainerBuilder().withName("c2").build()).withInitContainers(new ContainerBuilder().withName("initC2").build()).withVolumes(new VolumeBuilder().withName("v2").build()).withNodeSelector(Map.of("foo2", "bar2")).withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret2").build()).withTolerations(new Toleration("Effect", "key", "operator", 0L, "value1"), new Toleration("Effect", "key", "operator", 0L, "value2")).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();
    verifyContainsAllFrom(podTemplate.getSpec(), podData1.getSpec());
    verifyContainsAllFrom(podTemplate.getSpec(), podData2.getSpec());
}
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) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Toleration(io.fabric8.kubernetes.api.model.Toleration) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) Test(org.testng.annotations.Test)

Example 35 with PodData

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

the class PodMergerTest method shouldNotAddImagePullPolicyTwice.

@Test
public void shouldNotAddImagePullPolicyTwice() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret").build()).build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret").build()).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();
    List<LocalObjectReference> imagePullSecrets = podTemplate.getSpec().getImagePullSecrets();
    assertEquals(imagePullSecrets.size(), 1);
    assertEquals(imagePullSecrets.get(0).getName(), "secret");
}
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) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) 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