Search in sources :

Example 76 with V1ObjectMeta

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

the class RequestObjectBuilder method createStatefulSetForWorkers.

/**
 * create StatefulSet object for a job
 */
public static V1StatefulSet createStatefulSetForWorkers(ComputeResource computeResource) {
    if (config == null) {
        LOG.severe("RequestObjectBuilder.init method has not been called.");
        return null;
    }
    String statefulSetName = KubernetesUtils.createWorkersStatefulSetName(jobID, computeResource.getIndex());
    V1StatefulSet statefulSet = new V1StatefulSet();
    // set labels for the worker stateful set
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // worker statefulset
    labels.put("t2-wss", jobID);
    // construct metadata and set for jobID setting
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(statefulSetName);
    meta.setLabels(labels);
    statefulSet.setMetadata(meta);
    // construct JobSpec and set
    V1StatefulSetSpec setSpec = new V1StatefulSetSpec();
    setSpec.serviceName(KubernetesUtils.createServiceName(jobID));
    // pods will be started in parallel
    // by default they are started sequentially
    setSpec.setPodManagementPolicy("Parallel");
    int numberOfPods = computeResource.getInstances();
    setSpec.setReplicas(numberOfPods);
    // add selector for the job
    V1LabelSelector selector = new V1LabelSelector();
    selector.putMatchLabelsItem("t2-wp", jobID);
    setSpec.setSelector(selector);
    // construct the pod template
    V1PodTemplateSpec template = constructPodTemplate(computeResource);
    setSpec.setTemplate(template);
    statefulSet.setSpec(setSpec);
    return statefulSet;
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector)

Example 77 with V1ObjectMeta

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

the class RequestObjectBuilder method createHeadlessServiceObject.

public static V1Service createHeadlessServiceObject(String serviceName) {
    V1Service service = new V1Service();
    service.setKind("Service");
    service.setApiVersion("v1");
    // set labels for the worker services
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // construct and set metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(serviceName);
    meta.setLabels(labels);
    service.setMetadata(meta);
    // construct and set service spec
    V1ServiceSpec serviceSpec = new V1ServiceSpec();
    // ClusterIP needs to be None for headless service
    serviceSpec.setClusterIP("None");
    // set selector
    HashMap<String, String> selectors = new HashMap<String, String>();
    selectors.put("t2-wp", jobID);
    serviceSpec.setSelector(selectors);
    service.setSpec(serviceSpec);
    return service;
}
Also used : HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) V1Service(io.kubernetes.client.openapi.models.V1Service)

Example 78 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta 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

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)78 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 HashMap (java.util.HashMap)14 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)10 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1Container (io.kubernetes.client.openapi.models.V1Container)7 ApiClient (io.kubernetes.client.openapi.ApiClient)6 JSON (io.kubernetes.client.openapi.JSON)6 V1Job (io.kubernetes.client.openapi.models.V1Job)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1Service (io.kubernetes.client.openapi.models.V1Service)5 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5