Search in sources :

Example 6 with Volume

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

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)

Aggregations

Volume (org.eclipse.che.api.core.model.workspace.config.Volume)6 Container (io.fabric8.kubernetes.api.model.Container)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 ArrayList (java.util.ArrayList)4 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)4 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)4 KubernetesObjectUtil.newVolume (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 MachineConfig (org.eclipse.che.api.core.model.workspace.config.MachineConfig)2 CHE_VOLUME_NAME_LABEL (org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_VOLUME_NAME_LABEL)2 CHE_WORKSPACE_ID_LABEL (org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL)2