Search in sources :

Example 11 with KafkaRebalanceStatus

use of io.strimzi.api.kafka.model.status.KafkaRebalanceStatus in project strimzi by strimzi.

the class CruiseControlST method testCruiseControlIntraBrokerBalancing.

@ParallelNamespaceTest
@KRaftNotSupported("JBOD is not supported by KRaft mode and is used in this test case.")
void testCruiseControlIntraBrokerBalancing(ExtensionContext extensionContext) {
    final TestStorage testStorage = new TestStorage(extensionContext);
    String diskSize = "6Gi";
    JbodStorage jbodStorage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(true).withId(0).withSize(diskSize).build(), new PersistentClaimStorageBuilder().withDeleteClaim(true).withId(1).withSize(diskSize).build()).build();
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaWithCruiseControl(testStorage.getClusterName(), 3, 3).editMetadata().withNamespace(testStorage.getNamespaceName()).endMetadata().editOrNewSpec().editKafka().withStorage(jbodStorage).endKafka().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaRebalanceTemplates.kafkaRebalance(testStorage.getClusterName()).editMetadata().withNamespace(testStorage.getNamespaceName()).endMetadata().editOrNewSpec().withRebalanceDisk(true).endSpec().build());
    KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady);
    LOGGER.info("Checking status of KafkaRebalance");
    // The provision status should be "UNDECIDED" when doing an intra-broker disk balance because it is irrelevant to the provision status
    KafkaRebalanceStatus kafkaRebalanceStatus = KafkaRebalanceResource.kafkaRebalanceClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).get().getStatus();
    assertThat(kafkaRebalanceStatus.getOptimizationResult().get("provisionStatus").toString(), containsString("UNDECIDED"));
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) TestStorage(io.strimzi.systemtest.storage.TestStorage) Matchers.containsString(org.hamcrest.Matchers.containsString) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 12 with KafkaRebalanceStatus

use of io.strimzi.api.kafka.model.status.KafkaRebalanceStatus in project strimzi by strimzi.

the class CruiseControlST method testCruiseControlIntraBrokerBalancingWithoutSpecifyingJBODStorage.

@ParallelNamespaceTest
void testCruiseControlIntraBrokerBalancingWithoutSpecifyingJBODStorage(ExtensionContext extensionContext) {
    final TestStorage testStorage = new TestStorage(extensionContext);
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaWithCruiseControl(testStorage.getClusterName(), 3, 3).build());
    resourceManager.createResource(extensionContext, false, KafkaRebalanceTemplates.kafkaRebalance(testStorage.getClusterName()).editOrNewSpec().withRebalanceDisk(true).endSpec().build());
    KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.NotReady);
    // The intra-broker rebalance will fail for Kafka clusters with a non-JBOD configuration.
    KafkaRebalanceStatus kafkaRebalanceStatus = KafkaRebalanceResource.kafkaRebalanceClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).get().getStatus();
    assertThat(kafkaRebalanceStatus.getConditions().get(0).getReason(), is("InvalidResourceException"));
}
Also used : KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) TestStorage(io.strimzi.systemtest.storage.TestStorage) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 13 with KafkaRebalanceStatus

use of io.strimzi.api.kafka.model.status.KafkaRebalanceStatus in project strimzi by strimzi.

the class KafkaRebalanceUtils method waitForRebalanceStatusStability.

public static void waitForRebalanceStatusStability(Reconciliation reconciliation, String namespaceName, String resourceName) {
    int[] stableCounter = { 0 };
    KafkaRebalanceStatus oldStatus = KafkaRebalanceResource.kafkaRebalanceClient().inNamespace(namespaceName).withName(resourceName).get().getStatus();
    TestUtils.waitFor("KafkaRebalance status will be stable", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_STATUS_TIMEOUT, () -> {
        if (KafkaRebalanceResource.kafkaRebalanceClient().inNamespace(namespaceName).withName(resourceName).get().getStatus().equals(oldStatus)) {
            stableCounter[0]++;
            if (stableCounter[0] == Constants.GLOBAL_STABILITY_OFFSET_COUNT) {
                LOGGER.infoCr(reconciliation, "KafkaRebalance status is stable for {} polls intervals", stableCounter[0]);
                return true;
            }
        } else {
            LOGGER.infoCr(reconciliation, "KafkaRebalance status is not stable. Going to set the counter to zero.");
            stableCounter[0] = 0;
            return false;
        }
        LOGGER.infoCr(reconciliation, "KafkaRebalance status gonna be stable in {} polls", Constants.GLOBAL_STABILITY_OFFSET_COUNT - stableCounter[0]);
        return false;
    });
}
Also used : KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus)

Example 14 with KafkaRebalanceStatus

use of io.strimzi.api.kafka.model.status.KafkaRebalanceStatus in project strimzi by strimzi.

the class KafkaRebalanceStateMachineTest method createKafkaRebalance.

/**
 * Creates an example {@link KafkaRebalanceBuilder} instance using the supplied state parameters.
 *
 * @param currentState The current state of the resource before being passed to computeNextStatus.
 * @param currentStatusSessionID The user task ID attached to the current KafkaRebalance resource. Can be null.
 * @param userAnnotation An annotation to be applied after the reconcile has started, for example "approve" or "stop".
 * @param rebalanceSpec A custom rebalance specification. If null a blank spec will be used.
 * @return A KafkaRebalance instance configured with the supplied parameters.
 */
private KafkaRebalance createKafkaRebalance(KafkaRebalanceState currentState, String currentStatusSessionID, String userAnnotation, KafkaRebalanceSpec rebalanceSpec) {
    KafkaRebalanceBuilder kafkaRebalanceBuilder = new KafkaRebalanceBuilder().editOrNewMetadata().withName(RESOURCE_NAME).withNamespace(CLUSTER_NAMESPACE).withLabels(Collections.singletonMap(Labels.STRIMZI_CLUSTER_LABEL, CLUSTER_NAME)).withAnnotations(Collections.singletonMap(Annotations.ANNO_STRIMZI_IO_REBALANCE, userAnnotation == null ? "none" : userAnnotation)).endMetadata().withSpec(rebalanceSpec);
    // there is no actual status and related condition when a KafkaRebalance is just created
    if (currentState != KafkaRebalanceState.New) {
        Condition currentRebalanceCondition = new Condition();
        currentRebalanceCondition.setType(currentState.toString());
        currentRebalanceCondition.setStatus("True");
        KafkaRebalanceStatus currentStatus = new KafkaRebalanceStatus();
        currentStatus.setConditions(Collections.singletonList(currentRebalanceCondition));
        currentStatus.setSessionId(currentStatusSessionID);
        kafkaRebalanceBuilder.withStatus(currentStatus);
    }
    return kafkaRebalanceBuilder.build();
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder)

Example 15 with KafkaRebalanceStatus

use of io.strimzi.api.kafka.model.status.KafkaRebalanceStatus in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperatorTest method krNewToPendingProposalToProposalReady.

private void krNewToPendingProposalToProposalReady(VertxTestContext context, int pendingCalls, CruiseControlEndpoints endpoint, KafkaRebalance kr) throws IOException, URISyntaxException {
    // Setup the rebalance endpoint with the number of pending calls before a response is received.
    MockCruiseControl.setupCCRebalanceResponse(ccServer, pendingCalls, endpoint);
    Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).create(kr);
    when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
    mockSecretResources();
    mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, kr.getMetadata().getName(), client);
    Checkpoint checkpoint = context.checkpoint();
    kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), kr).onComplete(context.succeeding(v -> {
        // the resource moved from New to PendingProposal (due to the configured Mock server pending calls)
        assertState(context, client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceState.PendingProposal);
    })).compose(v -> {
        // trigger another reconcile to process the PendingProposal state
        KafkaRebalance kr1 = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(kr.getMetadata().getName()).get();
        return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), kr1);
    }).onComplete(context.succeeding(v -> {
        // the resource moved from PendingProposal to ProposalReady
        assertState(context, client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceState.ProposalReady);
        context.verify(() -> {
            KafkaRebalanceStatus rebalanceStatus = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(kr.getMetadata().getName()).get().getStatus();
            assertTrue(rebalanceStatus.getOptimizationResult().size() > 0);
            assertNotNull(rebalanceStatus.getSessionId());
        });
        checkpoint.flag();
    }));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) URISyntaxException(java.net.URISyntaxException) Annotations(io.strimzi.operator.common.Annotations) KafkaRebalanceSpecBuilder(io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) VertxExtension(io.vertx.junit5.VertxExtension) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) ClientAndServer(org.mockserver.integration.ClientAndServer) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Test(org.junit.jupiter.api.Test) Labels(io.strimzi.operator.common.model.Labels) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaList(io.strimzi.api.kafka.KafkaList) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) Crds(io.strimzi.api.kafka.Crds) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) CruiseControlEndpoints(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlEndpoints) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) TestUtils(io.strimzi.test.TestUtils) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) ConnectException(java.net.ConnectException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoStackTraceTimeoutException(io.strimzi.operator.common.operator.resource.NoStackTraceTimeoutException) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) MockCruiseControl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.MockCruiseControl) Collections(java.util.Collections) Checkpoint(io.vertx.junit5.Checkpoint) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance)

Aggregations

KafkaRebalanceStatus (io.strimzi.api.kafka.model.status.KafkaRebalanceStatus)22 Secret (io.fabric8.kubernetes.api.model.Secret)12 KafkaRebalanceBuilder (io.strimzi.api.kafka.model.KafkaRebalanceBuilder)12 KafkaRebalanceAnnotation (io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation)12 KafkaRebalanceState (io.strimzi.api.kafka.model.balancing.KafkaRebalanceState)12 Condition (io.strimzi.api.kafka.model.status.Condition)12 InvalidResourceException (io.strimzi.operator.cluster.model.InvalidResourceException)12 NoSuchResourceException (io.strimzi.operator.cluster.model.NoSuchResourceException)12 CruiseControlApi (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi)12 Reconciliation (io.strimzi.operator.common.Reconciliation)12 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)10 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)10 KafkaList (io.strimzi.api.kafka.KafkaList)10 KafkaRebalanceList (io.strimzi.api.kafka.KafkaRebalanceList)10 CruiseControlResources (io.strimzi.api.kafka.model.CruiseControlResources)10 Kafka (io.strimzi.api.kafka.model.Kafka)10 KafkaRebalance (io.strimzi.api.kafka.model.KafkaRebalance)10 KafkaRebalanceSpec (io.strimzi.api.kafka.model.KafkaRebalanceSpec)10 JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)10 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)10