Search in sources :

Example 6 with KafkaStatus

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

the class KafkaStatusTest method testPauseReconciliationsStatus.

@Test
public void testPauseReconciliationsStatus(VertxTestContext context) throws ParseException {
    Kafka kafka = getKafkaCrd();
    kafka.getMetadata().setAnnotations(singletonMap("strimzi.io/pause-reconciliation", Boolean.toString(true)));
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the Kafka Operator
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(getKafkaCrd()));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    MockWorkingKafkaAssemblyOperator kao = new MockWorkingKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        assertThat(kafkaCaptor.getValue(), is(notNullValue()));
        assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
        KafkaStatus status = kafkaCaptor.getValue().getStatus();
        assertThat(status.getConditions().size(), is(1));
        assertThat(status.getConditions().get(0).getStatus(), is("True"));
        assertThat(status.getConditions().get(0).getType(), is("ReconciliationPaused"));
        assertThat(status.getObservedGeneration(), is(1L));
        async.flag();
    });
}
Also used : ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 7 with KafkaStatus

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

the class KafkaStatusTest method testStatusAfterSuccessfulReconciliationWithPreviousFailure.

@Test
public void testStatusAfterSuccessfulReconciliationWithPreviousFailure(VertxTestContext context) throws ParseException {
    Kafka kafka = getKafkaCrd();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the Kafka Operator
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(getKafkaCrd()));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    MockWorkingKafkaAssemblyOperator kao = new MockWorkingKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        assertThat(kafkaCaptor.getValue(), is(notNullValue()));
        assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
        KafkaStatus status = kafkaCaptor.getValue().getStatus();
        assertThat(status.getListeners().size(), is(2));
        assertThat(status.getListeners().get(0).getType(), is("plain"));
        assertThat(status.getListeners().get(0).getName(), is("plain"));
        assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("my-service.my-namespace.svc"));
        assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(Integer.valueOf(9092)));
        assertThat(status.getListeners().get(0).getBootstrapServers(), is("my-service.my-namespace.svc:9092"));
        assertThat(status.getListeners().get(1).getType(), is("external"));
        assertThat(status.getListeners().get(1).getName(), is("external"));
        assertThat(status.getListeners().get(1).getAddresses().get(0).getHost(), is("my-route-address.domain.tld"));
        assertThat(status.getListeners().get(1).getAddresses().get(0).getPort(), is(Integer.valueOf(443)));
        assertThat(status.getListeners().get(1).getBootstrapServers(), is("my-route-address.domain.tld:443"));
        assertThat(status.getConditions().size(), is(1));
        assertThat(status.getConditions().get(0).getType(), is("Ready"));
        assertThat(status.getConditions().get(0).getStatus(), is("True"));
        assertThat(status.getObservedGeneration(), is(2L));
        async.flag();
    });
}
Also used : ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 8 with KafkaStatus

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

the class KafkaStatusTest method testStatusAfterFailedReconciliationWithPreviousSuccess.

@Test
public void testStatusAfterFailedReconciliationWithPreviousSuccess(VertxTestContext context) throws ParseException {
    Kafka kafka = getKafkaCrd();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the Kafka Operator
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    Kafka readyKafka = new KafkaBuilder(kafka).editStatus().withObservedGeneration(1L).editCondition(0).withType("Ready").endCondition().withListeners(new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build(), new ListenerStatusBuilder().withName("external").withAddresses(new ListenerAddressBuilder().withHost("my-route-address.domain.tld").withPort(443).build()).build()).endStatus().build();
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(readyKafka));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(readyKafka);
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    MockFailingKafkaAssemblyOperator kao = new MockFailingKafkaAssemblyOperator(new RuntimeException("Something went wrong"), vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
        assertThat(res.succeeded(), is(false));
        assertThat(kafkaCaptor.getValue(), is(notNullValue()));
        assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
        KafkaStatus status = kafkaCaptor.getValue().getStatus();
        assertThat(status.getListeners().size(), is(1));
        assertThat(status.getListeners().get(0).getType(), is("plain"));
        assertThat(status.getListeners().get(0).getName(), is("plain"));
        assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("my-service.my-namespace.svc"));
        assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(Integer.valueOf(9092)));
        assertThat(status.getListeners().get(0).getBootstrapServers(), is("my-service.my-namespace.svc:9092"));
        assertThat(status.getConditions().size(), is(1));
        assertThat(status.getConditions().get(0).getType(), is("NotReady"));
        assertThat(status.getConditions().get(0).getStatus(), is("True"));
        assertThat(status.getConditions().get(0).getReason(), is("RuntimeException"));
        assertThat(status.getConditions().get(0).getMessage(), is("Something went wrong"));
        assertThat(status.getObservedGeneration(), is(2L));
        async.flag();
    });
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 9 with KafkaStatus

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

the class KafkaStatusTest method testStatusAfterFailedReconciliationWithPreviousFailure.

public void testStatusAfterFailedReconciliationWithPreviousFailure(VertxTestContext context, Throwable exception) throws ParseException {
    Kafka kafka = getKafkaCrd();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the Kafka Operator
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(getKafkaCrd()));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    MockFailingKafkaAssemblyOperator kao = new MockFailingKafkaAssemblyOperator(exception, vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
        assertThat(res.succeeded(), is(false));
        assertThat(kafkaCaptor.getValue(), is(notNullValue()));
        assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
        KafkaStatus status = kafkaCaptor.getValue().getStatus();
        assertThat(status.getListeners().size(), is(1));
        assertThat(status.getListeners().get(0).getType(), is("plain"));
        assertThat(status.getListeners().get(0).getName(), is("plain"));
        assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("my-service.my-namespace.svc"));
        assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(Integer.valueOf(9092)));
        assertThat(status.getListeners().get(0).getBootstrapServers(), is("my-service.my-namespace.svc:9092"));
        assertThat(status.getConditions().size(), is(1));
        assertThat(status.getConditions().get(0).getType(), is("NotReady"));
        assertThat(status.getConditions().get(0).getStatus(), is("True"));
        assertThat(status.getConditions().get(0).getReason(), is(exception.getClass().getSimpleName()));
        assertThat(status.getConditions().get(0).getMessage(), is(exception.getMessage()));
        assertThat(status.getObservedGeneration(), is(2L));
        async.flag();
    });
}
Also used : ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus)

Example 10 with KafkaStatus

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

the class CruiseControlST method testCruiseControlWithSingleNodeKafka.

@ParallelNamespaceTest
void testCruiseControlWithSingleNodeKafka(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String errMessage = "Kafka " + namespaceName + "/" + clusterName + " has invalid configuration." + " Cruise Control cannot be deployed with a single-node Kafka cluster. It requires " + "at least two Kafka nodes.";
    LOGGER.info("Deploying single node Kafka with CruiseControl");
    resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaWithCruiseControl(clusterName, 1, 1).build());
    KafkaUtils.waitUntilKafkaStatusConditionContainsMessage(clusterName, namespaceName, errMessage, Duration.ofMinutes(6).toMillis());
    KafkaStatus kafkaStatus = KafkaTemplates.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    assertThat(kafkaStatus.getConditions().get(0).getReason(), is("InvalidResourceException"));
    LOGGER.info("Increasing Kafka nodes to 3");
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> kafka.getSpec().getKafka().setReplicas(3), namespaceName);
    KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
    kafkaStatus = KafkaTemplates.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    assertThat(kafkaStatus.getConditions().get(0).getMessage(), is(not(errMessage)));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Aggregations

KafkaStatus (io.strimzi.api.kafka.model.status.KafkaStatus)38 Kafka (io.strimzi.api.kafka.model.Kafka)28 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)28 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)28 Reconciliation (io.strimzi.operator.common.Reconciliation)28 CrdOperator (io.strimzi.operator.common.operator.resource.CrdOperator)28 Checkpoint (io.vertx.junit5.Checkpoint)26 Test (org.junit.jupiter.api.Test)22 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)20 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)18 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)16 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)16 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)16 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)16 ListenerAddressBuilder (io.strimzi.api.kafka.model.status.ListenerAddressBuilder)16 StatefulSetOperator (io.strimzi.operator.cluster.operator.resource.StatefulSetOperator)16 MetricsAndLogging (io.strimzi.operator.common.MetricsAndLogging)16 Labels (io.strimzi.operator.common.model.Labels)16 ConfigMapOperator (io.strimzi.operator.common.operator.resource.ConfigMapOperator)16 NodeOperator (io.strimzi.operator.common.operator.resource.NodeOperator)16