Search in sources :

Example 1 with KafkaStatus

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

the class StatusDiffTest method testStatusDiff.

@ParallelTest
public void testStatusDiff() {
    ListenerStatus ls1 = new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build();
    ListenerStatus ls2 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9093).build()).build();
    ListenerStatus ls3 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9094).build()).build();
    Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
    Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready2").withStatus("True").build();
    KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
    KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
    KafkaStatus status3 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
    KafkaStatus status4 = new KafkaStatusBuilder().withConditions(condition1, condition2).withListeners(ls1).build();
    KafkaStatus status5 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls3).build();
    KafkaStatus status6 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls3, ls1).build();
    StatusDiff diff = new StatusDiff(status1, status2);
    assertThat(diff.isEmpty(), is(true));
    diff = new StatusDiff(status1, status3);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status1, status4);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status3, status4);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status3, status5);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status5, status6);
    assertThat(diff.isEmpty(), is(false));
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) KafkaStatusBuilder(io.strimzi.api.kafka.model.status.KafkaStatusBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Date(java.util.Date) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 2 with KafkaStatus

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

the class KafkaStatusTest method testKafkaListenerNodePortAddressInStatusWithOverrides.

@Test
public void testKafkaListenerNodePortAddressInStatusWithOverrides(VertxTestContext context) throws ParseException {
    GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("my-address-0").build();
    GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("my-address-1").build();
    Kafka kafka = new KafkaBuilder(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(broker0, broker1).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    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());
    // Mock the KafkaSetOperator
    StatefulSetOperator mockStsOps = supplier.stsOperations;
    when(mockStsOps.getAsync(eq(namespace), eq(KafkaCluster.kafkaClusterName(clusterName)))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
    // Mock the StrimziPodSet operator
    CrdOperator<KubernetesClient, StrimziPodSet, StrimziPodSetList> mockPodSetOps = supplier.strimziPodSetOperator;
    when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    // Mock the ConfigMapOperator
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    when(mockCmOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafkaCluster.generateMetricsAndLogConfigMap(new MetricsAndLogging(null, null))));
    // Mock Pods Operator
    Pod pod0 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
    Pod pod1 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
    List<Pod> pods = new ArrayList<>();
    pods.add(pod0);
    pods.add(pod1);
    pods.add(pod2);
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(eq(namespace), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
    // Mock Node operator
    NodeOperator mockNodeOps = supplier.nodeOperator;
    when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(getClusterNodes()));
    MockNodePortStatusKafkaAssemblyOperator kao = new MockNodePortStatusKafkaAssemblyOperator(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(1));
        assertThat(status.getListeners().get(0).getType(), is("external"));
        assertThat(status.getListeners().get(0).getName(), is("external"));
        List<ListenerAddress> addresses = status.getListeners().get(0).getAddresses();
        assertThat(addresses.size(), is(3));
        List<ListenerAddress> expected = new ArrayList<>();
        expected.add(new ListenerAddressBuilder().withHost("my-address-0").withPort(31234).build());
        expected.add(new ListenerAddressBuilder().withHost("my-address-1").withPort(31234).build());
        expected.add(new ListenerAddressBuilder().withHost("5.124.16.8").withPort(31234).build());
        async.flag();
    });
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) Kafka(io.strimzi.api.kafka.model.Kafka) ArrayList(java.util.ArrayList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ListenerAddress(io.strimzi.api.kafka.model.status.ListenerAddress) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeOperator(io.strimzi.operator.common.operator.resource.NodeOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Labels(io.strimzi.operator.common.model.Labels) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 3 with KafkaStatus

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

the class KafkaStatusTest method testKafkaListenerNodePortAddressInStatus.

@Test
public void testKafkaListenerNodePortAddressInStatus(VertxTestContext context) throws ParseException {
    Kafka kafka = new KafkaBuilder(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).build()).endKafka().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    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());
    // Mock the KafkaSetOperator
    StatefulSetOperator mockStsOps = supplier.stsOperations;
    when(mockStsOps.getAsync(eq(namespace), eq(KafkaCluster.kafkaClusterName(clusterName)))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
    // Mock the StrimziPodSet operator
    CrdOperator<KubernetesClient, StrimziPodSet, StrimziPodSetList> mockPodSetOps = supplier.strimziPodSetOperator;
    when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    // Mock the ConfigMapOperator
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    when(mockCmOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafkaCluster.generateMetricsAndLogConfigMap(new MetricsAndLogging(null, null))));
    // Mock Pods Operator
    Pod pod0 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
    Pod pod1 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
    List<Pod> pods = new ArrayList<>();
    pods.add(pod0);
    pods.add(pod1);
    pods.add(pod2);
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(eq(namespace), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
    // Mock Node operator
    NodeOperator mockNodeOps = supplier.nodeOperator;
    when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(getClusterNodes()));
    MockNodePortStatusKafkaAssemblyOperator kao = new MockNodePortStatusKafkaAssemblyOperator(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(1));
        assertThat(status.getListeners().get(0).getType(), is("external"));
        assertThat(status.getListeners().get(0).getName(), is("external"));
        List<ListenerAddress> addresses = status.getListeners().get(0).getAddresses();
        assertThat(addresses.size(), is(3));
        List<ListenerAddress> expected = new ArrayList<>();
        expected.add(new ListenerAddressBuilder().withHost("50.35.18.119").withPort(31234).build());
        expected.add(new ListenerAddressBuilder().withHost("55.36.78.115").withPort(31234).build());
        expected.add(new ListenerAddressBuilder().withHost("5.124.16.8").withPort(31234).build());
        async.flag();
    });
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) Kafka(io.strimzi.api.kafka.model.Kafka) ArrayList(java.util.ArrayList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ListenerAddress(io.strimzi.api.kafka.model.status.ListenerAddress) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeOperator(io.strimzi.operator.common.operator.resource.NodeOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Labels(io.strimzi.operator.common.model.Labels) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 4 with KafkaStatus

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

the class KafkaStatusTest method testKafkaListenerNodePortAddressSameNode.

@Test
public void testKafkaListenerNodePortAddressSameNode(VertxTestContext context) throws ParseException {
    Kafka kafka = new KafkaBuilder(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).build()).endKafka().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    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());
    // Mock the KafkaSetOperator
    StatefulSetOperator mockStsOps = supplier.stsOperations;
    when(mockStsOps.getAsync(eq(namespace), eq(KafkaCluster.kafkaClusterName(clusterName)))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
    // Mock the StrimziPodSet operator
    CrdOperator<KubernetesClient, StrimziPodSet, StrimziPodSetList> mockPodSetOps = supplier.strimziPodSetOperator;
    when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    // Mock the ConfigMapOperator
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    when(mockCmOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafkaCluster.generateMetricsAndLogConfigMap(new MetricsAndLogging(null, null))));
    // Mock Pods Operator
    Pod pod0 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
    Pod pod1 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
    List<Pod> pods = new ArrayList<>();
    pods.add(pod0);
    pods.add(pod1);
    pods.add(pod2);
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(eq(namespace), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
    // Mock Node operator
    NodeOperator mockNodeOps = supplier.nodeOperator;
    when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(getClusterNodes()));
    MockNodePortStatusKafkaAssemblyOperator kao = new MockNodePortStatusKafkaAssemblyOperator(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(1));
        assertThat(status.getListeners().get(0).getType(), is("external"));
        assertThat(status.getListeners().get(0).getName(), is("external"));
        List<ListenerAddress> addresses = status.getListeners().get(0).getAddresses();
        assertThat(addresses.size(), is(1));
        List<ListenerAddress> expected = new ArrayList<>();
        expected.add(new ListenerAddressBuilder().withHost("50.35.18.119").withPort(31234).build());
        async.flag();
    });
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) Kafka(io.strimzi.api.kafka.model.Kafka) ArrayList(java.util.ArrayList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ListenerAddress(io.strimzi.api.kafka.model.status.ListenerAddress) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeOperator(io.strimzi.operator.common.operator.resource.NodeOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Labels(io.strimzi.operator.common.model.Labels) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 5 with KafkaStatus

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

the class KafkaStatusTest method testKafkaClusterIdInStatus.

@Test
public void testKafkaClusterIdInStatus(VertxTestContext context) throws ParseException {
    Kafka kafka = new KafkaBuilder(getKafkaCrd()).build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    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());
    // Mock the KafkaSecretOperator
    SecretOperator mockSecretOps = supplier.secretOperations;
    Secret secret = new Secret();
    when(mockSecretOps.getAsync(eq(namespace), eq(KafkaResources.clusterCaCertificateSecretName(clusterName)))).thenReturn(Future.succeededFuture(secret));
    when(mockSecretOps.getAsync(eq(namespace), eq(ClusterOperator.secretName(clusterName)))).thenReturn(Future.succeededFuture(secret));
    MockClusterIdStatusKafkaAssemblyOperator kao = new MockClusterIdStatusKafkaAssemblyOperator(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.getClusterId(), is(notNullValue()));
        async.flag();
    });
}
Also used : KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Secret(io.fabric8.kubernetes.api.model.Secret) 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) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

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