use of io.kubernetes.client.models.V1beta2StatefulSetSpec in project twister2 by DSC-SPIDAL.
the class KubernetesUtils method createStatefulSetObjectForJob.
/**
* TBD: calculate containers per pod or issue error
* when the numberOfContainers can not be divisible by the number of containersPerPod
* @param jobName
* @param resourceRequest
* @return
*/
public static V1beta2StatefulSet createStatefulSetObjectForJob(String jobName, RequestedResources resourceRequest, long jobFileSize, Config config) {
V1beta2StatefulSet statefulSet = new V1beta2StatefulSet();
statefulSet.setApiVersion("apps/v1beta2");
statefulSet.setKind("StatefulSet");
// construct metadata and set for jobName setting
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(jobName);
statefulSet.setMetadata(meta);
// construct JobSpec and set
V1beta2StatefulSetSpec setSpec = new V1beta2StatefulSetSpec();
setSpec.serviceName(createServiceName(jobName));
// pods will be started in parallel
// by default they are started sequentially
setSpec.setPodManagementPolicy("Parallel");
// number of containers has to be divisible by the containersPerPod
// all pods will have equal number of containers
// all pods will be identical
int containersPerPod = KubernetesContext.containersPerPod(config);
if (resourceRequest.getNoOfContainers() % containersPerPod != 0) {
LOG.log(Level.SEVERE, "Number of containers has to be divisible by containersPerPod.\n" + "Number of containers: " + resourceRequest.getNoOfContainers() + "\n" + "containersPerPod: " + containersPerPod + "\n" + "Aborting submission.");
return null;
}
int numberOfPods = resourceRequest.getNoOfContainers() / containersPerPod;
setSpec.setReplicas(numberOfPods);
// add selector for the job
V1LabelSelector selector = new V1LabelSelector();
String serviceLabel = createServiceLabel(jobName);
selector.putMatchLabelsItem("app", serviceLabel);
setSpec.setSelector(selector);
// construct the pod template
V1PodTemplateSpec template = constructPodTemplate(resourceRequest.getContainer(), serviceLabel, jobFileSize, config);
setSpec.setTemplate(template);
statefulSet.setSpec(setSpec);
return statefulSet;
}
Aggregations