Java Code Examples for io.kubernetes.client.openapi.models.V1Volume#setEmptyDir()

The following examples show how to use io.kubernetes.client.openapi.models.V1Volume#setEmptyDir() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestObjectBuilder.java    From twister2 with Apache License 2.0 5 votes vote down vote up
public static V1Volume createVolatileVolume(double volumeSize) {
  V1Volume volatileVolume = new V1Volume();
  volatileVolume.setName(KubernetesConstants.POD_VOLATILE_VOLUME_NAME);
  V1EmptyDirVolumeSource volumeSource2 = new V1EmptyDirVolumeSource();
  volumeSource2.setSizeLimit(new Quantity(String.format("%.2fGi", volumeSize)));
  volatileVolume.setEmptyDir(volumeSource2);
  return volatileVolume;
}
 
Example 2
Source File: JobMasterRequestObject.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * construct pod template
 */
public static V1PodTemplateSpec constructPodTemplate() {

  V1PodTemplateSpec template = new V1PodTemplateSpec();
  V1ObjectMeta templateMetaData = new V1ObjectMeta();
  HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
  labels.put("t2-mp", jobID); // job master pod

  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);

  // a volatile disk based volume
  // create it if the requested disk space is positive
  if (JobMasterContext.volatileVolumeRequested(config)) {
    double vSize = JobMasterContext.volatileVolumeSize(config);
    V1Volume volatileVolume = RequestObjectBuilder.createVolatileVolume(vSize);
    volumes.add(volatileVolume);
  }

  if (JobMasterContext.persistentVolumeRequested(config)) {
    String claimName = jobID;
    V1Volume persistentVolume = RequestObjectBuilder.createPersistentVolume(claimName);
    volumes.add(persistentVolume);
  }

  podSpec.setVolumes(volumes);

  ArrayList<V1Container> containers = new ArrayList<V1Container>();
  containers.add(constructContainer());
  podSpec.setContainers(containers);

  template.setSpec(podSpec);
  return template;
}
 
Example 3
Source File: RequestObjectBuilder.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * construct pod template
 */
public static V1PodTemplateSpec constructPodTemplate(ComputeResource computeResource) {

  V1PodTemplateSpec template = new V1PodTemplateSpec();
  V1ObjectMeta templateMetaData = new V1ObjectMeta();
  HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
  labels.put("t2-wp", jobID); // worker pod

  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);

  // a volatile disk based volume
  // 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.useOpenMPI(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.useOpenMPI(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;
}