Search in sources :

Example 6 with VolumeImpl

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

the class PVCProvisionerTest method testMatchingUserDefinedPVCWithCheVolume.

@Test
public void testMatchingUserDefinedPVCWithCheVolume() throws Exception {
    // given
    k8sEnv.getPersistentVolumeClaims().put("userDataPVC", newPVC("userDataPVC"));
    pod.getSpec().getVolumes().add(new VolumeBuilder().withName("userData").withPersistentVolumeClaim(new PersistentVolumeClaimVolumeSourceBuilder().withClaimName("userDataPVC").build()).build());
    pod.getSpec().getContainers().get(0).getVolumeMounts().add(new VolumeMountBuilder().withName("userData").withSubPath("/home/user/data").build());
    k8sEnv.getMachines().values().forEach(m -> m.getVolumes().clear());
    k8sEnv.getMachines().get(MACHINE_2_NAME).getVolumes().put("userDataPVC", new VolumeImpl().withPath("/"));
    // when
    provisioner.convertCheVolumes(k8sEnv, WORKSPACE_ID);
    // then
    assertEquals(k8sEnv.getPersistentVolumeClaims().size(), 1);
    PersistentVolumeClaim pvcForUserData = findPvc("userDataPVC", k8sEnv.getPersistentVolumeClaims());
    assertNotNull(pvcForUserData);
    assertEquals("userDataPVC", pvcForUserData.getMetadata().getName());
    PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec();
    io.fabric8.kubernetes.api.model.Volume userPodVolume = podSpec.getVolumes().get(0);
    assertEquals(userPodVolume.getPersistentVolumeClaim().getClaimName(), pvcForUserData.getMetadata().getName());
    assertEquals(podSpec.getVolumes().get(0).getPersistentVolumeClaim().getClaimName(), pvcForUserData.getMetadata().getName());
    // check container bound to user-defined PVC
    Container container1 = podSpec.getContainers().get(0);
    assertEquals(container1.getVolumeMounts().size(), 1);
    VolumeMount volumeMount = container1.getVolumeMounts().get(0);
    assertEquals(volumeMount.getName(), userPodVolume.getName());
    // check container that is bound to Che Volume via Machine configuration
    Container container2 = podSpec.getContainers().get(1);
    VolumeMount cheVolumeMount2 = container2.getVolumeMounts().get(0);
    assertEquals(cheVolumeMount2.getName(), userPodVolume.getName());
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) TestObjects.newContainer(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.TestObjects.newContainer) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) PersistentVolumeClaimVolumeSourceBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSourceBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Test(org.testng.annotations.Test)

Example 7 with VolumeImpl

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

the class WorkspaceActivityDaoTest method createWorkspaceConfig.

private static WorkspaceConfigImpl createWorkspaceConfig(String name) {
    // Project Sources configuration
    final SourceStorageImpl source1 = new SourceStorageImpl();
    source1.setType("type1");
    source1.setLocation("location1");
    // Project Configuration
    final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
    pCfg1.setPath("/path1");
    pCfg1.setType("type1");
    pCfg1.setName("project1");
    pCfg1.setDescription("description1");
    pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
    pCfg1.setSource(source1);
    final List<ProjectConfigImpl> projects = new ArrayList<>(singletonList(pCfg1));
    // Commands
    final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
    final List<CommandImpl> commands = new ArrayList<>(singletonList(cmd1));
    // OldMachine configs
    final MachineConfigImpl exMachine1 = new MachineConfigImpl();
    final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "path1", singletonMap("key", "value"));
    exMachine1.setServers(ImmutableMap.of("ref1", serverConf1));
    exMachine1.setAttributes(singletonMap("att1", "val"));
    exMachine1.setEnv(ImmutableMap.of("CHE_ENV1", "value", "CHE_ENV2", "value"));
    exMachine1.setVolumes(ImmutableMap.of("vol1", new VolumeImpl().withPath("/path/1")));
    // Environments
    final RecipeImpl recipe1 = new RecipeImpl();
    recipe1.setLocation("https://eclipse.che/Dockerfile");
    recipe1.setType("dockerfile");
    recipe1.setContentType("text/x-dockerfile");
    recipe1.setContent("content");
    final EnvironmentImpl env1 = new EnvironmentImpl();
    env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1)));
    env1.setRecipe(recipe1);
    final RecipeImpl recipe2 = new RecipeImpl();
    recipe2.setLocation("https://eclipse.che/Dockerfile");
    recipe2.setType("dockerfile");
    recipe2.setContentType("text/x-dockerfile");
    recipe2.setContent("content");
    final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1);
    // Workspace configuration
    final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
    wCfg.setDefaultEnv("env1");
    wCfg.setName(name);
    wCfg.setDescription("description");
    wCfg.setCommands(commands);
    wCfg.setProjects(projects);
    wCfg.setEnvironments(new HashMap<>(environments));
    return wCfg;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ArrayList(java.util.ArrayList) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 8 with VolumeImpl

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

the class DockerimageComponentToWorkspaceApplier method createMachineConfig.

private MachineConfigImpl createMachineConfig(ComponentImpl dockerimageComponent, String componentAlias) {
    MachineConfigImpl machineConfig = new MachineConfigImpl();
    machineConfig.getServers().putAll(convertEndpointsIntoServers(dockerimageComponent.getEndpoints(), !SINGLE_HOST_STRATEGY.equals(devfileEndpointsExposure)));
    dockerimageComponent.getVolumes().forEach(v -> machineConfig.getVolumes().put(v.getName(), new VolumeImpl().withPath(v.getContainerPath())));
    if (Boolean.TRUE.equals(dockerimageComponent.getMountSources())) {
        machineConfig.getVolumes().put(PROJECTS_VOLUME_NAME, new VolumeImpl().withPath(projectFolderPath));
    }
    if (!isNullOrEmpty(componentAlias)) {
        machineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, componentAlias);
    }
    return machineConfig;
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl)

Example 9 with VolumeImpl

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

the class KubernetesComponentToWorkspaceApplier method provisionVolumes.

private void provisionVolumes(ComponentImpl component, Container container, MachineConfigImpl config) throws DevfileException {
    for (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl componentVolume : component.getVolumes()) {
        Optional<VolumeMount> sameNameMount = container.getVolumeMounts().stream().filter(vm -> vm.getName().equals(componentVolume.getName())).findFirst();
        if (sameNameMount.isPresent() && sameNameMount.get().getMountPath().equals(componentVolume.getContainerPath())) {
            continue;
        } else if (sameNameMount.isPresent()) {
            throw new DevfileException(format("Conflicting volume with same name ('%s') but different path ('%s') found for component '%s' and its container '%s'.", componentVolume.getName(), componentVolume.getContainerPath(), getIdentifiableComponentName(component), container.getName()));
        }
        if (container.getVolumeMounts().stream().anyMatch(vm -> vm.getMountPath().equals(componentVolume.getContainerPath()))) {
            throw new DevfileException(format("Conflicting volume with same path ('%s') but different name ('%s') found for component '%s' and its container '%s'.", componentVolume.getContainerPath(), componentVolume.getName(), getIdentifiableComponentName(component), container.getName()));
        }
        config.getVolumes().put(componentVolume.getName(), new VolumeImpl().withPath(componentVolume.getContainerPath()));
    }
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) WorkspaceConfig(org.eclipse.che.api.core.model.workspace.WorkspaceConfig) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ComponentToWorkspaceApplier.convertEndpointsIntoServers(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier.convertEndpointsIntoServers) Map(java.util.Map) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) KubernetesObjectUtil.newPVC(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Set(java.util.Set) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) String.format(java.lang.String.format) List(java.util.List) Stream(java.util.stream.Stream) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Optional(java.util.Optional) Names.machineName(org.eclipse.che.workspace.infrastructure.kubernetes.Names.machineName) KubernetesObjectUtil.newVolumeMount(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount) Entrypoint(org.eclipse.che.api.core.model.workspace.devfile.Entrypoint) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) DevfileRecipeFormatException(org.eclipse.che.api.workspace.server.devfile.DevfileRecipeFormatException) ArrayList(java.util.ArrayList) KUBERNETES_BASED_COMPONENTS_KEY_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings.KUBERNETES_BASED_COMPONENTS_KEY_NAME) Inject(javax.inject.Inject) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Named(javax.inject.Named) Components.getIdentifiableComponentName(org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName) Volume(io.fabric8.kubernetes.api.model.Volume) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) Collectors.toList(java.util.stream.Collectors.toList) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) Constants(org.eclipse.che.api.workspace.server.devfile.Constants) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) KubernetesRecipeParser(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) KubernetesObjectUtil.newVolumeMount(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)

Example 10 with VolumeImpl

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

the class BrokerEnvironmentFactory method createForArtifactsBroker.

/**
 * Creates {@link KubernetesEnvironment} with everything needed to deploy artifacts plugin broker.
 *
 * @param pluginFQNs fully qualified names of plugins that needs to be resolved by the broker
 * @param runtimeID ID of the runtime the broker would be started
 * @param mergePlugins whether the broker should be configured to merge plugins where possible
 * @return kubernetes environment (or its extension) with the Plugin broker objects
 */
public E createForArtifactsBroker(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, boolean mergePlugins) throws InfrastructureException {
    BrokersConfigs brokersConfigs = getBrokersConfigs(pluginFQNs, runtimeID, artifactsBrokerImage, mergePlugins);
    brokersConfigs.machines.values().forEach(m -> m.getVolumes().put(PLUGINS_VOLUME_NAME, new VolumeImpl().withPath("/plugins")));
    return doCreate(brokersConfigs);
}
Also used : VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl)

Aggregations

VolumeImpl (org.eclipse.che.api.workspace.server.model.impl.VolumeImpl)12 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)8 ArrayList (java.util.ArrayList)6 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)6 Container (io.fabric8.kubernetes.api.model.Container)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)4 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)4 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)4 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)4 RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)4 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)4 SourceStorageImpl (org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 PersistentVolumeClaimVolumeSourceBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSourceBuilder)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)2 Volume (io.fabric8.kubernetes.api.model.Volume)2