Search in sources :

Example 1 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class AbstractKafkaCluster method getReadiness.

@Override
public OperandReadiness getReadiness(ManagedKafka managedKafka) {
    Kafka kafka = cachedKafka(managedKafka);
    if (kafka == null) {
        return new OperandReadiness(Status.False, Reason.Installing, String.format("Kafka %s does not exist", kafkaClusterName(managedKafka)));
    }
    Optional<Condition> notReady = kafkaCondition(kafka, c -> "NotReady".equals(c.getType()));
    if (notReady.filter(c -> "True".equals(c.getStatus())).isPresent()) {
        Condition c = notReady.get();
        return new OperandReadiness(Status.False, "Creating".equals(c.getReason()) ? Reason.Installing : Reason.Error, c.getMessage());
    }
    if (isStrimziUpdating(managedKafka)) {
        // the status here is actually unknown
        return new OperandReadiness(Status.True, Reason.StrimziUpdating, null);
    }
    if (isKafkaUpdating(managedKafka) || isKafkaUpgradeStabilityChecking(managedKafka)) {
        return new OperandReadiness(Status.True, Reason.KafkaUpdating, null);
    }
    if (isKafkaIbpUpdating(managedKafka)) {
        return new OperandReadiness(Status.True, Reason.KafkaIbpUpdating, null);
    }
    Optional<Condition> ready = kafkaCondition(kafka, c -> "Ready".equals(c.getType()));
    if (ready.filter(c -> "True".equals(c.getStatus())).isPresent()) {
        return new OperandReadiness(Status.True, null, null);
    }
    if (isReconciliationPaused(managedKafka)) {
        // strimzi may in the future report the status even when paused, but for now we don't know
        return new OperandReadiness(Status.Unknown, Reason.Paused, String.format("Kafka %s is paused for an unknown reason", kafkaClusterName(managedKafka)));
    }
    return new OperandReadiness(Status.False, Reason.Installing, String.format("Kafka %s is not providing status", kafkaClusterName(managedKafka)));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Quantity(io.fabric8.kubernetes.api.model.Quantity) Context(io.javaoperatorsdk.operator.api.Context) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) Arrays(java.util.Arrays) GenericSecretSource(io.strimzi.api.kafka.model.GenericSecretSource) Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Logger(org.jboss.logging.Logger) KafkaListenerAuthentication(io.strimzi.api.kafka.model.listener.KafkaListenerAuthentication) StrimziManager(org.bf2.operator.managers.StrimziManager) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerConfigurationBootstrapBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CertAndKeySecretSourceBuilder(io.strimzi.api.kafka.model.CertAndKeySecretSourceBuilder) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) SecuritySecretManager(org.bf2.operator.managers.SecuritySecretManager) Map(java.util.Map) KafkaManager(org.bf2.operator.managers.KafkaManager) KafkaResourceClient(org.bf2.operator.clients.KafkaResourceClient) CertAndKeySecretSource(io.strimzi.api.kafka.model.CertAndKeySecretSource) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) Predicate(java.util.function.Predicate) Pod(io.fabric8.kubernetes.api.model.Pod) InformerManager(org.bf2.operator.managers.InformerManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ManagedKafkaAuthenticationOAuth(org.bf2.operator.resources.v1alpha1.ManagedKafkaAuthenticationOAuth) Objects(java.util.Objects) List(java.util.List) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) GenericSecretSourceBuilder(io.strimzi.api.kafka.model.GenericSecretSourceBuilder) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) Optional(java.util.Optional) NetworkPolicyPeerBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeerBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Collections(java.util.Collections) GenericKafkaListenerConfigurationBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Example 2 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status 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)

Example 3 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaInstance method getReadiness.

@Override
public OperandReadiness getReadiness(ManagedKafka managedKafka) {
    if (managedKafka.getSpec().isDeleted()) {
        // TODO: it may be a good idea to offer a message here as well
        return new OperandReadiness(isDeleted(managedKafka) ? Status.False : Status.Unknown, Reason.Deleted, null);
    }
    List<OperandReadiness> readiness = operands.stream().map(o -> o.getReadiness(managedKafka)).filter(Objects::nonNull).collect(Collectors.toList());
    // default to the first reason, with can come from the kafka by the order of the operands
    Reason reason = readiness.stream().map(OperandReadiness::getReason).filter(Objects::nonNull).findFirst().orElse(null);
    // default the status to false or unknown if any are unknown
    Status status = readiness.stream().anyMatch(r -> Status.Unknown.equals(r.getStatus())) ? Status.Unknown : Status.False;
    // combine all the messages
    String message = readiness.stream().map(OperandReadiness::getMessage).filter(Objects::nonNull).collect(Collectors.joining("; "));
    // override in particular scenarios
    if (readiness.stream().allMatch(r -> Status.True.equals(r.getStatus()))) {
        status = Status.True;
    } else if (readiness.stream().anyMatch(r -> Reason.Installing.equals(r.getReason()))) {
        // may mask other error states
        reason = Reason.Installing;
    } else if (readiness.stream().anyMatch(r -> Reason.Error.equals(r.getReason()))) {
        reason = Reason.Error;
    }
    return new OperandReadiness(status, reason, message);
}
Also used : Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Context(io.javaoperatorsdk.operator.api.Context) Arrays(java.util.Arrays) ImagePullSecretManager(org.bf2.operator.managers.ImagePullSecretManager) Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason) Deque(java.util.Deque) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Objects(java.util.Objects) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ArrayDeque(java.util.ArrayDeque) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Objects(java.util.Objects) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason)

Example 4 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaControllerTest method shouldCreateStatus.

@Test
void shouldCreateStatus() throws InterruptedException {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    mk.getMetadata().setUid(UUID.randomUUID().toString());
    mk.getMetadata().setGeneration(1l);
    mk.getMetadata().setResourceVersion("1");
    // create
    Context<ManagedKafka> context = Mockito.mock(Context.class);
    Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
    StrimziManager strimziManager = Mockito.mock(StrimziManager.class);
    Mockito.when(strimziManager.getStrimziVersion("strimzi-cluster-operator.v0.23.0")).thenReturn(new StrimziVersionStatusBuilder().withVersion(mk.getSpec().getVersions().getStrimzi()).withKafkaVersions(mk.getSpec().getVersions().getKafka()).build());
    Mockito.when(strimziManager.getVersionLabel()).thenReturn("managedkafka.bf2.org/strimziVersion");
    QuarkusMock.installMockForType(strimziManager, StrimziManager.class);
    mkController.createOrUpdateResource(mk, context);
    ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
    assertEquals(ManagedKafkaCondition.Reason.Installing.name(), condition.getReason());
    mk.getSpec().setDeleted(true);
    // this simulates, but not exactly an issue seen with older logic
    // essentially there "last event" of the delete is something other than a deployment or a kafka
    // it should still trigger the update of the status
    Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new ResourceEvent<>(new ServiceBuilder().withNewMetadata().withOwnerReferences(new OwnerReferenceBuilder().withUid(mk.getMetadata().getUid()).build()).endMetadata().build(), null, Watcher.Action.DELETED))));
    mkController.createOrUpdateResource(mk, context);
    // should now be deleted
    condition = mk.getStatus().getConditions().get(0);
    assertEquals(ManagedKafkaCondition.Reason.Deleted.name(), condition.getReason());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) EventList(io.javaoperatorsdk.operator.processing.event.EventList) StrimziManager(org.bf2.operator.managers.StrimziManager) CustomResourceEvent(io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 5 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class StrimziBundleManager method updateStatus.

/**
 * Update status of ManagedKafkaAgent resource about approval of Strimzi bundle installation
 * NOTE: it creates a condition if Strimzi bundle installation was not approved. The condition is taken out if approved.
 *
 * @param approval the status of the approval
 */
private void updateStatus(Approval approval) {
    ManagedKafkaAgent resource = this.agentClient.getByName(this.agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME);
    if (resource != null && resource.getStatus() != null) {
        List<ManagedKafkaCondition> conditions = resource.getStatus().getConditions();
        ManagedKafkaCondition bundleReadyCondition = ConditionUtils.findManagedKafkaCondition(conditions, ManagedKafkaCondition.Type.StrimziBundleReady).orElse(null);
        ManagedKafkaCondition.Reason reason = ManagedKafkaCondition.Reason.OrphanedKafkas;
        ManagedKafkaCondition.Status status = ManagedKafkaCondition.Status.False;
        if (approval != Approval.ORPHANED) {
            if (bundleReadyCondition == null) {
                return;
            }
            conditions.remove(bundleReadyCondition);
        } else {
            if (bundleReadyCondition == null) {
                bundleReadyCondition = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.StrimziBundleReady, status);
                bundleReadyCondition.reason(reason);
                conditions.add(bundleReadyCondition);
            } else {
                ConditionUtils.updateConditionStatus(bundleReadyCondition, status, reason, null);
            }
        }
        this.agentClient.replaceStatus(resource);
    }
}
Also used : ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent)

Aggregations

Test (org.junit.jupiter.api.Test)14 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)12 Objects (java.util.Objects)11 QuarkusTest (io.quarkus.test.junit.QuarkusTest)9 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)7 ManagedConnectorSpecBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder)7 Map (java.util.Map)6 Inject (javax.inject.Inject)6 OperatorSelectorBuilder (org.bf2.cos.fleetshard.api.OperatorSelectorBuilder)6 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)5 List (java.util.List)5 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)5 Status (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status)5 Quantity (io.fabric8.kubernetes.api.model.Quantity)4 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)4 Transactional (javax.transaction.Transactional)4 ManagedKafkaCondition (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)4 ManagedKafkaStatus (org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus)4