Search in sources :

Example 1 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class PVCProvisioner method convertCheVolumes.

/**
 * Converts {@link Volume} specified in {@link MachineConfig#getVolumes()} to {@link
 * PersistentVolumeClaim}s and provision them to {@link KubernetesEnvironment}. The machines
 * corresponding pods and containers are updated in accordance.
 *
 * @param k8sEnv environment to provision
 * @param workspaceId identifier of workspace to which the specified environment belongs to
 */
public void convertCheVolumes(KubernetesEnvironment k8sEnv, String workspaceId) {
    Map<String, PersistentVolumeClaim> volumeName2PVC = groupByVolumeName(k8sEnv.getPersistentVolumeClaims().values());
    for (PodData pod : k8sEnv.getPodsData().values()) {
        final PodSpec podSpec = pod.getSpec();
        List<Container> containers = new ArrayList<>();
        containers.addAll(podSpec.getContainers());
        containers.addAll(podSpec.getInitContainers());
        for (Container container : containers) {
            final String machineName = Names.machineName(pod, container);
            InternalMachineConfig machineConfig = k8sEnv.getMachines().get(machineName);
            if (machineConfig == null) {
                continue;
            }
            Map<String, Volume> volumes = machineConfig.getVolumes();
            addMachineVolumes(workspaceId, k8sEnv, volumeName2PVC, pod, container, volumes);
        }
    }
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) Volume(org.eclipse.che.api.core.model.workspace.config.Volume) ArrayList(java.util.ArrayList) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Example 2 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class LogsVolumeMachineProvisionerTest method testProvisionLogsVolumeToAllMachineInEnvironment.

@Test
public void testProvisionLogsVolumeToAllMachineInEnvironment() throws Exception {
    logsVolumeProvisioner.provision(openShiftEnvironment, identity);
    InternalMachineConfig m1 = openShiftEnvironment.getMachines().get(MACHINE_NAME_1);
    InternalMachineConfig m2 = openShiftEnvironment.getMachines().get(MACHINE_NAME_2);
    assertTrue(m1.getVolumes().containsKey(LOGS_VOLUME_NAME));
    assertEquals(m1.getVolumes().get(LOGS_VOLUME_NAME).getPath(), WORKSPACE_LOGS_ROOT_PATH);
    assertTrue(m2.getVolumes().containsKey(LOGS_VOLUME_NAME));
    assertEquals(m2.getVolumes().get(LOGS_VOLUME_NAME).getPath(), WORKSPACE_LOGS_ROOT_PATH);
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Test(org.testng.annotations.Test)

Example 3 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class BrokerEnvironmentFactoryTest method shouldNotIncludePluginsVolumeInMetadataBroker.

@Test
public void shouldNotIncludePluginsVolumeInMetadataBroker() throws Exception {
    // given
    Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id"));
    ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class);
    // when
    factory.createForMetadataBroker(pluginFQNs, runtimeId, false);
    // then
    verify(factory).doCreate(captor.capture());
    BrokersConfigs brokersConfigs = captor.getValue();
    InternalMachineConfig machine = brokersConfigs.machines.values().iterator().next();
    assertFalse(machine.getVolumes().containsKey(PLUGINS_VOLUME_NAME));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) Test(org.testng.annotations.Test)

Example 4 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method addsMachineWithVolumeFromChePlugin.

@Test
public void addsMachineWithVolumeFromChePlugin() throws Exception {
    // given
    ChePlugin chePluginWithNoVolume = createChePlugin();
    chePluginWithNoVolume.getContainers().get(0).setVolumes(emptyList());
    // when
    applier.apply(runtimeIdentity, internalEnvironment, asList(createChePlugin(), chePluginWithNoVolume));
    // then
    Collection<InternalMachineConfig> machineConfigs = getNonUserMachines(internalEnvironment);
    assertEquals(machineConfigs.size(), 2);
    verifyNumberOfMachinesWithSpecificNumberOfVolumes(machineConfigs, 2, 0);
}
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 5 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method shouldUseContainerNameForMachinesName.

@Test
public void shouldUseContainerNameForMachinesName() throws Exception {
    // given
    internalEnvironment.getMachines().clear();
    ChePlugin chePlugin = createChePlugin("publisher/plugin1/0.2.1", createContainer("container1"));
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    Map<String, InternalMachineConfig> machines = internalEnvironment.getMachines();
    assertEquals(machines.size(), 1);
    validateContainerNameName(machines.keySet().iterator().next(), "container1");
}
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

InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)88 Test (org.testng.annotations.Test)64 Container (io.fabric8.kubernetes.api.model.Container)36 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)18 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)16 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)14 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)12 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)12 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)12 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)10 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 Pod (io.fabric8.kubernetes.api.model.Pod)10 Secret (io.fabric8.kubernetes.api.model.Secret)10 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)10 HashMap (java.util.HashMap)8 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)8 Traced (org.eclipse.che.commons.annotation.Traced)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)6