Search in sources :

Example 16 with GenericKafkaListenerConfigurationBroker

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

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

Example 18 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testGetExternalServiceAdvertisedHostAndPortOverride.

@ParallelTest
public void testGetExternalServiceAdvertisedHostAndPortOverride() {
    GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig0 = new GenericKafkaListenerConfigurationBroker();
    nodePortListenerBrokerConfig0.setBroker(0);
    nodePortListenerBrokerConfig0.setAdvertisedHost("my-host-0.cz");
    nodePortListenerBrokerConfig0.setAdvertisedPort(10000);
    GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig1 = new GenericKafkaListenerConfigurationBroker();
    nodePortListenerBrokerConfig1.setBroker(1);
    nodePortListenerBrokerConfig1.setAdvertisedHost("my-host-1.cz");
    nodePortListenerBrokerConfig1.setAdvertisedPort(10001);
    GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig2 = new GenericKafkaListenerConfigurationBroker();
    nodePortListenerBrokerConfig2.setBroker(2);
    nodePortListenerBrokerConfig2.setAdvertisedHost("my-host-2.cz");
    nodePortListenerBrokerConfig2.setAdvertisedPort(10002);
    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, nodePortListenerBrokerConfig1, nodePortListenerBrokerConfig2).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(ListenersUtils.brokerAdvertisedPort(kc.getListeners().get(0), 0), is(10000));
    assertThat(ListenersUtils.brokerAdvertisedHost(kc.getListeners().get(0), 0), is("my-host-0.cz"));
    assertThat(ListenersUtils.brokerAdvertisedPort(kc.getListeners().get(0), 1), is(10001));
    assertThat(ListenersUtils.brokerAdvertisedHost(kc.getListeners().get(0), 1), is("my-host-1.cz"));
    assertThat(ListenersUtils.brokerAdvertisedPort(kc.getListeners().get(0), 2), is(10002));
    assertThat(ListenersUtils.brokerAdvertisedHost(kc.getListeners().get(0), 2), is("my-host-2.cz"));
}
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)

Example 19 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testGetExternalNodePortServiceAddressOverrideWithNonNullAdvertisedHost.

@ParallelTest
public void testGetExternalNodePortServiceAddressOverrideWithNonNullAdvertisedHost() {
    GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig = new GenericKafkaListenerConfigurationBroker();
    nodePortListenerBrokerConfig.setBroker(0);
    nodePortListenerBrokerConfig.setNodePort(32101);
    nodePortListenerBrokerConfig.setAdvertisedHost("advertised.host");
    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(false).withNewConfiguration().withNewBootstrap().withNodePort(32001).endBootstrap().withBrokers(nodePortListenerBrokerConfig).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(kc.generateExternalServices(0).get(0).getSpec().getPorts().get(0).getNodePort(), is(32101));
    assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getNodePort(), is(32001));
    assertThat(ListenersUtils.bootstrapNodePort(kc.getListeners().get(0)), is(32001));
    assertThat(ListenersUtils.brokerNodePort(kc.getListeners().get(0), 0), is(32101));
    assertThat(ListenersUtils.brokerAdvertisedHost(kc.getListeners().get(0), 0), is("advertised.host"));
}
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)

Example 20 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testExternalLoadBalancersWithLabelsAndAnnotations.

@ParallelTest
public void testExternalLoadBalancersWithLabelsAndAnnotations() {
    GenericKafkaListenerConfigurationBootstrap bootstrapConfig = new GenericKafkaListenerConfigurationBootstrapBuilder().withAnnotations(Collections.singletonMap("external-dns.alpha.kubernetes.io/hostname", "bootstrap.myingress.com.")).withLabels(Collections.singletonMap("label", "label-value")).build();
    GenericKafkaListenerConfigurationBroker brokerConfig0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAnnotations(Collections.singletonMap("external-dns.alpha.kubernetes.io/hostname", "broker-0.myingress.com.")).withLabels(Collections.singletonMap("label", "label-value")).build();
    GenericKafkaListenerConfigurationBroker brokerConfig2 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(2).withAnnotations(Collections.singletonMap("external-dns.alpha.kubernetes.io/hostname", "broker-2.myingress.com.")).withLabels(Collections.singletonMap("label", "label-value")).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).getMetadata().getAnnotations(), is(Collections.singletonMap("external-dns.alpha.kubernetes.io/hostname", "bootstrap.myingress.com.")));
    assertThat(kc.generateExternalBootstrapServices().get(0).getMetadata().getLabels().get("label"), is("label-value"));
    assertThat(kc.generateExternalServices(0).get(0).getMetadata().getAnnotations(), is(Collections.singletonMap("external-dns.alpha.kubernetes.io/hostname", "broker-0.myingress.com.")));
    assertThat(kc.generateExternalServices(0).get(0).getMetadata().getLabels().get("label"), is("label-value"));
    assertThat(kc.generateExternalServices(1).get(0).getMetadata().getAnnotations().isEmpty(), is(true));
    assertThat(kc.generateExternalServices(1).get(0).getMetadata().getLabels().get("label"), is(nullValue()));
    assertThat(kc.generateExternalServices(2).get(0).getMetadata().getAnnotations(), is(Collections.singletonMap("external-dns.alpha.kubernetes.io/hostname", "broker-2.myingress.com.")));
    assertThat(kc.generateExternalServices(2).get(0).getMetadata().getLabels().get("label"), is("label-value"));
}
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

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