Search in sources :

Example 26 with GenericKafkaListenerConfigurationBrokerBuilder

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

the class ListenersValidatorTest method testIngressListenerHostNames.

@ParallelTest
public void testIngressListenerHostNames() {
    GenericKafkaListener listener = new GenericKafkaListenerBuilder().withName("ingress").withPort(9092).withType(KafkaListenerType.INGRESS).withTls(true).build();
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a configuration with host names which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBrokers((List<GenericKafkaListenerConfigurationBroker>) null).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a bootstrap host name which is required for Ingress based listeners", "listener ingress is missing a broker configuration with host names which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBootstrap(new GenericKafkaListenerConfigurationBootstrapBuilder().build()).withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).build()).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a bootstrap host name which is required for Ingress based listeners", "listener ingress is missing a broker host name for broker with ID 0 which is required for Ingress based listeners", "listener ingress is missing a broker host name for broker with ID 1 which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBootstrap(new GenericKafkaListenerConfigurationBootstrapBuilder().withHost("bootstrap-host").build()).withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("host-1").build()).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a broker host name for broker with ID 0 which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBootstrap(new GenericKafkaListenerConfigurationBootstrapBuilder().withHost("bootstrap-host").build()).withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withHost("host-0").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("host-1").build()).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), hasSize(0));
}
Also used : GenericKafkaListenerConfigurationBootstrapBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerConfigurationBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 27 with GenericKafkaListenerConfigurationBrokerBuilder

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

the class ListenersValidatorTest method testInternalListener.

@ParallelTest
public void testInternalListener() {
    String name = "plain";
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName(name).withPort(9092).withType(KafkaListenerType.INTERNAL).withNewConfiguration().withIngressClass("my-ingress").withUseServiceDnsDomain(true).withExternalTrafficPolicy(ExternalTrafficPolicy.LOCAL).withIpFamilyPolicy(IpFamilyPolicy.REQUIRE_DUAL_STACK).withIpFamilies(IpFamily.IPV4, IpFamily.IPV6).withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).withLoadBalancerSourceRanges(asList("10.0.0.0/8", "130.211.204.1/32")).withFinalizers(asList("service.kubernetes.io/load-balancer-cleanup")).withNewBootstrap().withAlternativeNames(asList("my-name-1", "my-name-2")).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).build()).endConfiguration().build();
    List<GenericKafkaListener> listeners = asList(listener1);
    List<String> expectedErrors = asList("listener " + name + " cannot configure ingressClass because it is not Ingress based listener", "listener " + name + " cannot configure externalTrafficPolicy because it is not LoadBalancer or NodePort based listener", "listener " + name + " cannot configure loadBalancerSourceRanges because it is not LoadBalancer based listener", "listener " + name + " cannot configure finalizers because it is not LoadBalancer based listener", "listener " + name + " cannot configure preferredAddressType because it is not NodePort based listener", "listener " + name + " cannot configure bootstrap.host because it is not Route ot Ingress based listener", "listener " + name + " cannot configure bootstrap.loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure bootstrap.nodePort because it is not NodePort based listener", "listener " + name + " cannot configure bootstrap.annotations because it is not LoadBalancer, NodePort, Route, or Ingress based listener", "listener " + name + " cannot configure bootstrap.labels because it is not LoadBalancer, NodePort, Route, or Ingress based listener", "listener " + name + " cannot configure brokers[].host because it is not Route ot Ingress based listener", "listener " + name + " cannot configure brokers[].loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure brokers[].nodePort because it is not NodePort based listener", "listener " + name + " cannot configure brokers[].annotations because it is not LoadBalancer, NodePort, Route, or Ingress based listener", "listener " + name + " cannot configure brokers[].labels because it is not LoadBalancer, NodePort, Route, or Ingress based listener", "listener " + name + " cannot configure ipFamilyPolicy because it is not internal listener", "listener " + name + " cannot configure ipFamilies because it is not internal listener");
    assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder(expectedErrors.toArray()));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 28 with GenericKafkaListenerConfigurationBrokerBuilder

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

the class ListenersValidatorTest method testNodePortListener.

@ParallelTest
public void testNodePortListener() {
    String name = "nodeport";
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName(name).withPort(9092).withType(KafkaListenerType.NODEPORT).withNewConfiguration().withIngressClass("my-ingress").withUseServiceDnsDomain(true).withExternalTrafficPolicy(ExternalTrafficPolicy.LOCAL).withIpFamilyPolicy(IpFamilyPolicy.REQUIRE_DUAL_STACK).withIpFamilies(IpFamily.IPV4, IpFamily.IPV6).withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).withLoadBalancerSourceRanges(asList("10.0.0.0/8", "130.211.204.1/32")).withFinalizers(asList("service.kubernetes.io/load-balancer-cleanup")).withNewBootstrap().withAlternativeNames(asList("my-name-1", "my-name-2")).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).build()).endConfiguration().build();
    List<GenericKafkaListener> listeners = asList(listener1);
    List<String> expectedErrors = asList("listener " + name + " cannot configure ingressClass because it is not Ingress based listener", "listener " + name + " cannot configure useServiceDnsDomain because it is not internal listener", "listener " + name + " cannot configure loadBalancerSourceRanges because it is not LoadBalancer based listener", "listener " + name + " cannot configure finalizers because it is not LoadBalancer based listener", "listener " + name + " cannot configure bootstrap.host because it is not Route ot Ingress based listener", "listener " + name + " cannot configure bootstrap.loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure brokers[].host because it is not Route ot Ingress based listener", "listener " + name + " cannot configure brokers[].loadBalancerIP because it is not LoadBalancer based listener");
    assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder(expectedErrors.toArray()));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 29 with GenericKafkaListenerConfigurationBrokerBuilder

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

the class ListenersST method testOverrideNodePortConfiguration.

@ParallelNamespaceTest
@Tag(NODEPORT_SUPPORTED)
@Tag(EXTERNAL_CLIENTS_USED)
void testOverrideNodePortConfiguration(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 int brokerNodePort = 32000;
    final int brokerId = 0;
    final int clusterBootstrapNodePort = 32100;
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 1).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9099).withTls(true).build(), new GenericKafkaListenerBuilder().withType(KafkaListenerType.NODEPORT).withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9100).withTls(false).withNewConfiguration().withNewBootstrap().withNodePort(clusterBootstrapNodePort).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(brokerId).withNodePort(brokerNodePort).build()).endConfiguration().build()).endKafka().endSpec().build());
    LOGGER.info("Checking nodePort to {} for bootstrap service {}", clusterBootstrapNodePort, KafkaResources.externalBootstrapServiceName(clusterName));
    assertThat(kubeClient(namespaceName).getService(namespaceName, KafkaResources.externalBootstrapServiceName(clusterName)).getSpec().getPorts().get(0).getNodePort(), is(clusterBootstrapNodePort));
    String firstExternalService = clusterName + "-kafka-" + Constants.EXTERNAL_LISTENER_DEFAULT_NAME + "-" + 0;
    LOGGER.info("Checking nodePort to {} for kafka-broker service {}", brokerNodePort, firstExternalService);
    assertThat(kubeClient(namespaceName).getService(namespaceName, firstExternalService).getSpec().getPorts().get(0).getNodePort(), is(brokerNodePort));
    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());
}
Also used : ExternalKafkaClient(io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) 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)

Example 30 with GenericKafkaListenerConfigurationBrokerBuilder

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

the class KafkaClusterTest method testExternalLoadBalancersWithLoadBalancerIPOverride.

@ParallelTest
public void testExternalLoadBalancersWithLoadBalancerIPOverride() {
    GenericKafkaListenerConfigurationBootstrap bootstrapConfig = new GenericKafkaListenerConfigurationBootstrapBuilder().withLoadBalancerIP("10.0.0.1").build();
    GenericKafkaListenerConfigurationBroker brokerConfig0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withLoadBalancerIP("10.0.0.2").build();
    GenericKafkaListenerConfigurationBroker brokerConfig2 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(2).withLoadBalancerIP("10.0.0.3").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.LOADBALANCER).withTls(true).withNewConfiguration().withBootstrap(bootstrapConfig).withBrokers(brokerConfig0, brokerConfig2).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    // Check annotations
    assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getLoadBalancerIP(), is("10.0.0.1"));
    assertThat(kc.generateExternalServices(0).get(0).getSpec().getLoadBalancerIP(), is("10.0.0.2"));
    assertThat(kc.generateExternalServices(1).get(0).getSpec().getLoadBalancerIP(), is(nullValue()));
    assertThat(kc.generateExternalServices(2).get(0).getSpec().getLoadBalancerIP(), is("10.0.0.3"));
}
Also used : GenericKafkaListenerConfigurationBootstrapBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder) GenericKafkaListenerConfigurationBootstrap(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrap) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) 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

GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)42 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)42 ParallelTest (io.strimzi.test.annotations.ParallelTest)30 Kafka (io.strimzi.api.kafka.model.Kafka)20 GenericKafkaListenerConfigurationBroker (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker)20 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)18 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)18 Matchers.containsString (org.hamcrest.Matchers.containsString)12 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)8 Labels (io.strimzi.operator.common.model.Labels)8 GenericKafkaListenerConfigurationBootstrapBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)6 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)6 KafkaListenerType (io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType)6 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)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 Reconciliation (io.strimzi.operator.common.Reconciliation)6