use of io.kubernetes.client.custom.Quantity in project heron by twitter.
the class V1ControllerTest method testCreatePersistentVolumeClaims.
@Test
public void testCreatePersistentVolumeClaims() {
final String topologyName = "topology-name";
final String volumeNameOne = "volume-name-one";
final String volumeNameTwo = "volume-name-two";
final String volumeNameStatic = "volume-name-static";
final String claimNameOne = "OnDemand";
final String claimNameTwo = "claim-name-two";
final String claimNameStatic = "OnDEmaND";
final String storageClassName = "storage-class-name";
final String sizeLimit = "555Gi";
final String accessModesList = "ReadWriteOnce,ReadOnlyMany,ReadWriteMany";
final String accessModes = "ReadOnlyMany";
final String volumeMode = "VolumeMode";
final String path = "/path/to/mount/";
final String subPath = "/sub/path/to/mount/";
final Map<String, Map<VolumeConfigKeys, String>> mapPVCOpts = ImmutableMap.of(volumeNameOne, new HashMap<VolumeConfigKeys, String>() {
{
put(VolumeConfigKeys.claimName, claimNameOne);
put(VolumeConfigKeys.storageClassName, storageClassName);
put(VolumeConfigKeys.sizeLimit, sizeLimit);
put(VolumeConfigKeys.accessModes, accessModesList);
put(VolumeConfigKeys.volumeMode, volumeMode);
put(VolumeConfigKeys.path, path);
}
}, volumeNameTwo, new HashMap<VolumeConfigKeys, String>() {
{
put(VolumeConfigKeys.claimName, claimNameTwo);
put(VolumeConfigKeys.storageClassName, storageClassName);
put(VolumeConfigKeys.sizeLimit, sizeLimit);
put(VolumeConfigKeys.accessModes, accessModes);
put(VolumeConfigKeys.volumeMode, volumeMode);
put(VolumeConfigKeys.path, path);
put(VolumeConfigKeys.subPath, subPath);
}
}, volumeNameStatic, new HashMap<VolumeConfigKeys, String>() {
{
put(VolumeConfigKeys.claimName, claimNameStatic);
put(VolumeConfigKeys.sizeLimit, sizeLimit);
put(VolumeConfigKeys.accessModes, accessModes);
put(VolumeConfigKeys.volumeMode, volumeMode);
put(VolumeConfigKeys.path, path);
put(VolumeConfigKeys.subPath, subPath);
}
});
final V1PersistentVolumeClaim claimOne = new V1PersistentVolumeClaimBuilder().withNewMetadata().withName(volumeNameOne).withLabels(V1Controller.getPersistentVolumeClaimLabels(topologyName)).endMetadata().withNewSpec().withStorageClassName(storageClassName).withAccessModes(Arrays.asList(accessModesList.split(","))).withVolumeMode(volumeMode).withNewResources().addToRequests("storage", new Quantity(sizeLimit)).endResources().endSpec().build();
final V1PersistentVolumeClaim claimStatic = new V1PersistentVolumeClaimBuilder().withNewMetadata().withName(volumeNameStatic).withLabels(V1Controller.getPersistentVolumeClaimLabels(topologyName)).endMetadata().withNewSpec().withStorageClassName("").withAccessModes(Collections.singletonList(accessModes)).withVolumeMode(volumeMode).withNewResources().addToRequests("storage", new Quantity(sizeLimit)).endResources().endSpec().build();
final List<V1PersistentVolumeClaim> expectedClaims = new LinkedList<>(Arrays.asList(claimOne, claimStatic));
final List<V1PersistentVolumeClaim> actualClaims = v1ControllerWithPodTemplate.createPersistentVolumeClaims(mapPVCOpts);
Assert.assertTrue(expectedClaims.containsAll(actualClaims));
}
use of io.kubernetes.client.custom.Quantity in project heron by twitter.
the class V1ControllerTest method testConfigureContainerResourcesCLI.
@Test
public void testConfigureContainerResourcesCLI() {
final boolean isExecutor = true;
final String customLimitMEMStr = "120Gi";
final String customLimitCPUStr = "5";
final String customRequestMEMStr = "100Mi";
final String customRequestCPUStr = "4";
final Resource resources = new Resource(6, ByteAmount.fromMegabytes(34000), ByteAmount.fromGigabytes(400));
final Quantity customLimitMEM = Quantity.fromString(customLimitMEMStr);
final Quantity customLimitCPU = Quantity.fromString(customLimitCPUStr);
final Quantity customRequestMEM = Quantity.fromString(customRequestMEMStr);
final Quantity customRequestCPU = Quantity.fromString(customRequestCPUStr);
final Config config = Config.newBuilder().put(String.format(KubernetesContext.KUBERNETES_RESOURCE_LIMITS_PREFIX + KubernetesConstants.CPU, KubernetesConstants.EXECUTOR_NAME), customLimitCPUStr).put(String.format(KubernetesContext.KUBERNETES_RESOURCE_LIMITS_PREFIX + KubernetesConstants.MEMORY, KubernetesConstants.EXECUTOR_NAME), customLimitMEMStr).put(String.format(KubernetesContext.KUBERNETES_RESOURCE_REQUESTS_PREFIX + KubernetesConstants.CPU, KubernetesConstants.EXECUTOR_NAME), customRequestCPUStr).put(String.format(KubernetesContext.KUBERNETES_RESOURCE_REQUESTS_PREFIX + KubernetesConstants.MEMORY, KubernetesConstants.EXECUTOR_NAME), customRequestMEMStr).put(KubernetesContext.KUBERNETES_RESOURCE_REQUEST_MODE, "EQUAL_TO_LIMIT").build();
final V1Container expected = new V1ContainerBuilder().withNewResources().addToLimits(KubernetesConstants.CPU, customLimitCPU).addToLimits(KubernetesConstants.MEMORY, customLimitMEM).addToRequests(KubernetesConstants.CPU, customRequestCPU).addToRequests(KubernetesConstants.MEMORY, customRequestMEM).endResources().build();
final V1Container actual = new V1Container();
v1ControllerWithPodTemplate.configureContainerResources(actual, config, resources, isExecutor);
Assert.assertEquals("Container Resources are set from CLI.", expected, actual);
}
use of io.kubernetes.client.custom.Quantity in project java by kubernetes-client.
the class KubectlTop method topNodes.
private List<Pair<ApiType, MetricsType>> topNodes(CoreV1Api api, ApiClient apiClient, String metricName) throws KubectlException, ApiException, IOException {
V1NodeList nodes = api.listNode(null, null, null, null, null, null, null, null, null, null);
NodeMetricsList metrics = new Metrics(apiClient).getNodeMetrics();
List<V1Node> items = nodes.getItems();
Collections.sort(items, new Comparator<V1Node>() {
@Override
public int compare(V1Node arg0, V1Node arg1) {
Quantity m0 = findNodeMetric(arg0.getMetadata().getName(), metrics).getUsage().get(metricName);
Quantity m1 = findNodeMetric(arg1.getMetadata().getName(), metrics).getUsage().get(metricName);
double p0 = findNodePercentage(arg0, m0, metricName);
double p1 = findNodePercentage(arg1, m1, metricName);
// sort high to low
return Double.compare(p0, p1) * -1;
}
});
List<Pair<ApiType, MetricsType>> result = new ArrayList<>();
for (V1Node node : items) {
result.add(new ImmutablePair<>((ApiType) node, (MetricsType) findNodeMetric(node, metrics)));
}
return result;
}
Aggregations