Search in sources :

Example 1 with PersistentVolumeClaimStatus

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));
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) PodAffinityTerm(io.fabric8.kubernetes.api.model.PodAffinityTerm) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ImagePullSecretManager(org.bf2.operator.managers.ImagePullSecretManager) Storage(io.strimzi.api.kafka.model.storage.Storage) Rack(io.strimzi.api.kafka.model.Rack) StrimziManager(org.bf2.operator.managers.StrimziManager) Resource(io.fabric8.kubernetes.client.dsl.Resource) JvmOptionsBuilder(io.strimzi.api.kafka.model.JvmOptionsBuilder) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaClusterTemplate(io.strimzi.api.kafka.model.template.KafkaClusterTemplate) SystemProperty(io.strimzi.api.kafka.model.SystemProperty) Map(java.util.Map) KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) KafkaSpec(io.strimzi.api.kafka.model.KafkaSpec) KafkaManager(org.bf2.operator.managers.KafkaManager) Instance(javax.enterprise.inject.Instance) ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) ZookeeperClusterTemplateBuilder(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateBuilder) JvmOptions(io.strimzi.api.kafka.model.JvmOptions) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) OperandUtils(org.bf2.common.OperandUtils) DrainCleanerManager(org.bf2.operator.managers.DrainCleanerManager) Config(org.eclipse.microprofile.config.Config) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) PodAffinityTermBuilder(io.fabric8.kubernetes.api.model.PodAffinityTermBuilder) Startup(io.quarkus.runtime.Startup) List(java.util.List) RackBuilder(io.strimzi.api.kafka.model.RackBuilder) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) DatatypeConverter(javax.xml.bind.DatatypeConverter) ZookeeperClusterTemplate(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplate) PersistentVolumeClaimStatus(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatus) Context(io.javaoperatorsdk.operator.api.Context) ZookeeperClusterSpec(io.strimzi.api.kafka.model.ZookeeperClusterSpec) ExternalLoggingBuilder(io.strimzi.api.kafka.model.ExternalLoggingBuilder) MessageDigest(java.security.MessageDigest) Logger(org.jboss.logging.Logger) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) KafkaAuthorizationCustomBuilder(io.strimzi.api.kafka.model.KafkaAuthorizationCustomBuilder) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Inject(javax.inject.Inject) PodDisruptionBudgetTemplateBuilder(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder) DefaultBean(io.quarkus.arc.DefaultBean) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) PodAntiAffinity(io.fabric8.kubernetes.api.model.PodAntiAffinity) ExternalConfigurationReferenceBuilder(io.strimzi.api.kafka.model.ExternalConfigurationReferenceBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) KafkaAuthorization(io.strimzi.api.kafka.model.KafkaAuthorization) KafkaClusterTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) SecuritySecretManager(org.bf2.operator.managers.SecuritySecretManager) PodAffinity(io.fabric8.kubernetes.api.model.PodAffinity) PodAntiAffinityBuilder(io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder) Versions(org.bf2.operator.resources.v1alpha1.Versions) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) IngressControllerManager(org.bf2.operator.managers.IngressControllerManager) Toleration(io.fabric8.kubernetes.api.model.Toleration) IOException(java.io.IOException) PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) ServiceAccount(org.bf2.operator.resources.v1alpha1.ServiceAccount) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ManagedKafkaAuthenticationOAuth(org.bf2.operator.resources.v1alpha1.ManagedKafkaAuthenticationOAuth) KafkaExporterSpecBuilder(io.strimzi.api.kafka.model.KafkaExporterSpecBuilder) AccessControl(org.bf2.operator.operands.KafkaInstanceConfiguration.AccessControl) SystemPropertyBuilder(io.strimzi.api.kafka.model.SystemPropertyBuilder) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) DigestInputStream(java.security.DigestInputStream) PodNested(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateFluent.PodNested) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Kafka(io.strimzi.api.kafka.model.Kafka) Collections(java.util.Collections) InputStream(java.io.InputStream) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentVolumeClaimStatus(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatus) Quantity(io.fabric8.kubernetes.api.model.Quantity)

Aggregations

AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 ConfigMapKeySelector (io.fabric8.kubernetes.api.model.ConfigMapKeySelector)1 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)1 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 PersistentVolumeClaimStatus (io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatus)1 PodAffinity (io.fabric8.kubernetes.api.model.PodAffinity)1 PodAffinityTerm (io.fabric8.kubernetes.api.model.PodAffinityTerm)1 PodAffinityTermBuilder (io.fabric8.kubernetes.api.model.PodAffinityTermBuilder)1 PodAntiAffinity (io.fabric8.kubernetes.api.model.PodAntiAffinity)1 PodAntiAffinityBuilder (io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)1 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)1 Toleration (io.fabric8.kubernetes.api.model.Toleration)1 TolerationBuilder (io.fabric8.kubernetes.api.model.TolerationBuilder)1 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)1 TopologySpreadConstraintBuilder (io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1