Search in sources :

Example 11 with CheContainer

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));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 12 with CheContainer

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());
}
Also used : CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) ArrayList(java.util.ArrayList) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) Test(org.testng.annotations.Test)

Example 13 with CheContainer

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));
}
Also used : PLUGIN_MACHINE_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.PLUGIN_MACHINE_ATTRIBUTE) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Singleton(javax.inject.Singleton) CONTAINER_SOURCE_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.CONTAINER_SOURCE_ATTRIBUTE) Function(java.util.function.Function) WORKING_DIRECTORY_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE) Inject(javax.inject.Inject) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Map(java.util.Map) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Service(io.fabric8.kubernetes.api.model.Service) Named(javax.inject.Named) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Command(org.eclipse.che.api.workspace.server.wsplugins.model.Command) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ChePluginsApplier(org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier) TOOL_CONTAINER_SOURCE(org.eclipse.che.api.workspace.shared.Constants.TOOL_CONTAINER_SOURCE) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Pod(io.fabric8.kubernetes.api.model.Pod) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Beta(com.google.common.annotations.Beta) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Warnings(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) ProjectsRootEnvVariableProvider(org.eclipse.che.api.workspace.server.spi.provision.env.ProjectsRootEnvVariableProvider) KubernetesSize(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSize) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 14 with CheContainer

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.");
            }
        }
    }
}
Also used : CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)

Example 15 with CheContainer

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));
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Aggregations

CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)38 Container (io.fabric8.kubernetes.api.model.Container)28 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)26 Test (org.testng.annotations.Test)22 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)10 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)8 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)6 ChePluginEndpoint (org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)6 Beta (com.google.common.annotations.Beta)4 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)4 Sets (com.google.common.collect.Sets)4 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 Service (io.fabric8.kubernetes.api.model.Service)4 String.format (java.lang.String.format)4 Collection (java.util.Collection)4 Collections.emptyList (java.util.Collections.emptyList)4 List (java.util.List)4 Map (java.util.Map)4