Search in sources :

Example 21 with V1Volume

use of io.kubernetes.client.openapi.models.V1Volume in project twister2 by DSC-SPIDAL.

the class RequestObjectBuilder method constructPodTemplate.

/**
 * construct pod template
 */
public static V1PodTemplateSpec constructPodTemplate(ComputeResource computeResource) {
    V1PodTemplateSpec template = new V1PodTemplateSpec();
    V1ObjectMeta templateMetaData = new V1ObjectMeta();
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // worker pod
    labels.put("t2-wp", jobID);
    templateMetaData.setLabels(labels);
    template.setMetadata(templateMetaData);
    V1PodSpec podSpec = new V1PodSpec();
    podSpec.setTerminationGracePeriodSeconds(0L);
    ArrayList<V1Volume> volumes = new ArrayList<>();
    V1Volume memoryVolume = new V1Volume();
    memoryVolume.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME);
    V1EmptyDirVolumeSource volumeSource1 = new V1EmptyDirVolumeSource();
    volumeSource1.setMedium("Memory");
    memoryVolume.setEmptyDir(volumeSource1);
    volumes.add(memoryVolume);
    // create it if the requested disk space is positive
    if (computeResource.getDiskGigaBytes() > 0) {
        double volumeSize = computeResource.getDiskGigaBytes() * computeResource.getWorkersPerPod();
        V1Volume volatileVolume = createVolatileVolume(volumeSize);
        volumes.add(volatileVolume);
    }
    if (SchedulerContext.persistentVolumeRequested(config)) {
        String claimName = jobID;
        V1Volume persistentVolume = createPersistentVolume(claimName);
        volumes.add(persistentVolume);
    }
    // if openmpi is used, we initialize a Secret volume on each pod
    if (SchedulerContext.usingOpenMPI(config)) {
        String secretName = KubernetesContext.secretName(config);
        V1Volume secretVolume = createSecretVolume(secretName);
        volumes.add(secretVolume);
    }
    podSpec.setVolumes(volumes);
    int containersPerPod = computeResource.getWorkersPerPod();
    // if openmpi is used, we initialize only one container for each pod
    if (SchedulerContext.usingOpenMPI(config)) {
        containersPerPod = 1;
    }
    ArrayList<V1Container> containers = new ArrayList<V1Container>();
    for (int i = 0; i < containersPerPod; i++) {
        containers.add(constructContainer(computeResource, i));
    }
    podSpec.setContainers(containers);
    if (computeResource.getIndex() == 0) {
        constructAffinity(podSpec);
    }
    template.setSpec(podSpec);
    return template;
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) ArrayList(java.util.ArrayList) V1EmptyDirVolumeSource(io.kubernetes.client.openapi.models.V1EmptyDirVolumeSource) V1Container(io.kubernetes.client.openapi.models.V1Container) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec)

Aggregations

V1Volume (io.kubernetes.client.openapi.models.V1Volume)21 Test (org.junit.Test)10 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)9 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 Config (org.apache.heron.spi.common.Config)8 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)7 LinkedList (java.util.LinkedList)7 Matchers.anyString (org.mockito.Matchers.anyString)6 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 V1Container (io.kubernetes.client.openapi.models.V1Container)4 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)4 VolumeConfigKeys (org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys)4 V1EmptyDirVolumeSource (io.kubernetes.client.openapi.models.V1EmptyDirVolumeSource)3 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)3 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)3 Quantity (io.kubernetes.client.custom.Quantity)2