use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class PodMergerTest method shouldGenerateContainerNamesIfCollisionHappened.
@Test
public void shouldGenerateContainerNamesIfCollisionHappened() throws Exception {
// given
PodSpec podSpec1 = new PodSpecBuilder().withContainers(new ContainerBuilder().withName("c").build()).build();
PodData podData1 = new PodData(podSpec1, new ObjectMetaBuilder().build());
PodSpec podSpec2 = new PodSpecBuilder().withContainers(new ContainerBuilder().withName("c").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> containers = podTemplate.getSpec().getContainers();
assertEquals(containers.size(), 2);
Container container1 = containers.get(0);
assertEquals(container1.getName(), "c");
Container container2 = containers.get(1);
assertNotEquals(container2.getName(), "c");
assertTrue(container2.getName().startsWith("c"));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class ContainerResourceProvisionerTest method setup.
@BeforeMethod
public void setup() {
resourceProvisioner = new ContainerResourceProvisioner(1024, 512, "500m", "100m");
container = new Container();
container.setName(CONTAINER_NAME);
when(k8sEnv.getMachines()).thenReturn(of(MACHINE_NAME, internalMachineConfig));
when(internalMachineConfig.getAttributes()).thenReturn(of(MEMORY_LIMIT_ATTRIBUTE, RAM_LIMIT_VALUE, MEMORY_REQUEST_ATTRIBUTE, RAM_REQUEST_VALUE, CPU_LIMIT_ATTRIBUTE, CPU_LIMIT_VALUE, CPU_REQUEST_ATTRIBUTE, CPU_REQUEST_VALUE));
final ObjectMeta podMetadata = mock(ObjectMeta.class);
when(podMetadata.getName()).thenReturn(POD_NAME);
final PodSpec podSpec = mock(PodSpec.class);
when(podSpec.getContainers()).thenReturn(Collections.singletonList(container));
when(k8sEnv.getPodsData()).thenReturn(of(POD_NAME, new PodData(podSpec, podMetadata)));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class RestartPolicyRewriterTest method rewritesRestartPolicyWhenItsDifferentWithDefaultOne.
@Test
public void rewritesRestartPolicyWhenItsDifferentWithDefaultOne() throws Exception {
Pod pod = newPod(TEST_POD_NAME, ALWAYS_RESTART_POLICY);
PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
when(k8sEnv.getPodsData()).thenReturn(singletonMap(TEST_POD_NAME, podData));
restartPolicyRewriter.provision(k8sEnv, runtimeIdentity);
assertEquals(pod.getSpec().getRestartPolicy(), DEFAULT_RESTART_POLICY);
verifyWarnings(new WarningImpl(RESTART_POLICY_SET_TO_NEVER_WARNING_CODE, format("Restart policy '%s' for pod '%s' is rewritten with %s", ALWAYS_RESTART_POLICY, TEST_POD_NAME, DEFAULT_RESTART_POLICY)));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class KubernetesServerExposerTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
container = new ContainerBuilder().withName("main").build();
Pod pod = new PodBuilder().withNewMetadata().withName("pod").endMetadata().withNewSpec().withContainers(container).endSpec().build();
kubernetesEnvironment = KubernetesEnvironment.builder().setPods(ImmutableMap.of("pod", pod)).build();
PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
this.serverExposer = new KubernetesServerExposer<>(externalServerExposer, secureServerExposer, MACHINE_NAME, podData, container, kubernetesEnvironment);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class UniqueNamesProvisionerTest method rewritePodConfigMapEnvFrom.
@Test
public void rewritePodConfigMapEnvFrom() throws Exception {
when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
ConfigMap configMap = newConfigMap();
doReturn(ImmutableMap.of(CONFIGMAP_NAME, configMap)).when(k8sEnv).getConfigMaps();
EnvFromSource envFrom = new EnvFromSourceBuilder().withNewConfigMapRef().withName(CONFIGMAP_NAME).endConfigMapRef().build();
Container container = new ContainerBuilder().withEnvFrom(envFrom).build();
Pod pod = newPod();
pod.getSpec().setContainers(ImmutableList.of(container));
PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
doReturn(ImmutableMap.of(POD_NAME, podData)).when(k8sEnv).getPodsData();
uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);
String newConfigMapName = configMap.getMetadata().getName();
EnvFromSource newEnvFromSource = container.getEnvFrom().iterator().next();
assertEquals(newEnvFromSource.getConfigMapRef().getName(), newConfigMapName);
}
Aggregations