use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.
the class KafkaClusterTest method testExternalRoutesWithHostOverrides.
@ParallelTest
public void testExternalRoutesWithHostOverrides() {
GenericKafkaListenerConfigurationBroker routeListenerBrokerConfig0 = new GenericKafkaListenerConfigurationBroker();
routeListenerBrokerConfig0.setBroker(0);
routeListenerBrokerConfig0.setHost("my-host-0.cz");
GenericKafkaListenerConfigurationBroker routeListenerBrokerConfig1 = new GenericKafkaListenerConfigurationBroker();
routeListenerBrokerConfig1.setBroker(1);
routeListenerBrokerConfig1.setHost("my-host-1.cz");
GenericKafkaListenerConfigurationBroker routeListenerBrokerConfig2 = new GenericKafkaListenerConfigurationBroker();
routeListenerBrokerConfig2.setBroker(2);
routeListenerBrokerConfig2.setHost("my-host-2.cz");
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.ROUTE).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().withNewConfiguration().withNewBootstrap().withHost("my-boostrap.cz").endBootstrap().withBrokers(routeListenerBrokerConfig0, routeListenerBrokerConfig1, routeListenerBrokerConfig2).endConfiguration().build()).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
// Check bootstrap route
Route brt = kc.generateExternalBootstrapRoutes().get(0);
assertThat(brt.getMetadata().getName(), is(KafkaCluster.serviceName(cluster)));
assertThat(brt.getSpec().getHost(), is("my-boostrap.cz"));
// Check per pod router
for (int i = 0; i < replicas; i++) {
Route rt = kc.generateExternalRoutes(i).get(0);
assertThat(rt.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
assertThat(rt.getSpec().getHost(), is("my-host-" + i + ".cz"));
}
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.
the class KafkaClusterTest method testExternalNodePortWithLabelsAndAnnotations.
@ParallelTest
public void testExternalNodePortWithLabelsAndAnnotations() {
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.NODEPORT).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"));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.
the class KafkaClusterTest method testGetExternalNodePortServiceAddressOverrideWithNullAdvertisedHost.
@ParallelTest
public void testGetExternalNodePortServiceAddressOverrideWithNullAdvertisedHost() {
GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig = new GenericKafkaListenerConfigurationBroker();
nodePortListenerBrokerConfig.setBroker(0);
nodePortListenerBrokerConfig.setNodePort(32101);
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));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi by strimzi.
the class KafkaClusterTest method testExternalRoutesWithLabelsAndAnnotations.
@ParallelTest
public void testExternalRoutesWithLabelsAndAnnotations() {
GenericKafkaListenerConfigurationBroker routeListenerBrokerConfig0 = new GenericKafkaListenerConfigurationBroker();
routeListenerBrokerConfig0.setBroker(0);
routeListenerBrokerConfig0.setAnnotations(Collections.singletonMap("anno", "anno-value-0"));
routeListenerBrokerConfig0.setLabels(Collections.singletonMap("label", "label-value-0"));
GenericKafkaListenerConfigurationBroker routeListenerBrokerConfig1 = new GenericKafkaListenerConfigurationBroker();
routeListenerBrokerConfig1.setBroker(1);
routeListenerBrokerConfig1.setAnnotations(Collections.singletonMap("anno", "anno-value-1"));
routeListenerBrokerConfig1.setLabels(Collections.singletonMap("label", "label-value-1"));
GenericKafkaListenerConfigurationBroker routeListenerBrokerConfig2 = new GenericKafkaListenerConfigurationBroker();
routeListenerBrokerConfig2.setBroker(2);
routeListenerBrokerConfig2.setAnnotations(Collections.singletonMap("anno", "anno-value-2"));
routeListenerBrokerConfig2.setLabels(Collections.singletonMap("label", "label-value-2"));
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.ROUTE).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().withNewConfiguration().withNewBootstrap().withAnnotations(Collections.singletonMap("anno", "anno-value")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(routeListenerBrokerConfig0, routeListenerBrokerConfig1, routeListenerBrokerConfig2).endConfiguration().build()).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
// Check bootstrap route
Route brt = kc.generateExternalBootstrapRoutes().get(0);
assertThat(brt.getMetadata().getName(), is(KafkaCluster.serviceName(cluster)));
assertThat(brt.getMetadata().getAnnotations().get("anno"), is("anno-value"));
assertThat(brt.getMetadata().getLabels().get("label"), is("label-value"));
// Check per pod router
for (int i = 0; i < replicas; i++) {
Route rt = kc.generateExternalRoutes(i).get(0);
assertThat(rt.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
assertThat(rt.getMetadata().getAnnotations().get("anno"), is("anno-value-" + i));
assertThat(rt.getMetadata().getLabels().get("label"), is("label-value-" + i));
}
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi-kafka-operator 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");
}
}
Aggregations