Search in sources :

Example 6 with ListenerStatus

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

the class KafkaAssemblyOperatorLoadBalancerKafkaListenerTest method testLoadBalancerWithBootstrapService.

@Test
public void testLoadBalancerWithBootstrapService(VertxTestContext context) {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(LISTENER_PORT).withTls(true).withType(KafkaListenerType.LOADBALANCER).withNewConfiguration().withCreateBootstrapService(true).endConfiguration().build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
    ResourceOperatorSupplier supplier = prepareResourceOperatorSupplier(kafka);
    KafkaAssemblyOperator op = new MockKafkaAssemblyOperatorForLoadBalancerTests(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), certManager, passwordGenerator, supplier, ResourceUtils.dummyClusterOperatorConfig(KafkaVersionTestUtils.getKafkaVersionLookup()));
    Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
    Checkpoint async = context.checkpoint();
    op.reconcile(reconciliation).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(kafka.getStatus().getListeners().size(), is(1));
        ListenerStatus listenerStatus = kafka.getStatus().getListeners().get(0);
        assertThat(listenerStatus.getBootstrapServers(), is("bootstrap-broker.test.dns.name:9094"));
        assertThat(listenerStatus.getAddresses().size(), is(1));
        assertThat(listenerStatus.getAddresses().get(0).getHost(), is(DNS_NAME_FOR_BOOTSTRAP_SERVICE));
        assertThat(listenerStatus.getAddresses().get(0).getPort(), is(LISTENER_PORT));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CertManager(io.strimzi.certs.CertManager) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) AfterAll(org.junit.jupiter.api.AfterAll) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Service(io.fabric8.kubernetes.api.model.Service) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) Collections.emptyList(java.util.Collections.emptyList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) Kafka(io.strimzi.api.kafka.model.Kafka) OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with ListenerStatus

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

the class KafkaAssemblyOperatorLoadBalancerKafkaListenerTest method testLoadBalancer.

@Test
public void testLoadBalancer(VertxTestContext context) {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(LISTENER_PORT).withTls(true).withType(KafkaListenerType.LOADBALANCER).build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
    ResourceOperatorSupplier supplier = prepareResourceOperatorSupplier(kafka);
    KafkaAssemblyOperator op = new MockKafkaAssemblyOperatorForLoadBalancerTests(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), certManager, passwordGenerator, supplier, ResourceUtils.dummyClusterOperatorConfig(KafkaVersionTestUtils.getKafkaVersionLookup()));
    Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
    Checkpoint async = context.checkpoint();
    op.reconcile(reconciliation).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(kafka.getStatus().getListeners().size(), is(1));
        ListenerStatus listenerStatus = kafka.getStatus().getListeners().get(0);
        assertThat(listenerStatus.getBootstrapServers(), is("bootstrap-broker.test.dns.name:9094"));
        assertThat(listenerStatus.getAddresses().size(), is(1));
        assertThat(listenerStatus.getAddresses().get(0).getHost(), is(DNS_NAME_FOR_BOOTSTRAP_SERVICE));
        assertThat(listenerStatus.getAddresses().get(0).getPort(), is(LISTENER_PORT));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CertManager(io.strimzi.certs.CertManager) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) AfterAll(org.junit.jupiter.api.AfterAll) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Service(io.fabric8.kubernetes.api.model.Service) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) Collections.emptyList(java.util.Collections.emptyList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) Kafka(io.strimzi.api.kafka.model.Kafka) OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with ListenerStatus

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

the class StatusDiffTest method testTimestampDiff.

@ParallelTest
public void testTimestampDiff() throws ParseException {
    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();
    Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
    Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2011-01-01 00:00:00"))).withType("Ready").withStatus("True").build();
    KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
    KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition2).withListeners(ls1, ls2).build();
    StatusDiff diff = new StatusDiff(status1, status2);
    assertThat(diff.isEmpty(), is(true));
}
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) SimpleDateFormat(java.text.SimpleDateFormat) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Date(java.util.Date) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 9 with ListenerStatus

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

the class CustomResourceStatusIsolatedST method assertKafkaStatus.

void assertKafkaStatus(long expectedObservedGeneration, String internalAddress) {
    KafkaStatus kafkaStatus = KafkaResource.kafkaClient().inNamespace(Constants.INFRA_NAMESPACE).withName(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME).get().getStatus();
    assertThat("Kafka cluster status has incorrect Observed Generation", kafkaStatus.getObservedGeneration(), is(expectedObservedGeneration));
    for (ListenerStatus listener : kafkaStatus.getListeners()) {
        switch(listener.getType()) {
            case Constants.TLS_LISTENER_DEFAULT_NAME:
                assertThat("TLS bootstrap has incorrect port", listener.getAddresses().get(0).getPort(), is(9093));
                assertThat("TLS bootstrap has incorrect host", listener.getAddresses().get(0).getHost(), is(internalAddress));
                break;
            case Constants.PLAIN_LISTENER_DEFAULT_NAME:
                assertThat("Plain bootstrap has incorrect port", listener.getAddresses().get(0).getPort(), is(9092));
                assertThat("Plain bootstrap has incorrect host", listener.getAddresses().get(0).getHost(), is(internalAddress));
                break;
            case Constants.EXTERNAL_LISTENER_DEFAULT_NAME:
                Service extBootstrapService = kubeClient(Constants.INFRA_NAMESPACE).getClient().services().inNamespace(Constants.INFRA_NAMESPACE).withName(externalBootstrapServiceName(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME)).get();
                assertThat("External bootstrap has incorrect port", listener.getAddresses().get(0).getPort(), is(extBootstrapService.getSpec().getPorts().get(0).getNodePort()));
                assertThat("External bootstrap has incorrect host", listener.getAddresses().get(0).getHost() != null);
                break;
        }
    }
}
Also used : ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Service(io.fabric8.kubernetes.api.model.Service) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus)

Example 10 with ListenerStatus

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

the class ListenersST method testNodePort.

@ParallelNamespaceTest
@Tag(NODEPORT_SUPPORTED)
@Tag(EXTERNAL_CLIENTS_USED)
void testNodePort(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
    final Map<String, String> label = Collections.singletonMap("my-label", "value");
    final Map<String, String> anno = Collections.singletonMap("my-annotation", "value");
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 1).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9097).withTls(true).build(), new GenericKafkaListenerBuilder().withType(KafkaListenerType.NODEPORT).withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9098).withTls(false).build()).withConfig(Collections.singletonMap("default.replication.factor", 3)).editOrNewTemplate().withNewClusterRoleBinding().withNewMetadata().withAnnotations(anno).withLabels(label).endMetadata().endClusterRoleBinding().endTemplate().endKafka().endSpec().build());
    ExternalKafkaClient externalKafkaClient = new ExternalKafkaClient.Builder().withTopicName(topicName).withNamespaceName(namespaceName).withClusterName(clusterName).withMessageCount(MESSAGE_COUNT).withListenerName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).build();
    externalKafkaClient.verifyProducedAndConsumedMessages(externalKafkaClient.sendMessagesPlain(), externalKafkaClient.receiveMessagesPlain());
    // Check that Kafka status has correct addresses in NodePort external listener part
    for (ListenerStatus listenerStatus : KafkaResource.getKafkaStatus(clusterName, namespaceName).getListeners()) {
        if (listenerStatus.getType().equals(Constants.EXTERNAL_LISTENER_DEFAULT_NAME)) {
            List<String> listStatusAddresses = listenerStatus.getAddresses().stream().map(ListenerAddress::getHost).collect(Collectors.toList());
            listStatusAddresses.sort(Comparator.comparing(String::toString));
            List<Integer> listStatusPorts = listenerStatus.getAddresses().stream().map(ListenerAddress::getPort).collect(Collectors.toList());
            Integer nodePort = kubeClient(namespaceName).getService(namespaceName, KafkaResources.externalBootstrapServiceName(clusterName)).getSpec().getPorts().get(0).getNodePort();
            List<String> nodeIps = kubeClient(namespaceName).listPods(KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName))).stream().map(pods -> pods.getStatus().getHostIP()).distinct().collect(Collectors.toList());
            nodeIps.sort(Comparator.comparing(String::toString));
            assertThat(listStatusAddresses, is(nodeIps));
            for (Integer port : listStatusPorts) {
                assertThat(port, is(nodePort));
            }
        }
    }
    // check the ClusterRoleBinding annotations and labels in Kafka cluster
    Map<String, String> actualLabel = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getSpec().getKafka().getTemplate().getClusterRoleBinding().getMetadata().getLabels();
    Map<String, String> actualAnno = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getSpec().getKafka().getTemplate().getClusterRoleBinding().getMetadata().getAnnotations();
    assertThat(actualLabel, is(label));
    assertThat(actualAnno, is(anno));
}
Also used : ExternalKafkaClient(io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Aggregations

ListenerStatus (io.strimzi.api.kafka.model.status.ListenerStatus)19 Service (io.fabric8.kubernetes.api.model.Service)10 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)10 KafkaListenerType (io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType)8 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)6 Kafka (io.strimzi.api.kafka.model.Kafka)6 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)6 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)6 CertManager (io.strimzi.certs.CertManager)6 OpenSslCertManager (io.strimzi.certs.OpenSslCertManager)6 KubernetesVersion (io.strimzi.operator.KubernetesVersion)6 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)6 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)6 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)6 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)6 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)6 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)6 StatefulSetOperator (io.strimzi.operator.cluster.operator.resource.StatefulSetOperator)6 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)6