use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi-kafka-operator by strimzi.
the class KafkaClusterTest method testExternalIngressMissingConfiguration.
@ParallelTest
public void testExternalIngressMissingConfiguration() {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).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).endConfiguration().build()).endKafka().endSpec().build();
try {
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
fail("Expected exception was not thrown");
} catch (InvalidResourceException e) {
// pass
}
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi-kafka-operator 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));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi-kafka-operator 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++)));
}
}
Aggregations