use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project devspaces-images by redhat-developer.
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.ChePlugin in project devspaces-images by redhat-developer.
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.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.
the class SidecarToolingProvisioner method provision.
@Traced
@Beta
public void provision(RuntimeIdentity identity, StartSynchronizer startSynchronizer, E environment, Map<String, String> startOptions) throws InfrastructureException {
Collection<PluginFQN> pluginFQNs = pluginFQNParser.parsePlugins(environment.getAttributes());
if (pluginFQNs.isEmpty()) {
return;
}
LOG.debug("Started sidecar tooling provisioning workspace '{}'", identity.getWorkspaceId());
String recipeType = environment.getType();
ChePluginsApplier pluginsApplier = workspaceNextAppliers.get(recipeType);
if (pluginsApplier == null) {
throw new InfrastructureException("Sidecar tooling configuration is not supported with environment type " + recipeType);
}
boolean isEphemeral = EphemeralWorkspaceUtility.isEphemeral(environment.getAttributes());
boolean mergePlugins = shouldMergePlugins(environment.getAttributes());
List<ChePlugin> chePlugins = pluginBrokerManager.getTooling(identity, startSynchronizer, pluginFQNs, isEphemeral, mergePlugins, startOptions);
pluginsApplier.apply(identity, environment, chePlugins);
artifactsBrokerApplier.apply(environment, identity, pluginFQNs, mergePlugins);
LOG.debug("Finished sidecar tooling provisioning workspace '{}'", identity.getWorkspaceId());
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin 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.ChePlugin in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method shouldFillInWarningIfChePluginDoesNotHaveAnyContainersButThereAreRelatedCommands.
@Test
public void shouldFillInWarningIfChePluginDoesNotHaveAnyContainersButThereAreRelatedCommands() throws Exception {
// given
ChePlugin chePlugin = createChePlugin("somePublisher/custom-name/0.0.3");
String pluginRef = chePlugin.getId();
CommandImpl pluginCommand = new CommandImpl("test-command", "echo Hello World!", "custom");
pluginCommand.getAttributes().put("plugin", pluginRef);
internalEnvironment.getCommands().add(pluginCommand);
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
// then
List<Warning> envWarnings = internalEnvironment.getWarnings();
assertEquals(envWarnings.size(), 1);
Warning warning = envWarnings.get(0);
assertEquals(warning.getCode(), Warnings.COMMAND_IS_CONFIGURED_IN_PLUGIN_WITHOUT_CONTAINERS_WARNING_CODE);
assertEquals(warning.getMessage(), "There are configured commands for plugin 'somePublisher/custom-name/0.0.3' that doesn't have any containers");
}
Aggregations