use of io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatus in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KafkaCluster method calculateRetentionSize.
/**
* Get the current sum of storage as reported by the pvcs.
* This may not match the requested amount ephemerally, or due to rounding
*/
@Override
public Quantity calculateRetentionSize(ManagedKafka managedKafka) {
Kafka current = cachedKafka(managedKafka);
long storageInGbs = informerManager.getPvcsInNamespace(managedKafka.getMetadata().getNamespace()).stream().map(pvc -> {
if (pvc.getStatus() == null) {
return 0L;
}
PersistentVolumeClaimStatus status = pvc.getStatus();
Quantity q = OperandUtils.getOrDefault(status.getCapacity(), "storage", (Quantity) null);
if (q == null) {
return 0L;
}
long value = Quantity.getAmountInBytes(q).longValue();
// round down to the nearest GB - the PVC request is automatically rounded up
return (long) Math.floor(((double) unpadBrokerStorage(managedKafka, current, value)) / (1L << 30));
}).collect(Collectors.summingLong(Long::longValue));
Quantity capacity = managedKafka.getSpec().getCapacity().getMaxDataRetentionSize();
// try to correct for the overall rounding
if (storageInGbs > 0 && (capacity == null || ("Gi".equals(capacity.getFormat()) && (Quantity.getAmountInBytes(capacity).longValue() / (1L << 30)) % getBrokerReplicas(managedKafka, current) != 0))) {
storageInGbs++;
}
return Quantity.parse(String.format("%sGi", storageInGbs));
}
Aggregations