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);
}
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);
}
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
}
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");
}
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());
}
Aggregations