use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method addsMachinesWithVolumesToAllToolingContainer.
@Test
public void addsMachinesWithVolumesToAllToolingContainer() throws Exception {
// given
ChePlugin chePluginWithNonDefaultVolume = createChePlugin();
String anotherVolumeName = VOLUME_NAME + "1";
String anotherVolumeMountPath = VOLUME_MOUNT_PATH + "/something";
List<Volume> volumes = singletonList(new Volume().name(anotherVolumeName).mountPath(anotherVolumeMountPath));
CheContainer toolingContainer = chePluginWithNonDefaultVolume.getContainers().get(0);
toolingContainer.setVolumes(volumes);
ChePlugin chePlugin = createChePlugin();
// when
applier.apply(runtimeIdentity, internalEnvironment, asList(chePlugin, chePluginWithNonDefaultVolume));
// then
Collection<InternalMachineConfig> machineConfigs = getNonUserMachines(internalEnvironment);
assertEquals(machineConfigs.size(), 2);
verify(chePluginsVolumeApplier).applyVolumes(any(PodData.class), any(Container.class), eq(chePlugin.getContainers().get(0).getVolumes()), eq(internalEnvironment));
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class K8sContainerResolverBuilderTest method shouldPassOnlyParticularContainerEndpoints.
@Test
public void shouldPassOnlyParticularContainerEndpoints() {
// given
K8sContainerResolverBuilder builder = new K8sContainerResolverBuilder();
builder.setContainer(new CheContainer().ports(asList(new CheContainerPort().exposedPort(9014), new CheContainerPort().exposedPort(4040))));
builder.setPluginEndpoints(asList(new ChePluginEndpoint().targetPort(9014), new ChePluginEndpoint().targetPort(9013), new ChePluginEndpoint().targetPort(8080), new ChePluginEndpoint().targetPort(4040)));
K8sContainerResolver resolver = builder.build();
ArrayList<ChePluginEndpoint> expected = new ArrayList<>();
expected.add(new ChePluginEndpoint().targetPort(9014));
expected.add(new ChePluginEndpoint().targetPort(4040));
// when
List<ChePluginEndpoint> actualEndpoints = resolver.getEndpoints();
// then
assertEqualsNoOrder(actualEndpoints.toArray(), expected.toArray());
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer 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.api.workspace.server.wsplugins.model.CheContainer in project che-server by eclipse-che.
the class KubernetesPluginsToolingValidator method validatePluginNames.
public void validatePluginNames(List<? extends ChePlugin> plugins) throws ValidationException {
for (ChePlugin plugin : plugins) {
if (plugin.getName() != null) {
final String formattedPluginName = plugin.getName().toLowerCase();
checkValid(formattedPluginName, "Plugin name `%s` contains unacceptable symbols and cannot be used as part of container naming.");
}
for (CheContainer container : plugin.getContainers()) {
if (container.getName() != null) {
final String formattedContainerName = container.getName().toLowerCase();
checkValid(formattedContainerName, "Container name `%s` contains unacceptable symbols and cannot be used as part of container naming.");
}
}
}
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer in project devspaces-images by redhat-developer.
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