Search in sources :

Example 1 with V1ResourceRequirementsBuilder

use of io.kubernetes.client.openapi.models.V1ResourceRequirementsBuilder in project cdap by caskdata.

the class KubeTwillPreparer method createResourceRequirements.

/**
 * Creates a {@link V1ResourceRequirements} based on the given {@link ResourceSpecification}.
 */
private V1ResourceRequirements createResourceRequirements(ResourceSpecification resourceSpec) {
    Map<String, String> cConf = masterEnvContext.getConfigurations();
    float cpuMultiplier = Float.parseFloat(cConf.getOrDefault(CPU_MULTIPLIER, DEFAULT_MULTIPLIER));
    float memoryMultiplier = Float.parseFloat(cConf.getOrDefault(MEMORY_MULTIPLIER, DEFAULT_MULTIPLIER));
    int cpuToRequest = (int) (resourceSpec.getVirtualCores() * 1000 * cpuMultiplier);
    int memoryToRequest = (int) (resourceSpec.getMemorySize() * memoryMultiplier);
    return new V1ResourceRequirementsBuilder().addToRequests("cpu", new Quantity(String.format("%dm", cpuToRequest))).addToRequests("memory", new Quantity(String.format("%dMi", memoryToRequest))).build();
}
Also used : V1ResourceRequirementsBuilder(io.kubernetes.client.openapi.models.V1ResourceRequirementsBuilder) Quantity(io.kubernetes.client.custom.Quantity)

Aggregations

Quantity (io.kubernetes.client.custom.Quantity)1 V1ResourceRequirementsBuilder (io.kubernetes.client.openapi.models.V1ResourceRequirementsBuilder)1