use of io.fabric8.kubernetes.api.model.Quantity in project syndesis-qe by syndesisio.
the class OperatorValidationSteps method checkDbPvCapacity.
@Then("check that {string} persistent volume capacity is greater or equals to {string}")
public void checkDbPvCapacity(String pvc, String expected) {
try {
OpenShiftWaitUtils.waitFor(() -> OpenShiftUtils.getInstance().getPersistentVolumeClaim(pvc) != null);
OpenShiftWaitUtils.waitFor(() -> OpenShiftUtils.getInstance().getPersistentVolumeClaim(pvc).getStatus().getPhase().equals("Bound"));
} catch (TimeoutException | InterruptedException e) {
fail("Unable to get " + pvc + " pvc: ", e);
}
final Quantity capacity = OpenShiftUtils.getInstance().getPersistentVolumeClaim(pvc).getStatus().getCapacity().get("storage");
assertThat(capacity.getFormat()).isEqualTo("Gi");
assertThat(Integer.parseInt(capacity.getAmount())).isGreaterThanOrEqualTo(Integer.parseInt(expected.replaceAll("[a-zA-Z]", "")));
}
use of io.fabric8.kubernetes.api.model.Quantity in project syndesis-qe by syndesisio.
the class OperatorValidationSteps method createPv.
@Given("create test persistent volumes with {string} storage class name")
public void createPv(String className) {
// Create 3 PVs, two with higher capacity that will be used by meta and prometheus, because the binding of PV is FCFS,
// so they theoretically can steal the test-pv from db
// These volumes won't work, but they will be available to bind
Map<String, Quantity> capacity = new HashMap<>();
capacity.put("storage", new Quantity("3Gi"));
if (!"".equals(className) && OpenShiftUtils.getInstance().storage().storageClasses().withName(className).get() == null) {
log.info("Creating storage class " + className);
OpenShiftUtils.getInstance().storage().storageClasses().createOrReplaceWithNew().withNewMetadata().withName(className).endMetadata().withProvisioner("kubernetes.io/cinder").done();
}
PersistentVolumeFluent.SpecNested<DoneablePersistentVolume> pv = OpenShiftUtils.getInstance().persistentVolumes().createOrReplaceWithNew().withNewMetadata().withName(TEST_PV_NAME).withLabels(TestUtils.map("operator", "test")).endMetadata().withNewSpec().withAccessModes("ReadOnlyMany", "ReadWriteOnce", "ReadWriteMany").withCapacity(capacity).withNewNfs().withNewServer("testServer").withNewPath("/testPath").endNfs();
// The default storage class for OCP3 is empty, for OCP4 is "standard", so if the className is empty, we should use the default one
if ("".equals(className)) {
if (!OpenShiftUtils.isOpenshift3()) {
if (OpenShiftUtils.isOSD()) {
pv.withStorageClassName("gp2");
} else {
pv.withStorageClassName("standard");
}
}
} else {
pv.withStorageClassName(className);
}
pv.endSpec().done();
capacity.put("storage", new Quantity("5Gi"));
for (int i = 1; i < 3; i++) {
pv = OpenShiftUtils.getInstance().persistentVolumes().createOrReplaceWithNew().withNewMetadata().withName(TEST_PV_NAME + "-" + i).endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withCapacity(capacity).withNewNfs().withNewServer("testServer").withNewPath("/testPath").endNfs();
if (!OpenShiftUtils.isOpenshift3()) {
// This should always be the default value despite the actual value of className - that is used only in "test-pv" intentionally
if (OpenShiftUtils.isOSD()) {
pv.withStorageClassName("gp2");
} else {
pv.withStorageClassName("standard");
}
}
pv.endSpec().done();
}
}
use of io.fabric8.kubernetes.api.model.Quantity in project syndesis-qe by syndesisio.
the class OpenshiftValidationSteps method verifyResourceValues.
@Then("^verify that the deployment config \"([^\"]*)\" has the (cpu|memory) (limits|requests) set to \"([^\"]*)\"$")
public void verifyResourceValues(String dcName, String which, String what, String value) {
ResourceRequirements resources = OpenShiftUtils.getInstance().getDeploymentConfig(dcName).getSpec().getTemplate().getSpec().getContainers().get(0).getResources();
Map<String, Quantity> check = "limits".equals(what) ? resources.getLimits() : resources.getRequests();
assertThat(check).isNotNull();
assertThat(check).containsKey(which);
assertThat(check.get(which).getAmount() + check.get(which).getFormat()).isEqualTo(value);
}
use of io.fabric8.kubernetes.api.model.Quantity in project flink by apache.
the class KubernetesUtils method getResourceRequirements.
/**
* Get resource requirements from memory and cpu.
*
* @param resourceRequirements resource requirements in pod template
* @param mem Memory in mb.
* @param memoryLimitFactor limit factor for the memory, used to set the limit resources.
* @param cpu cpu.
* @param cpuLimitFactor limit factor for the cpu, used to set the limit resources.
* @param externalResources external resources
* @param externalResourceConfigKeys config keys of external resources
* @return KubernetesResource requirements.
*/
public static ResourceRequirements getResourceRequirements(ResourceRequirements resourceRequirements, int mem, double memoryLimitFactor, double cpu, double cpuLimitFactor, Map<String, ExternalResource> externalResources, Map<String, String> externalResourceConfigKeys) {
final Quantity cpuQuantity = new Quantity(String.valueOf(cpu));
final Quantity cpuLimitQuantity = new Quantity(String.valueOf(cpu * cpuLimitFactor));
final Quantity memQuantity = new Quantity(mem + Constants.RESOURCE_UNIT_MB);
final Quantity memQuantityLimit = new Quantity(((int) (mem * memoryLimitFactor)) + Constants.RESOURCE_UNIT_MB);
ResourceRequirementsBuilder resourceRequirementsBuilder = new ResourceRequirementsBuilder(resourceRequirements).addToRequests(Constants.RESOURCE_NAME_MEMORY, memQuantity).addToRequests(Constants.RESOURCE_NAME_CPU, cpuQuantity).addToLimits(Constants.RESOURCE_NAME_MEMORY, memQuantityLimit).addToLimits(Constants.RESOURCE_NAME_CPU, cpuLimitQuantity);
// Add the external resources to resource requirement.
for (Map.Entry<String, ExternalResource> externalResource : externalResources.entrySet()) {
final String configKey = externalResourceConfigKeys.get(externalResource.getKey());
if (!StringUtils.isNullOrWhitespaceOnly(configKey)) {
final Quantity resourceQuantity = new Quantity(String.valueOf(externalResource.getValue().getValue().longValue()));
resourceRequirementsBuilder.addToRequests(configKey, resourceQuantity).addToLimits(configKey, resourceQuantity);
LOG.info("Request external resource {} with config key {}.", resourceQuantity.getAmount(), configKey);
}
}
return resourceRequirementsBuilder.build();
}
use of io.fabric8.kubernetes.api.model.Quantity in project flink by apache.
the class KubernetesJobManagerFactoryTest method testPodSpec.
@Test
public void testPodSpec() throws IOException {
kubernetesJobManagerSpecification = KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(flinkPod, kubernetesJobManagerParameters);
final PodSpec resultPodSpec = this.kubernetesJobManagerSpecification.getDeployment().getSpec().getTemplate().getSpec();
assertEquals(1, resultPodSpec.getContainers().size());
assertEquals(SERVICE_ACCOUNT_NAME, resultPodSpec.getServiceAccountName());
assertEquals(3, resultPodSpec.getVolumes().size());
final Container resultedMainContainer = resultPodSpec.getContainers().get(0);
assertEquals(Constants.MAIN_CONTAINER_NAME, resultedMainContainer.getName());
assertEquals(CONTAINER_IMAGE, resultedMainContainer.getImage());
assertEquals(CONTAINER_IMAGE_PULL_POLICY.name(), resultedMainContainer.getImagePullPolicy());
assertEquals(3, resultedMainContainer.getEnv().size());
assertTrue(resultedMainContainer.getEnv().stream().anyMatch(envVar -> envVar.getName().equals("key1")));
assertEquals(3, resultedMainContainer.getPorts().size());
final Map<String, Quantity> requests = resultedMainContainer.getResources().getRequests();
assertEquals(Double.toString(JOB_MANAGER_CPU), requests.get("cpu").getAmount());
assertEquals(String.valueOf(JOB_MANAGER_MEMORY), requests.get("memory").getAmount());
assertEquals(1, resultedMainContainer.getCommand().size());
// The args list is [bash, -c, 'java -classpath $FLINK_CLASSPATH ...'].
assertEquals(3, resultedMainContainer.getArgs().size());
assertEquals(3, resultedMainContainer.getVolumeMounts().size());
}
Aggregations