Search in sources :

Example 26 with ManagedKafka

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

the class ManagedKafkaResourceType method readiness.

@Override
public Predicate<ManagedKafka> readiness(KubeClient client) {
    AtomicInteger count = new AtomicInteger();
    Set<String> messages = Collections.synchronizedSet(new LinkedHashSet<>());
    return mk -> {
        if (mk == null) {
            throw new IllegalStateException("ManagedKafka is null");
        }
        ManagedKafkaCondition mkc = getCondition(mk.getStatus(), ManagedKafkaCondition.Type.Ready).orElse(null);
        if (mkc == null) {
            return false;
        }
        if (ManagedKafkaCondition.Status.True.name().equals(mkc.getStatus())) {
            return true;
        }
        if (ManagedKafkaCondition.Reason.Error.name().equals(mkc.getReason())) {
            if (messages.add(mkc.getMessage())) {
                LOGGER.warn("ManagedKafka {} in error state {}", mk.getMetadata().getName(), mkc.getMessage());
            }
        // throw new IllegalStateException(String.format("ManagedKafka %s in error state %s", mk.getMetadata().getName(), mkc.getMessage()));
        }
        if (count.getAndIncrement() % 15 == 0) {
            ListOptions opts = new ListOptionsBuilder().withFieldSelector("status.phase=Pending").build();
            client.client().pods().inNamespace(mk.getMetadata().getNamespace()).withLabel("strimzi.io/cluster").list(opts).getItems().forEach(ManagedKafkaResourceType::checkUnschedulablePod);
        }
        return false;
    };
}
Also used : KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) ListOptionsBuilder(io.fabric8.kubernetes.api.model.ListOptionsBuilder) ListOptions(io.fabric8.kubernetes.api.model.ListOptions) Resource(io.fabric8.kubernetes.client.dsl.Resource) KubeClient(org.bf2.test.k8s.KubeClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedKafkaStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus) LinkedHashSet(java.util.LinkedHashSet) KeycloakInstance(org.bf2.systemtest.framework.KeycloakInstance) SecurityUtils(org.bf2.systemtest.framework.SecurityUtils) Predicate(java.util.function.Predicate) TestUtils(org.bf2.test.TestUtils) Pod(io.fabric8.kubernetes.api.model.Pod) SystemTestEnvironment(org.bf2.systemtest.framework.SystemTestEnvironment) Set(java.util.Set) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) Optional(java.util.Optional) Kafka(io.strimzi.api.kafka.model.Kafka) LogManager(org.apache.logging.log4j.LogManager) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ListOptions(io.fabric8.kubernetes.api.model.ListOptions) ListOptionsBuilder(io.fabric8.kubernetes.api.model.ListOptionsBuilder) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)

Example 27 with ManagedKafka

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

the class KafkaManager method currentKafkaVersion.

/**
 * Returns the current Kafka version for the Kafka instance
 * It comes directly from the Kafka custom resource or from the ManagedKafka in case of creation
 *
 * @param managedKafka ManagedKafka instance
 * @return current Kafka version for the Kafka instance
 */
public String currentKafkaVersion(ManagedKafka managedKafka) {
    Kafka kafka = cachedKafka(managedKafka);
    // on first time Kafka resource creation, we take the Kafka version from the ManagedKafka resource spec
    String kafkaVersion = kafka != null ? kafka.getSpec().getKafka().getVersion() : managedKafka.getSpec().getVersions().getKafka();
    log.debugf("[%s/%s] currentKafkaVersion = %s", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), kafkaVersion);
    return kafkaVersion;
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Example 28 with ManagedKafka

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

the class KafkaManager method currentKafkaLogMessageFormatVersion.

/**
 * Returns the current Kafka log message format version for the Kafka instance
 * It comes directly from the Kafka custom resource or from the ManagedKafka in case of creation
 *
 * @param managedKafka ManagedKafka instance
 * @return current Kafka log message format version for the Kafka instance
 */
public String currentKafkaLogMessageFormatVersion(ManagedKafka managedKafka) {
    Kafka kafka = cachedKafka(managedKafka);
    String kafkaLogMessageFormatVersion;
    String current;
    // on first time Kafka resource creation, we take the Kafka log message format version from the ManagedKafka resource spec
    if (kafka != null) {
        Object logMessageFormat = kafka.getSpec().getKafka().getConfig().get("log.message.format.version");
        current = logMessageFormat != null ? logMessageFormat.toString() : kafka.getSpec().getKafka().getVersion();
    } else {
        current = managedKafka.getSpec().getVersions().getKafka();
    }
    kafkaLogMessageFormatVersion = AbstractKafkaCluster.getKafkaLogMessageFormatVersion(current);
    log.debugf("[%s/%s] currentKafkaLogMessageFormatVersion = %s", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), kafkaLogMessageFormatVersion);
    return kafkaLogMessageFormatVersion;
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Example 29 with ManagedKafka

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

the class KafkaManager method currentKafkaIbpVersion.

/**
 * Returns the current Kafka inter broker protocol version for the Kafka instance
 * It comes directly from the Kafka custom resource or from the ManagedKafka in case of creation
 *
 * @param managedKafka ManagedKafka instance
 * @return current Kafka inter broker protocol version for the Kafka instance
 */
public String currentKafkaIbpVersion(ManagedKafka managedKafka) {
    Kafka kafka = cachedKafka(managedKafka);
    String kafkaIbpVersion;
    // on first time Kafka resource creation, we take the Kafka inter broker protocol version from the ManagedKafka resource spec
    if (kafka != null) {
        Object interBrokerProtocol = kafka.getSpec().getKafka().getConfig().get("inter.broker.protocol.version");
        kafkaIbpVersion = interBrokerProtocol != null ? AbstractKafkaCluster.getKafkaIbpVersion(interBrokerProtocol.toString()) : AbstractKafkaCluster.getKafkaIbpVersion(kafka.getSpec().getKafka().getVersion());
    } else {
        kafkaIbpVersion = managedKafka.getSpec().getVersions().getKafkaIbp();
        // dealing with ManagedKafka instances not having the IBP field specified
        if (kafkaIbpVersion == null) {
            kafkaIbpVersion = AbstractKafkaCluster.getKafkaIbpVersion(managedKafka.getSpec().getVersions().getKafka());
        }
    }
    log.debugf("[%s/%s] currentKafkaIbpVersion = %s", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), kafkaIbpVersion);
    return kafkaIbpVersion;
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Example 30 with ManagedKafka

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

the class OperatorST method testResizeAndCapacity.

@ParallelTest
void testResizeAndCapacity(ExtensionContext extensionContext) throws Exception {
    String mkAppName = "mk-test-resize-capacity";
    LOGGER.info("Create namespace");
    resourceManager.addResource(extensionContext, new NamespaceBuilder().withNewMetadata().withName(mkAppName).endMetadata().build());
    LOGGER.info("Create managedkafka");
    ManagedKafka mk = ManagedKafkaResourceType.getDefault(mkAppName, mkAppName, null, latestStrimziVersion, latestKafkaVersion);
    Quantity quantity = Quantity.parse("100Gi");
    // for values below 270Gi, the logic will report a slightly larger values
    Quantity reportedQuantity = Quantity.parse("103Gi");
    mk.getSpec().getCapacity().setMaxDataRetentionSize(quantity);
    mk = resourceManager.createResource(extensionContext, mk);
    Resource<ManagedKafka> mkResource = kube.client().resources(ManagedKafka.class).inNamespace(mk.getMetadata().getNamespace()).withName(mk.getMetadata().getName());
    assertEquals(reportedQuantity, mk.getStatus().getCapacity().getMaxDataRetentionSize());
    LOGGER.info("Trying to shrink");
    mk.getSpec().getCapacity().setMaxDataRetentionSize(Quantity.parse("50Gi"));
    mk = mkResource.createOrReplace(mk);
    String currentVersion = mk.getMetadata().getResourceVersion();
    // wait until the status is updated
    mk = mkResource.waitUntilCondition(m -> !Objects.equals(currentVersion, m.getMetadata().getResourceVersion()), 2, TimeUnit.MINUTES);
    // should be the same, as we can't resize down
    assertEquals(reportedQuantity, mk.getStatus().getCapacity().getMaxDataRetentionSize());
    LOGGER.info("Trying to grow");
    mk.getSpec().getCapacity().setMaxDataRetentionSize(Quantity.parse("200Gi"));
    mk = mkResource.createOrReplace(mk);
    // should grow - again the size is a little off
    Quantity endReportedQuantity = Quantity.parse("202Gi");
    mk = mkResource.waitUntilCondition(m -> endReportedQuantity.equals(m.getStatus().getCapacity().getMaxDataRetentionSize()), 5, TimeUnit.MINUTES);
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) StrimziOperatorManager(org.bf2.systemtest.operator.StrimziOperatorManager) SyncApiClient(org.bf2.systemtest.api.sync.SyncApiClient) SequentialTest(org.bf2.systemtest.framework.SequentialTest) ManagedKafkaAgentBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedKafkaAgentSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentSpecBuilder) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) AfterAll(org.junit.jupiter.api.AfterAll) Resource(io.fabric8.kubernetes.client.dsl.Resource) AbstractST(org.bf2.systemtest.integration.AbstractST) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ManagedKafkaAgentResourceClient(org.bf2.common.ManagedKafkaAgentResourceClient) FleetShardOperatorManager(org.bf2.systemtest.operator.FleetShardOperatorManager) ManagedKafkaResourceType(org.bf2.systemtest.framework.resource.ManagedKafkaResourceType) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) ParallelTest(org.bf2.systemtest.framework.ParallelTest) LogManager(org.apache.logging.log4j.LogManager) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Quantity(io.fabric8.kubernetes.api.model.Quantity) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) ParallelTest(org.bf2.systemtest.framework.ParallelTest)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)67 Kafka (io.strimzi.api.kafka.model.Kafka)30 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)23 List (java.util.List)16 Map (java.util.Map)15 Inject (javax.inject.Inject)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Objects (java.util.Objects)14 Quantity (io.fabric8.kubernetes.api.model.Quantity)11 Optional (java.util.Optional)11 Collectors (java.util.stream.Collectors)10 ApplicationScoped (javax.enterprise.context.ApplicationScoped)9 StrimziManager (org.bf2.operator.managers.StrimziManager)9 Logger (org.jboss.logging.Logger)9 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 ArrayList (java.util.ArrayList)8 Reason (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason)8 Status (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status)8 ManagedKafkaUtils.exampleManagedKafka (org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka)8