Search in sources :

Example 36 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project devspaces-images by redhat-developer.

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");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Warning(org.eclipse.che.api.core.model.workspace.Warning) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 37 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project devspaces-images by redhat-developer.

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));
}
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)

Example 38 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplierTest method shouldProvisionApplyEnvironmentVariableToContainersAndInitContainersOfPlugin.

@Test
public void shouldProvisionApplyEnvironmentVariableToContainersAndInitContainersOfPlugin() throws Exception {
    // given
    CheContainer container = new CheContainer();
    container.setName("container");
    CheContainer initContainer = new CheContainer();
    initContainer.setName("initContainer");
    ChePlugin chePlugin = createChePlugin("publisher/id/1.0.0", singletonList(container), singletonList(initContainer));
    ComponentImpl component = internalEnvironment.getDevfile().getComponents().get(0);
    component.getEnv().add(new EnvImpl("TEST", "VALUE"));
    ArgumentCaptor<Container> containerArgumentCaptor = ArgumentCaptor.forClass(Container.class);
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    verify(envVars, times(2)).apply(containerArgumentCaptor.capture(), eq(component.getEnv()));
    List<Container> containers = containerArgumentCaptor.getAllValues();
    // containers names are suffixed to provide uniqueness and converted to be k8s API compatible
    assertTrue(containers.get(0).getName().startsWith("initcontainer"));
    assertTrue(containers.get(1).getName().startsWith("container"));
}
Also used : 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) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 39 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplierTest method addsMachineWithServersForContainer.

@Test
public void addsMachineWithServersForContainer() throws Exception {
    // given
    ChePlugin chePlugin = createChePlugin();
    addPortToSingleContainerPlugin(chePlugin, 80, "test-port", emptyMap(), true);
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    InternalMachineConfig machineConfig = getOneAndOnlyNonUserMachine(internalEnvironment);
    assertEquals(machineConfig.getServers(), expectedSingleServer(80, "test-port", emptyMap(), true));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 40 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplierTest method addsMachineWithServersThatSetProtocolAndPath.

@Test
public void addsMachineWithServersThatSetProtocolAndPath() throws Exception {
    // given
    ChePlugin chePlugin = createChePlugin();
    addPortToSingleContainerPlugin(chePlugin, 443, "test-port", ImmutableMap.of("path", "/path/1", "protocol", "https", "attr1", "value1"), true);
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    InternalMachineConfig machineConfig = getOneAndOnlyNonUserMachine(internalEnvironment);
    assertEquals(machineConfig.getServers(), expectedSingleServer(443, "test-port", singletonMap("attr1", "value1"), true, "https", "/path/1"));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Aggregations

ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)68 Test (org.testng.annotations.Test)58 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)32 Container (io.fabric8.kubernetes.api.model.Container)30 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)20 ChePluginEndpoint (org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)12 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)10 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)10 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)10 CheContainerPort (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort)8 Beta (com.google.common.annotations.Beta)6 Service (io.fabric8.kubernetes.api.model.Service)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 ChePluginsApplier (org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier)6 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 String.format (java.lang.String.format)4