io.kubernetes.client.openapi.models.V1ResourceRequirements Java Examples

The following examples show how to use io.kubernetes.client.openapi.models.V1ResourceRequirements. 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: DefaultTaskToPodConverter.java    From titus-control-plane with Apache License 2.0 8 votes vote down vote up
private V1ResourceRequirements buildV1ResourceRequirements(ContainerResources containerResources) {
    Map<String, Quantity> requests = new HashMap<>();
    Map<String, Quantity> limits = new HashMap<>();

    requests.put("cpu", new Quantity(String.valueOf(containerResources.getCpu())));
    limits.put("cpu", new Quantity(String.valueOf(containerResources.getCpu())));

    requests.put("nvidia.com/gpu", new Quantity(String.valueOf(containerResources.getGpu())));
    limits.put("nvidia.com/gpu", new Quantity(String.valueOf(containerResources.getGpu())));

    requests.put("memory", new Quantity(String.valueOf(containerResources.getMemoryMB())));
    limits.put("memory", new Quantity(String.valueOf(containerResources.getMemoryMB())));

    requests.put("ephemeral-storage", new Quantity(String.valueOf(containerResources.getDiskMB())));
    limits.put("ephemeral-storage", new Quantity(String.valueOf(containerResources.getDiskMB())));

    requests.put("titus/network", new Quantity(String.valueOf(containerResources.getNetworkMbps())));
    limits.put("titus/network", new Quantity(String.valueOf(containerResources.getNetworkMbps())));

    return new V1ResourceRequirements().requests(requests).limits(limits);
}
 
Example #2
Source File: V1EphemeralContainer.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Get resources
 * @return resources
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")

public V1ResourceRequirements getResources() {
  return resources;
}
 
Example #3
Source File: V1Container.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Get resources
 * @return resources
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")

public V1ResourceRequirements getResources() {
  return resources;
}
 
Example #4
Source File: V1PersistentVolumeClaimSpec.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Get resources
 * @return resources
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")

public V1ResourceRequirements getResources() {
  return resources;
}
 
Example #5
Source File: RequestObjectBuilder.java    From twister2 with Apache License 2.0 5 votes vote down vote up
public static V1PersistentVolumeClaim createPersistentVolumeClaimObject(int numberOfWorkers) {

    String pvcName = jobID;

    // set labels for V1PersistentVolumeClaim
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);

    String storageClass = KubernetesContext.persistentStorageClass(config);
    String accessMode = KubernetesContext.storageAccessMode(config);

    V1ResourceRequirements resources = new V1ResourceRequirements();
    double storageSize = SchedulerContext.persistentVolumePerWorker(config) * numberOfWorkers;
    if (!JobMasterContext.jobMasterRunsInClient(config)) {
      storageSize += JobMasterContext.persistentVolumeSize(config);
    }
    resources.putRequestsItem("storage", new Quantity(storageSize + "Gi"));

    V1PersistentVolumeClaim pvc = new V1PersistentVolumeClaimBuilder()
        .withApiVersion("v1")
        .withNewMetadata().withName(pvcName).withLabels(labels).endMetadata()
        .withNewSpec()
        .withStorageClassName(storageClass)
        .withAccessModes(Arrays.asList(accessMode))
        .withResources(resources)
        .endSpec()
        .build();

    return pvc;
  }
 
Example #6
Source File: V1EphemeralContainer.java    From java with Apache License 2.0 4 votes vote down vote up
public void setResources(V1ResourceRequirements resources) {
  this.resources = resources;
}
 
Example #7
Source File: V1Container.java    From java with Apache License 2.0 4 votes vote down vote up
public void setResources(V1ResourceRequirements resources) {
  this.resources = resources;
}
 
Example #8
Source File: V1PersistentVolumeClaimSpec.java    From java with Apache License 2.0 4 votes vote down vote up
public void setResources(V1ResourceRequirements resources) {
  this.resources = resources;
}
 
Example #9
Source File: JobMasterRequestObject.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * construct a container
 */
public static V1Container constructContainer() {
  // construct container and add it to podSpec
  V1Container container = new V1Container();
  container.setName("twister2-job-master-0");

  String containerImage = KubernetesContext.twister2DockerImageForK8s(config);
  if (containerImage == null) {
    throw new RuntimeException("Container Image name is null. Config parameter: "
        + "twister2.resource.kubernetes.docker.image can not be null");
  }
  container.setImage(containerImage);
  container.setImagePullPolicy(KubernetesContext.imagePullPolicy(config));
  container.setCommand(Arrays.asList("/bin/bash"));
  container.setArgs(Arrays.asList("-c", "./init.sh"));

  int jmRam = JobMasterContext.jobMasterRAM(config) + 128;
  V1ResourceRequirements resReq = new V1ResourceRequirements();
  resReq.putRequestsItem("cpu", new Quantity(JobMasterContext.jobMasterCpu(config) + ""));
  resReq.putRequestsItem("memory", new Quantity(jmRam + "Mi"));
  container.setResources(resReq);

  ArrayList<V1VolumeMount> volumeMounts = new ArrayList<>();
  V1VolumeMount memoryVolumeMount = new V1VolumeMount();
  memoryVolumeMount.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME);
  memoryVolumeMount.setMountPath(KubernetesConstants.POD_MEMORY_VOLUME);
  volumeMounts.add(memoryVolumeMount);

  if (JobMasterContext.volatileVolumeRequested(config)) {
    V1VolumeMount volatileVolumeMount = new V1VolumeMount();
    volatileVolumeMount.setName(KubernetesConstants.POD_VOLATILE_VOLUME_NAME);
    volatileVolumeMount.setMountPath(KubernetesConstants.POD_VOLATILE_VOLUME);
    volumeMounts.add(volatileVolumeMount);
  }

  if (JobMasterContext.persistentVolumeRequested(config)) {
    V1VolumeMount persVolumeMount = new V1VolumeMount();
    persVolumeMount.setName(KubernetesConstants.PERSISTENT_VOLUME_NAME);
    persVolumeMount.setMountPath(KubernetesConstants.PERSISTENT_VOLUME_MOUNT);
    volumeMounts.add(persVolumeMount);
  }

  container.setVolumeMounts(volumeMounts);

  V1ContainerPort port = new V1ContainerPort();
  port.name("job-master-port");
  port.containerPort(JobMasterContext.jobMasterPort(config));
  port.setProtocol("TCP");
  container.setPorts(Arrays.asList(port));

  container.setEnv(constructEnvironmentVariables(JobMasterContext.jobMasterRAM(config)));

  return container;
}
 
Example #10
Source File: AppsV1Controller.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
private V1Container getContainer(List<String> executorCommand, Resource resource,
    int numberOfInstances) {
  final Config configuration = getConfiguration();
  final V1Container container = new V1Container().name("executor");

  // set up the container images
  container.setImage(KubernetesContext.getExecutorDockerImage(configuration));

  // set up the container command
  container.setCommand(executorCommand);

  if (KubernetesContext.hasImagePullPolicy(configuration)) {
    container.setImagePullPolicy(KubernetesContext.getKubernetesImagePullPolicy(configuration));
  }

  // setup the environment variables for the container
  final V1EnvVar envVarHost = new V1EnvVar();
  envVarHost.name(KubernetesConstants.ENV_HOST)
      .valueFrom(new V1EnvVarSource()
          .fieldRef(new V1ObjectFieldSelector()
              .fieldPath(KubernetesConstants.POD_IP)));

  final V1EnvVar envVarPodName = new V1EnvVar();
  envVarPodName.name(KubernetesConstants.ENV_POD_NAME)
      .valueFrom(new V1EnvVarSource()
          .fieldRef(new V1ObjectFieldSelector()
              .fieldPath(KubernetesConstants.POD_NAME)));
  container.setEnv(Arrays.asList(envVarHost, envVarPodName));


  // set container resources
  final V1ResourceRequirements resourceRequirements = new V1ResourceRequirements();
  final Map<String, Quantity> requests = new HashMap<>();
  requests.put(KubernetesConstants.MEMORY,
      Quantity.fromString(KubernetesUtils.Megabytes(resource.getRam())));
  requests.put(KubernetesConstants.CPU,
       Quantity.fromString(Double.toString(roundDecimal(resource.getCpu(), 3))));
  resourceRequirements.setRequests(requests);
  container.setResources(resourceRequirements);

  // set container ports
  final boolean debuggingEnabled =
      TopologyUtils.getTopologyRemoteDebuggingEnabled(
          Runtime.topology(getRuntimeConfiguration()));
  container.setPorts(getContainerPorts(debuggingEnabled, numberOfInstances));

  // setup volume mounts
  mountVolumeIfPresent(container);

  return container;
}