use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class EnvVarsTest method shouldProvisionEnvIfContainersDoeNotHaveEnvAtAll.
@Test
public void shouldProvisionEnvIfContainersDoeNotHaveEnvAtAll() throws Exception {
// given
PodData pod = new PodData(new PodBuilder().withNewMetadata().withName("pod").endMetadata().withNewSpec().withInitContainers(new ContainerBuilder().withName("initContainer").build()).withContainers(new ContainerBuilder().withName("container").build()).endSpec().build());
// when
envVars.apply(pod, singletonList(new EnvImpl("TEST_ENV", "anyValue")));
// then
List<EnvVar> initCEnv = pod.getSpec().getInitContainers().get(0).getEnv();
assertEquals(initCEnv.size(), 1);
assertEquals(initCEnv.get(0), new EnvVar("TEST_ENV", "anyValue", null));
List<EnvVar> containerEnv = pod.getSpec().getContainers().get(0).getEnv();
assertEquals(containerEnv.size(), 1);
assertEquals(containerEnv.get(0), new EnvVar("TEST_ENV", "anyValue", null));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class KubernetesInternalRuntimeTest method testMultipleMachinesRequiringSamePodInjectionResultInOnePodInjected.
@Test
public void testMultipleMachinesRequiringSamePodInjectionResultInOnePodInjected() throws Exception {
// given
Map<String, Pod> injectedPods = ImmutableMap.of("injected", mockPod(singletonList(mockContainer("injectedContainer"))));
Map<String, Pod> injectedPods2 = ImmutableMap.of("injected", mockPod(singletonList(mockContainer("injectedContainer"))));
doReturn(ImmutableMap.of(M1_NAME, injectedPods, M2_NAME, injectedPods2)).when(k8sEnv).getInjectablePodsCopy();
doReturn(concat(podsMap.entrySet().stream(), injectedPods.entrySet().stream()).collect(toMap(Map.Entry::getKey, e -> new PodData(e.getValue())))).when(k8sEnv).getPodsData();
doReturn(ImmutableMap.of(M1_NAME, mock(InternalMachineConfig.class), M2_NAME, mock(InternalMachineConfig.class), WORKSPACE_POD_NAME + "/injectedContainer", mock(InternalMachineConfig.class))).when(k8sEnv).getMachines();
// when
internalRuntime.start(emptyMap());
// then
ArgumentCaptor<Deployment> podCaptor = ArgumentCaptor.forClass(Deployment.class);
verify(deployments).deploy(podCaptor.capture());
List<Deployment> depls = podCaptor.getAllValues();
assertEquals(depls.size(), 1);
Deployment deployedPod = depls.get(0);
List<String> containerNames = deployedPod.getSpec().getTemplate().getSpec().getContainers().stream().map(Container::getName).collect(toList());
assertEquals(containerNames.size(), 3);
assertEquals(new HashSet<>(containerNames), new HashSet<>(asList(CONTAINER_NAME_1, CONTAINER_NAME_2, "injectedContainer")));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplier method apply.
@Override
public void apply(RuntimeIdentity runtimeIdentity, InternalEnvironment internalEnvironment, Collection<ChePlugin> chePlugins) throws InfrastructureException {
if (chePlugins.isEmpty()) {
return;
}
KubernetesEnvironment k8sEnv = (KubernetesEnvironment) internalEnvironment;
Map<String, PodData> pods = k8sEnv.getPodsData();
switch(pods.size()) {
case 0:
addToolingPod(k8sEnv);
pods = k8sEnv.getPodsData();
break;
case 1:
break;
default:
throw new InfrastructureException("Che plugins tooling configuration can be applied to a workspace with one pod only");
}
PodData pod = pods.values().iterator().next();
CommandsResolver commandsResolver = new CommandsResolver(k8sEnv);
for (ChePlugin chePlugin : chePlugins) {
Map<String, ComponentImpl> devfilePlugins = k8sEnv.getDevfile().getComponents().stream().filter(c -> c.getType().equals("cheEditor") || c.getType().equals("chePlugin")).collect(Collectors.toMap(ComponentImpl::getId, Function.identity()));
if (!devfilePlugins.containsKey(chePlugin.getId())) {
throw new InfrastructureException(String.format("The downloaded plugin '%s' configuration does not have the " + "corresponding component in devfile. Devfile contains the following cheEditor/chePlugins: %s", chePlugin.getId(), devfilePlugins.keySet()));
}
ComponentImpl pluginRelatedComponent = devfilePlugins.get(chePlugin.getId());
for (CheContainer container : chePlugin.getInitContainers()) {
Container k8sInitContainer = toK8sContainer(container);
envVars.apply(k8sInitContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sInitContainer, container.getVolumes(), k8sEnv);
pod.getSpec().getInitContainers().add(k8sInitContainer);
}
Collection<CommandImpl> pluginRelatedCommands = commandsResolver.resolve(chePlugin);
for (CheContainer container : chePlugin.getContainers()) {
addSidecar(pod, container, chePlugin, k8sEnv, pluginRelatedCommands, pluginRelatedComponent, runtimeIdentity);
}
}
chePlugins.forEach(chePlugin -> populateWorkspaceEnvVars(chePlugin, k8sEnv));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
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);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
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);
}
Aggregations