Search in sources :

Example 76 with PlatformFeaturesAvailability

use of io.strimzi.operator.PlatformFeaturesAvailability in project strimzi-kafka-operator by strimzi.

the class KafkaMirrorMakerAssemblyOperatorTest method testReconcile.

@Test
public void testReconcile(VertxTestContext context) {
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    CrdOperator mockMirrorOps = supplier.mirrorMakerOperator;
    DeploymentOperator mockDcOps = supplier.deploymentOperations;
    SecretOperator mockSecretOps = supplier.secretOperations;
    String kmmNamespace = "test";
    KafkaMirrorMakerConsumerSpec consumer = new KafkaMirrorMakerConsumerSpecBuilder().withBootstrapServers(consumerBootstrapServers).withGroupId(groupId).withNumStreams(numStreams).build();
    KafkaMirrorMakerProducerSpec producer = new KafkaMirrorMakerProducerSpecBuilder().withBootstrapServers(producerBootstrapServers).build();
    Map<String, Object> metricsCm = new HashMap<>();
    metricsCm.put("foo", "bar");
    KafkaMirrorMaker foo = ResourceUtils.createKafkaMirrorMaker(kmmNamespace, "foo", image, producer, consumer, include);
    KafkaMirrorMaker bar = ResourceUtils.createKafkaMirrorMaker(kmmNamespace, "bar", image, producer, consumer, include);
    when(mockMirrorOps.listAsync(eq(kmmNamespace), any(Optional.class))).thenReturn(Future.succeededFuture(asList(foo, bar)));
    // when requested ConfigMap for a specific Kafka Mirror Maker cluster
    when(mockMirrorOps.get(eq(kmmNamespace), eq("foo"))).thenReturn(foo);
    when(mockMirrorOps.get(eq(kmmNamespace), eq("bar"))).thenReturn(bar);
    when(mockMirrorOps.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture());
    // providing the list of ALL Deployments for all the Kafka Mirror Maker clusters
    Labels newLabels = Labels.forStrimziKind(KafkaMirrorMaker.RESOURCE_KIND);
    when(mockDcOps.list(eq(kmmNamespace), eq(newLabels))).thenReturn(asList(KafkaMirrorMakerCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateDeployment(new HashMap<String, String>(), true, null, null)));
    // providing the list Deployments for already "existing" Kafka Mirror Maker clusters
    Labels barLabels = Labels.forStrimziCluster("bar");
    when(mockDcOps.list(eq(kmmNamespace), eq(barLabels))).thenReturn(asList(KafkaMirrorMakerCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateDeployment(new HashMap<String, String>(), true, null, null)));
    when(mockDcOps.readiness(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(mockDcOps.waitForObserved(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(mockSecretOps.reconcile(any(), eq(kmmNamespace), any(), any())).thenReturn(Future.succeededFuture());
    Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
    Checkpoint createdOrUpdateAsync = context.checkpoint(2);
    KafkaMirrorMakerAssemblyOperator ops = new KafkaMirrorMakerAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS)) {

        @Override
        public Future<KafkaMirrorMakerStatus> createOrUpdate(Reconciliation reconciliation, KafkaMirrorMaker kafkaMirrorMakerAssembly) {
            createdOrUpdated.add(kafkaMirrorMakerAssembly.getMetadata().getName());
            createdOrUpdateAsync.flag();
            return Future.succeededFuture();
        }
    };
    Checkpoint async = context.checkpoint();
    // Now try to reconcile all the Kafka Mirror Maker clusters
    ops.reconcileAll("test", kmmNamespace, context.succeeding(v -> context.verify(() -> {
        assertThat(createdOrUpdated, is(new HashSet(asList("foo", "bar"))));
        async.flag();
    })));
}
Also used : KafkaMirrorMakerProducerSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerProducerSpecBuilder) CoreMatchers.is(org.hamcrest.CoreMatchers.is) KafkaMirrorMakerResources(io.strimzi.api.kafka.model.KafkaMirrorMakerResources) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Annotations(io.strimzi.operator.common.Annotations) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) VertxExtension(io.vertx.junit5.VertxExtension) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) KafkaMirrorMakerConsumerSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerConsumerSpecBuilder) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) KafkaMirrorMakerStatus(io.strimzi.api.kafka.model.status.KafkaMirrorMakerStatus) PodDisruptionBudgetOperator(io.strimzi.operator.common.operator.resource.PodDisruptionBudgetOperator) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) KafkaMirrorMakerConsumerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerConsumerSpec) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) KafkaMirrorMakerProducerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerProducerSpec) TestUtils(io.strimzi.test.TestUtils) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Mockito.verify(org.mockito.Mockito.verify) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito.never(org.mockito.Mockito.never) KafkaMirrorMakerCluster(io.strimzi.operator.cluster.model.KafkaMirrorMakerCluster) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaMirrorMakerStatus(io.strimzi.api.kafka.model.status.KafkaMirrorMakerStatus) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) KafkaMirrorMakerProducerSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerProducerSpecBuilder) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) KafkaMirrorMakerProducerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerProducerSpec) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) HashSet(java.util.HashSet) KafkaMirrorMakerConsumerSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerConsumerSpecBuilder) Optional(java.util.Optional) KafkaMirrorMakerConsumerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerConsumerSpec) Labels(io.strimzi.operator.common.model.Labels) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Checkpoint(io.vertx.junit5.Checkpoint) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Test(org.junit.jupiter.api.Test)

Example 77 with PlatformFeaturesAvailability

use of io.strimzi.operator.PlatformFeaturesAvailability in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceStateMachineTest method checkTransition.

/**
 *  Checks the expected transition between two states of the Kafka Rebalance operator.
 *
 * @param vertx The vertx test instance.
 * @param context The test context instance.
 * @param currentState The current state of the resource before being passed to computeNextStatus.
 * @param nextState The expected state of the resouce after computeNextStatus has been called.
 * @param initialAnnotation The initial annotation attached to the Kafka Rebalance resource. For example none or refresh.
 * @param kcRebalance The Kafka Rebalance instance that will be returned by the resourceSupplier.
 * @return A future for the {@link KafkaRebalanceStatus} returned by the {@link KafkaRebalanceAssemblyOperator#computeNextStatus} method
 */
private Future<KafkaRebalanceStatus> checkTransition(Vertx vertx, VertxTestContext context, KafkaRebalanceState currentState, KafkaRebalanceState nextState, KafkaRebalanceAnnotation initialAnnotation, KafkaRebalance kcRebalance) {
    CruiseControlApi client = new CruiseControlApiImpl(vertx, HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS, MockCruiseControl.CC_SECRET, MockCruiseControl.CC_API_SECRET, true, true);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, kubernetesVersion);
    KafkaRebalanceAssemblyOperator kcrao = new KafkaRebalanceAssemblyOperator(vertx, pfa, supplier, ResourceUtils.dummyClusterOperatorConfig()) {

        @Override
        public String cruiseControlHost(String clusterName, String clusterNamespace) {
            return HOST;
        }
    };
    Reconciliation recon = new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME);
    RebalanceOptions.RebalanceOptionsBuilder rbOptions = new RebalanceOptions.RebalanceOptionsBuilder();
    if (kcRebalance.getSpec() != null) {
        if (kcRebalance.getSpec().getGoals() != null) {
            rbOptions.withGoals(kcRebalance.getSpec().getGoals());
        }
        if (kcRebalance.getSpec().isSkipHardGoalCheck()) {
            rbOptions.withSkipHardGoalCheck();
        }
    }
    CrdOperator<KubernetesClient, KafkaRebalance, KafkaRebalanceList> mockRebalanceOps = supplier.kafkaRebalanceOperator;
    when(mockCmOps.getAsync(CLUSTER_NAMESPACE, RESOURCE_NAME)).thenReturn(Future.succeededFuture(new ConfigMap()));
    when(mockRebalanceOps.get(CLUSTER_NAMESPACE, RESOURCE_NAME)).thenReturn(kcRebalance);
    when(mockRebalanceOps.getAsync(CLUSTER_NAMESPACE, RESOURCE_NAME)).thenReturn(Future.succeededFuture(kcRebalance));
    return kcrao.computeNextStatus(recon, HOST, client, kcRebalance, currentState, initialAnnotation, rbOptions).compose(result -> {
        context.verify(() -> {
            assertThat(result.getStatus().getConditions(), StateMatchers.hasStateInConditions(nextState));
        });
        return Future.succeededFuture(result.getStatus());
    });
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance)

Example 78 with PlatformFeaturesAvailability

use of io.strimzi.operator.PlatformFeaturesAvailability in project strimzi-kafka-operator by strimzi.

the class KafkaStatusTest method testInitialStatusOnOldResource.

@Test
public void testInitialStatusOnOldResource() 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(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());
    MockInitialStatusKafkaAssemblyOperator kao = new MockInitialStatusKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        assertThat(kafkaCaptor.getAllValues().size(), is(1));
    });
}
Also used : ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) 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) Test(org.junit.jupiter.api.Test)

Example 79 with PlatformFeaturesAvailability

use of io.strimzi.operator.PlatformFeaturesAvailability in project strimzi-kafka-operator 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 80 with PlatformFeaturesAvailability

use of io.strimzi.operator.PlatformFeaturesAvailability in project strimzi-kafka-operator 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)

Aggregations

PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)246 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)242 Reconciliation (io.strimzi.operator.common.Reconciliation)232 Test (org.junit.jupiter.api.Test)222 Checkpoint (io.vertx.junit5.Checkpoint)210 KubernetesVersion (io.strimzi.operator.KubernetesVersion)204 Vertx (io.vertx.core.Vertx)204 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)204 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)204 Mockito.when (org.mockito.Mockito.when)204 Future (io.vertx.core.Future)200 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)198 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)198 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)198 AfterAll (org.junit.jupiter.api.AfterAll)196 BeforeAll (org.junit.jupiter.api.BeforeAll)196 VertxExtension (io.vertx.junit5.VertxExtension)192 VertxTestContext (io.vertx.junit5.VertxTestContext)192 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)192 CoreMatchers.is (org.hamcrest.CoreMatchers.is)190