Search in sources :

Example 26 with PodData

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

the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionEnvIntoK8SList.

@Test
public void shouldProvisionEnvIntoK8SList() throws Exception {
    // given
    List<HasMetadata> k8sList = new ArrayList<>();
    Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").endMetadata().withNewSpec().endSpec().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").endMetadata().withNewSpec().endSpec().build();
    k8sList.add(pod1);
    k8sList.add(pod2);
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    List<EnvImpl> envToApply = singletonList(new EnvImpl("TEST_ENV", "anyValue"));
    component.setEnv(envToApply);
    // when
    applier.apply(workspaceConfig, component, s -> "content");
    // then
    envVars.apply(new PodData(pod1), envToApply);
    envVars.apply(new PodData(pod2), envToApply);
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Pod(io.fabric8.kubernetes.api.model.Pod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ArrayList(java.util.ArrayList) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 27 with PodData

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

the class PodMergerTest method shouldAssignSecurityContextSharedByPods.

@Test
public void shouldAssignSecurityContextSharedByPods() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withSecurityContext(new PodSecurityContextBuilder().withRunAsUser(42L).build()).build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withSecurityContext(new PodSecurityContextBuilder().withRunAsUser(42L).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();
    PodSecurityContext sc = podTemplate.getSpec().getSecurityContext();
    assertEquals(sc.getRunAsUser(), (Long) 42L);
}
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) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.testng.annotations.Test)

Example 28 with PodData

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

the class PodMergerTest method shouldFailIfSecurityContextDiffersInPods.

@Test(expectedExceptions = ValidationException.class)
public void shouldFailIfSecurityContextDiffersInPods() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withSecurityContext(new PodSecurityContextBuilder().withRunAsUser(42L).build()).build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withSecurityContext(new PodSecurityContextBuilder().withRunAsUser(43L).build()).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) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) 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 29 with PodData

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

the class PodMergerTest method shouldAssignServiceAccountNameSharedByPods.

@Test
public void shouldAssignServiceAccountNameSharedByPods() throws Exception {
    // given
    PodSpec podSpec1 = new PodSpecBuilder().withServiceAccountName("sa").build();
    podSpec1.setAdditionalProperty("add1", 1L);
    PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
    PodSpec podSpec2 = new PodSpecBuilder().withServiceAccountName("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().getServiceAccountName();
    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)

Example 30 with PodData

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

the class PodMergerTest method shouldMergeMetasOfPodsData.

@Test
public void shouldMergeMetasOfPodsData() 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);
    ObjectMeta podMeta2 = new ObjectMetaBuilder().withName("ignored-2").withAnnotations(ImmutableMap.of("ann2", "v2")).withLabels(ImmutableMap.of("label2", "v2")).build();
    podMeta2.setAdditionalProperty("add2", 2L);
    PodData podData2 = new PodData(new PodSpecBuilder().build(), podMeta2);
    // when
    Deployment merged = podMerger.merge(Arrays.asList(podData1, podData2));
    // then
    PodTemplateSpec podTemplate = merged.getSpec().getTemplate();
    ObjectMeta podMeta = podTemplate.getMetadata();
    verifyContainsAllFrom(podMeta, podData1.getMetadata());
    verifyContainsAllFrom(podMeta, podData2.getMetadata());
}
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)

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