use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplier method addSidecar.
/**
* Adds k8s and Che specific configuration of a sidecar into the environment. For example:
* <li>k8s container configuration {@link Container}
* <li>k8s service configuration {@link Service}
* <li>Che machine config {@link InternalMachineConfig}
* <li>Fill in machine name attribute in related commands
*
* @throws InfrastructureException when any error occurs
*/
private void addSidecar(PodData pod, CheContainer container, ChePlugin chePlugin, KubernetesEnvironment k8sEnv, Collection<CommandImpl> sidecarRelatedCommands, Component pluginRelatedComponent, RuntimeIdentity runtimeIdentity) throws InfrastructureException {
K8sContainerResolver k8sContainerResolver = toK8sContainerResolver(container, chePlugin.getEndpoints());
List<ChePluginEndpoint> containerEndpoints = k8sContainerResolver.getEndpoints();
Container k8sContainer = k8sContainerResolver.resolve();
envVars.apply(k8sContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sContainer, container.getVolumes(), k8sEnv);
String machineName = k8sContainer.getName();
Names.putMachineName(pod.getMetadata(), k8sContainer.getName(), machineName);
pod.getSpec().getContainers().add(k8sContainer);
MachineResolver machineResolver = new MachineResolverBuilder().setCheContainer(container).setContainer(k8sContainer).setContainerEndpoints(containerEndpoints).setDefaultSidecarMemoryLimitAttribute(defaultSidecarMemoryLimitBytes).setDefaultSidecarMemoryRequestAttribute(defaultSidecarMemoryRequestBytes).setDefaultSidecarCpuLimitAttribute(defaultSidecarCpuLimitCores).setDefaultSidecarCpuRequestAttribute(defaultSidecarCpuRequestCores).setProjectsRootPathEnvVar(projectsRootEnvVariableProvider.get(runtimeIdentity)).setComponent(pluginRelatedComponent).build();
InternalMachineConfig machineConfig = machineResolver.resolve();
machineConfig.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, TOOL_CONTAINER_SOURCE);
machineConfig.getAttributes().put(PLUGIN_MACHINE_ATTRIBUTE, chePlugin.getId());
k8sEnv.getMachines().put(machineName, machineConfig);
sidecarRelatedCommands.forEach(c -> c.getAttributes().put(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE, machineName));
container.getCommands().stream().map(c -> asCommand(machineName, c)).forEach(c -> k8sEnv.getCommands().add(c));
SidecarServicesProvisioner sidecarServicesProvisioner = new SidecarServicesProvisioner(containerEndpoints, pod.getMetadata().getName());
sidecarServicesProvisioner.provision(k8sEnv);
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class K8sContainerResolverTest method setUp.
@BeforeMethod
public void setUp() {
cheContainer = new CheContainer();
endpoints = new ArrayList<>();
resolver = new K8sContainerResolver("Always", cheContainer, endpoints);
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class MachineResolverTest method setUp.
@BeforeMethod
public void setUp() {
endpoints = new ArrayList<>();
cheContainer = new CheContainer();
container = new Container();
component = new ComponentImpl("chePlugin", PLUGIN_ID);
resolver = new MachineResolver(new Pair<>(PROJECTS_ENV_VAR, PROJECTS_MOUNT_PATH), container, cheContainer, DEFAULT_MEM_LIMIT, DEFAULT_MEM_REQUEST, DEFAULT_CPU_LIMIT, DEFAULT_CPU_REQUEST, endpoints, component);
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method applyPluginInitContainerWithOneVolume.
@Test
public void applyPluginInitContainerWithOneVolume() throws InfrastructureException {
lenient().when(podSpec.getInitContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
CheContainer initContainer = createContainer();
chePlugin.setInitContainers(singletonList(initContainer));
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
verifyPodAndInitContainersNumber(1);
Container toolingInitContainer = getOnlyOneInitContainerFromPod(internalEnvironment);
verifyContainer(toolingInitContainer);
verify(chePluginsVolumeApplier).applyVolumes(any(PodData.class), eq(toolingInitContainer), eq(initContainer.getVolumes()), eq(internalEnvironment));
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method applyPluginContainerWithOneVolume.
@Test
public void applyPluginContainerWithOneVolume() throws InfrastructureException {
lenient().when(podSpec.getContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
CheContainer cheContainer = chePlugin.getContainers().get(0);
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
verifyPodAndContainersNumber(1);
Container container = getOneAndOnlyNonUserContainer(internalEnvironment);
verifyContainer(container);
verify(chePluginsVolumeApplier).applyVolumes(any(PodData.class), eq(container), eq(cheContainer.getVolumes()), eq(internalEnvironment));
}
Aggregations