parent
7cf011ba38
commit
31dde19914
|
|
@ -128,7 +128,7 @@ public class Containers {
|
|||
&& resources.getLimits() != null
|
||||
&& (quantity = resources.getLimits().get("cpu")) != null
|
||||
&& quantity.getAmount() != null) {
|
||||
return KubernetesSize.toCores(quantity.getAmount());
|
||||
return KubernetesSize.toCores(quantity);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ public class Containers {
|
|||
&& resources.getRequests() != null
|
||||
&& (quantity = resources.getRequests().get("cpu")) != null
|
||||
&& quantity.getAmount() != null) {
|
||||
return KubernetesSize.toCores(quantity.getAmount());
|
||||
return KubernetesSize.toCores(quantity);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
*/
|
||||
package org.eclipse.che.workspace.infrastructure.kubernetes.util;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.Quantity;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -154,4 +155,16 @@ public class KubernetesSize {
|
|||
}
|
||||
throw new IllegalArgumentException("Invalid Kubernetes CPU size format provided: " + cpuString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts CPU resource from {@link Quantity} object to cores.
|
||||
*
|
||||
* <p>see {@link KubernetesSize#toCores(String)} for conversion rules
|
||||
*
|
||||
* @param quantity to convert
|
||||
* @return value in cores
|
||||
*/
|
||||
public static float toCores(Quantity quantity) {
|
||||
return toCores(quantity.getAmount() + quantity.getFormat());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,4 +288,13 @@ public class ContainersTest {
|
|||
{"155m", "155", "m", null},
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnContainerCPULimitAndRequestConvertedToFullCores() {
|
||||
when(resource.getLimits()).thenReturn(ImmutableMap.of("cpu", new Quantity("1000", "m")));
|
||||
when(resource.getRequests()).thenReturn(ImmutableMap.of("cpu", new Quantity("30", "m")));
|
||||
|
||||
assertEquals(Containers.getCpuLimit(container), 1);
|
||||
assertEquals(Containers.getCpuRequest(container), 0.03, 0.000000001);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue