Search in sources :

Example 1 with GenericKafkaListenerConfigurationBroker

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker 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 2 with GenericKafkaListenerConfigurationBroker

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.

the class ListenersST method testAdvertisedHostNamesAppearsInBrokerCerts.

@Tag(NODEPORT_SUPPORTED)
@ParallelNamespaceTest
void testAdvertisedHostNamesAppearsInBrokerCerts(ExtensionContext extensionContext) throws CertificateException {
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String advertHostInternal0 = "kafka-test.internal.0.net";
    final String advertHostInternal1 = "kafka-test.internal.1.net";
    final String advertHostInternal2 = "kafka-test.internal.2.net";
    List<String> advertHostInternalList = asList(advertHostInternal0, advertHostInternal1, advertHostInternal2);
    final int advertPortInternalListener = 9999;
    final String advertHostExternal0 = "kafka-test.external.0.net";
    final String advertHostExternal1 = "kafka-test.external.1.net";
    final String advertHostExternal2 = "kafka-test.external.2.net";
    List<String> advertHostExternalList = asList(advertHostExternal0, advertHostExternal1, advertHostExternal2);
    final int advertPortExternalListener = 9888;
    GenericKafkaListenerConfigurationBroker brokerInternal0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost(advertHostInternal0).withAdvertisedPort(advertPortInternalListener).build();
    GenericKafkaListenerConfigurationBroker brokerInternal1 = new GenericKafkaListenerConfigurationBrokerBuilder(brokerInternal0).withBroker(1).withAdvertisedHost(advertHostInternal1).build();
    GenericKafkaListenerConfigurationBroker brokerInternal2 = new GenericKafkaListenerConfigurationBrokerBuilder(brokerInternal0).withBroker(2).withAdvertisedHost(advertHostInternal2).build();
    GenericKafkaListenerConfigurationBroker brokerExternal0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost(advertHostExternal0).withAdvertisedPort(advertPortExternalListener).build();
    GenericKafkaListenerConfigurationBroker brokerExternal1 = new GenericKafkaListenerConfigurationBrokerBuilder(brokerExternal0).withBroker(1).withAdvertisedHost(advertHostExternal1).build();
    GenericKafkaListenerConfigurationBroker brokerExternal2 = new GenericKafkaListenerConfigurationBrokerBuilder(brokerExternal0).withBroker(2).withAdvertisedHost(advertHostExternal2).build();
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 3).editSpec().editKafka().withListeners(asList(new GenericKafkaListenerBuilder().withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9098).withType(KafkaListenerType.INTERNAL).withTls(true).withNewConfiguration().withBrokers(asList(brokerInternal0, brokerInternal1, brokerInternal2)).endConfiguration().build(), new GenericKafkaListenerBuilder().withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9099).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(asList(brokerExternal0, brokerExternal1, brokerExternal2)).endConfiguration().build())).endKafka().endSpec().build());
    Map<String, String> secretData = kubeClient().getSecret(namespaceName, KafkaResources.brokersServiceName(clusterName)).getData();
    List<String> kafkaPods = kubeClient().listPodNamesInSpecificNamespace(namespaceName, Labels.STRIMZI_KIND_LABEL, Kafka.RESOURCE_KIND).stream().filter(podName -> podName.contains("kafka")).collect(Collectors.toList());
    int index = 0;
    for (String kafkaBroker : kafkaPods) {
        String cert = secretData.get(kafkaBroker + ".crt");
        LOGGER.info("Encoding {}.crt", kafkaBroker);
        ByteArrayInputStream publicCert = new ByteArrayInputStream(Base64.getDecoder().decode(cert.getBytes()));
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        Certificate certificate = certificateFactory.generateCertificate(publicCert);
        assertThat(certificate.toString(), containsString(advertHostInternalList.get(index)));
        assertThat(certificate.toString(), containsString(advertHostExternalList.get(index++)));
    }
}
Also used : ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) CoreMatchers.is(org.hamcrest.CoreMatchers.is) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) CertificateFactory(java.security.cert.CertificateFactory) KafkaResource(io.strimzi.systemtest.resources.crd.KafkaResource) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) KafkaTopicUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaTopicUtils) INFRA_NAMESPACE(io.strimzi.systemtest.Constants.INFRA_NAMESPACE) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) KafkaUtils.getKafkaSecretCertificates(io.strimzi.systemtest.utils.kafkaUtils.KafkaUtils.getKafkaSecretCertificates) KafkaListenerAuthenticationTls(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationTls) Matcher(java.util.regex.Matcher) SystemTestCertAndKey(io.strimzi.systemtest.security.SystemTestCertAndKey) ByteArrayInputStream(java.io.ByteArrayInputStream) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) ServiceUtils(io.strimzi.systemtest.utils.kubeUtils.objects.ServiceUtils) StUtils(io.strimzi.systemtest.utils.StUtils) RollingUpdateUtils(io.strimzi.systemtest.utils.RollingUpdateUtils) ACCEPTANCE(io.strimzi.systemtest.Constants.ACCEPTANCE) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ListenerAddress(io.strimzi.api.kafka.model.status.ListenerAddress) INTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.INTERNAL_CLIENTS_USED) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) SystemTestCertManager.generateRootCaCertAndKey(io.strimzi.systemtest.security.SystemTestCertManager.generateRootCaCertAndKey) CertAndKeyFiles(io.strimzi.systemtest.security.CertAndKeyFiles) Collectors(java.util.stream.Collectors) ClientUtils(io.strimzi.systemtest.utils.ClientUtils) StandardCharsets(java.nio.charset.StandardCharsets) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Base64(java.util.Base64) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) Certificate(java.security.cert.Certificate) KafkaUtils.getKafkaStatusCertificates(io.strimzi.systemtest.utils.kafkaUtils.KafkaUtils.getKafkaStatusCertificates) KafkaTopicTemplates(io.strimzi.systemtest.templates.crd.KafkaTopicTemplates) Secret(io.fabric8.kubernetes.api.model.Secret) Pattern(java.util.regex.Pattern) AbstractST(io.strimzi.systemtest.AbstractST) KafkaClientsTemplates(io.strimzi.systemtest.templates.crd.KafkaClientsTemplates) LOADBALANCER_SUPPORTED(io.strimzi.systemtest.Constants.LOADBALANCER_SUPPORTED) ParallelSuite(io.strimzi.systemtest.annotations.ParallelSuite) OpenShiftOnly(io.strimzi.systemtest.annotations.OpenShiftOnly) ExternalKafkaClient(io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) SecretUtils(io.strimzi.systemtest.utils.kubeUtils.objects.SecretUtils) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) PodUtils(io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils) SystemTestCertManager.generateIntermediateCaCertAndKey(io.strimzi.systemtest.security.SystemTestCertManager.generateIntermediateCaCertAndKey) SystemTestCertManager.generateEndEntityCertAndKey(io.strimzi.systemtest.security.SystemTestCertManager.generateEndEntityCertAndKey) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NODEPORT_SUPPORTED(io.strimzi.systemtest.Constants.NODEPORT_SUPPORTED) KafkaTemplates(io.strimzi.systemtest.templates.crd.KafkaTemplates) KafkaUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaUtils) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Constants(io.strimzi.systemtest.Constants) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) EXTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.EXTERNAL_CLIENTS_USED) CertificateException(java.security.cert.CertificateException) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) JsonArray(io.vertx.core.json.JsonArray) AfterEach(org.junit.jupiter.api.AfterEach) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KafkaUserTemplates(io.strimzi.systemtest.templates.crd.KafkaUserTemplates) KafkaUserUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaUserUtils) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) REGRESSION(io.strimzi.systemtest.Constants.REGRESSION) SystemTestCertManager.exportToPemFiles(io.strimzi.systemtest.security.SystemTestCertManager.exportToPemFiles) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CertificateFactory(java.security.cert.CertificateFactory) Certificate(java.security.cert.Certificate) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 3 with GenericKafkaListenerConfigurationBroker

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.

the class ListenersValidator method validateIngress.

/**
 * Validates that Ingress type listener has the right host configurations
 *
 * @param errors    List where any found errors will be added
 * @param replicas  Number of Kafka replicas
 * @param listener  Listener which needs to be validated
 */
private static void validateIngress(Set<String> errors, int replicas, GenericKafkaListener listener) {
    if (listener.getConfiguration() != null) {
        GenericKafkaListenerConfiguration conf = listener.getConfiguration();
        if (conf.getBootstrap() == null || conf.getBootstrap().getHost() == null) {
            errors.add("listener " + listener.getName() + " is missing a bootstrap host name which is required for Ingress based listeners");
        }
        if (conf.getBrokers() != null) {
            for (int i = 0; i < replicas; i++) {
                final int id = i;
                GenericKafkaListenerConfigurationBroker broker = conf.getBrokers().stream().filter(b -> b.getBroker() == id).findFirst().orElse(null);
                if (broker == null || broker.getHost() == null) {
                    errors.add("listener " + listener.getName() + " is missing a broker host name for broker with ID " + i + " which is required for Ingress based listeners");
                }
            }
        } else {
            errors.add("listener " + listener.getName() + " is missing a broker configuration with host names which is required for Ingress based listeners");
        }
    } else {
        errors.add("listener " + listener.getName() + " is missing a configuration with host names which is required for Ingress based listeners");
    }
}
Also used : GenericKafkaListenerConfiguration(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfiguration) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker)

Example 4 with GenericKafkaListenerConfigurationBroker

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.

the class KafkaClusterTest method testExternalIngressClass.

@ParallelTest
public void testExternalIngressClass() {
    GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-0.com").withBroker(0).build();
    GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-1.com").withBroker(1).build();
    GenericKafkaListenerConfigurationBroker broker2 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-2.com").withBroker(2).build();
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.INGRESS).withTls(true).withNewConfiguration().withIngressClass("nginx-internal").withNewBootstrap().withHost("my-kafka-bootstrap.com").withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-bootstrap.com")).endBootstrap().withBrokers(broker0, broker1, broker2).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    // Check bootstrap ingress
    Ingress bing = kc.generateExternalBootstrapIngresses().get(0);
    assertThat(bing.getSpec().getIngressClassName(), is("nginx-internal"));
    io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress bingV1Beta1 = kc.generateExternalBootstrapIngressesV1Beta1().get(0);
    assertThat(bingV1Beta1.getSpec().getIngressClassName(), is("nginx-internal"));
    // Check per pod ingress
    for (int i = 0; i < replicas; i++) {
        Ingress ing = kc.generateExternalIngresses(i).get(0);
        assertThat(ing.getSpec().getIngressClassName(), is("nginx-internal"));
        io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingV1Beta1 = kc.generateExternalIngressesV1Beta1(i).get(0);
        assertThat(ingV1Beta1.getSpec().getIngressClassName(), is("nginx-internal"));
    }
}
Also used : GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 5 with GenericKafkaListenerConfigurationBroker

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.

the class KafkaClusterTest method testGetExternalAdvertisedUrlWithOverrides.

@ParallelTest
public void testGetExternalAdvertisedUrlWithOverrides() {
    GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig0 = new GenericKafkaListenerConfigurationBroker();
    nodePortListenerBrokerConfig0.setBroker(0);
    nodePortListenerBrokerConfig0.setAdvertisedHost("my-host-0.cz");
    nodePortListenerBrokerConfig0.setAdvertisedPort(10000);
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(nodePortListenerBrokerConfig0).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 0, "some-host.com"), is("EXTERNAL_9094_0://my-host-0.cz"));
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 0, ""), is("EXTERNAL_9094_0://my-host-0.cz"));
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 1, "some-host.com"), is("EXTERNAL_9094_1://some-host.com"));
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 1, ""), is("EXTERNAL_9094_1://"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 0, 12345), is("EXTERNAL_9094_0://10000"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 0, 12345), is("EXTERNAL_9094_0://10000"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 1, 12345), is("EXTERNAL_9094_1://12345"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 1, 12345), is("EXTERNAL_9094_1://12345"));
}
Also used : GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

GenericKafkaListenerConfigurationBroker (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker)38 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)34 Kafka (io.strimzi.api.kafka.model.Kafka)30 ParallelTest (io.strimzi.test.annotations.ParallelTest)30 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)28 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)20 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)10 GenericKafkaListenerConfigurationBootstrapBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder)7 Service (io.fabric8.kubernetes.api.model.Service)6 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)6 GenericKafkaListenerConfigurationBootstrap (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrap)5 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)4 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)4 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)4 Route (io.fabric8.openshift.api.model.Route)4 ListenerAddress (io.strimzi.api.kafka.model.status.ListenerAddress)4 Reconciliation (io.strimzi.operator.common.Reconciliation)4 Labels (io.strimzi.operator.common.model.Labels)4 KafkaListenerAuthenticationTls (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationTls)3 GenericKafkaListenerConfiguration (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfiguration)3