Search in sources :

Example 1 with Volume

use of org.eclipse.che.api.workspace.server.wsplugins.model.Volume in project che-server by eclipse-che.

the class ChePluginsVolumeApplier method provisionPVCPodVolume.

private io.fabric8.kubernetes.api.model.Volume provisionPVCPodVolume(Volume volume, KubernetesEnvironment.PodData pod, KubernetesEnvironment k8sEnv) {
    String pvcName = volume.getName();
    if (!k8sEnv.getPersistentVolumeClaims().containsKey(pvcName)) {
        final PersistentVolumeClaim pvc = newPVC(pvcName, pvcAccessMode, pvcQuantity, pvcStorageClassName);
        k8sEnv.getPersistentVolumeClaims().put(pvcName, pvc);
    }
    PodSpec podSpec = pod.getSpec();
    Optional<io.fabric8.kubernetes.api.model.Volume> volumeOpt = podSpec.getVolumes().stream().filter(vm -> vm.getPersistentVolumeClaim() != null && pvcName.equals(vm.getPersistentVolumeClaim().getClaimName())).findAny();
    io.fabric8.kubernetes.api.model.Volume podVolume;
    if (volumeOpt.isPresent()) {
        podVolume = volumeOpt.get();
    } else {
        podVolume = newVolume(pvcName, pvcName);
        podSpec.getVolumes().add(podVolume);
    }
    return podVolume;
}
Also used : KubernetesObjectUtil.newPVC(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC) Container(io.fabric8.kubernetes.api.model.Container) Collection(java.util.Collection) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Singleton(javax.inject.Singleton) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) Inject(javax.inject.Inject) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Optional(java.util.Optional) Named(javax.inject.Named) KubernetesObjectUtil.newVolumeMount(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Example 2 with Volume

use of org.eclipse.che.api.workspace.server.wsplugins.model.Volume in project che-server by eclipse-che.

the class ChePluginsVolumeApplier method applyVolumes.

public void applyVolumes(KubernetesEnvironment.PodData pod, Container container, Collection<Volume> volumes, KubernetesEnvironment k8sEnv) {
    for (Volume volume : volumes) {
        String podVolumeName = provisionPodVolume(volume, pod, k8sEnv);
        container.getVolumeMounts().add(newVolumeMount(podVolumeName, volume.getMountPath(), ""));
    }
}
Also used : KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume)

Example 3 with Volume

use of org.eclipse.che.api.workspace.server.wsplugins.model.Volume in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method createContainer.

private CheContainer createContainer(String name, Command... commands) {
    CheContainer cheContainer = new CheContainer();
    cheContainer.setImage(TEST_IMAGE);
    cheContainer.setName(name);
    cheContainer.setEnv(singletonList(new EnvVar().name(ENV_VAR).value(ENV_VAR_VALUE)));
    cheContainer.setVolumes(singletonList(new Volume().name(VOLUME_NAME).mountPath(VOLUME_MOUNT_PATH)));
    cheContainer.setCommands(Arrays.asList(commands));
    return cheContainer;
}
Also used : CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) EnvVar(org.eclipse.che.api.workspace.server.wsplugins.model.EnvVar)

Example 4 with Volume

use of org.eclipse.che.api.workspace.server.wsplugins.model.Volume 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 5 with Volume

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

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)

Aggregations

Volume (org.eclipse.che.api.workspace.server.wsplugins.model.Volume)10 Container (io.fabric8.kubernetes.api.model.Container)4 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)4 KubernetesObjectUtil.newVolume (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume)4 Test (org.testng.annotations.Test)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)2 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Singleton (javax.inject.Singleton)2 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)2 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)2 EnvVar (org.eclipse.che.api.workspace.server.wsplugins.model.EnvVar)2 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)2 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)2 KubernetesObjectUtil.newPVC (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC)2 KubernetesObjectUtil.newVolumeMount (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount)2