use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class KafkaBrokerConfigurationBuilder method configureOAuthPrincipalBuilderIfNeeded.
private void configureOAuthPrincipalBuilderIfNeeded(PrintWriter writer, List<GenericKafkaListener> kafkaListeners) {
for (GenericKafkaListener listener : kafkaListeners) {
if (listener.getAuth() instanceof KafkaListenerAuthenticationOAuth) {
writer.println(String.format("principal.builder.class=%s", KafkaListenerAuthenticationOAuth.PRINCIPAL_BUILDER_CLASS_NAME));
writer.println();
return;
}
}
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class ListenersValidator method validateAndGetErrorMessages.
/*test*/
static Set<String> validateAndGetErrorMessages(int replicas, List<GenericKafkaListener> listeners) {
Set<String> errors = new HashSet<>(0);
List<Integer> ports = getPorts(listeners);
List<String> names = getNames(listeners);
if (names.size() != listeners.size()) {
errors.add("every listener needs to have a unique name");
}
List<String> invalidNames = names.stream().filter(name -> !LISTENER_NAME_PATTERN.matcher(name).matches()).collect(Collectors.toList());
if (!invalidNames.isEmpty()) {
errors.add("listener names " + invalidNames + " are invalid and do not match the pattern " + GenericKafkaListener.LISTENER_NAME_REGEX);
}
if (ports.size() != listeners.size()) {
errors.add("every listener needs to have a unique port number");
}
for (GenericKafkaListener listener : listeners) {
validatePortNumbers(errors, listener);
validateRouteAndIngressTlsOnly(errors, listener);
validateTlsFeaturesOnNonTlsListener(errors, listener);
validateOauth(errors, listener);
if (listener.getConfiguration() != null) {
validateServiceDnsDomain(errors, listener);
validateIpFamilyPolicy(errors, listener);
validateIpFamilies(errors, listener);
validateIngressClass(errors, listener);
validateExternalTrafficPolicy(errors, listener);
validateLoadBalancerSourceRanges(errors, listener);
validateFinalizers(errors, listener);
validatePreferredAddressType(errors, listener);
validateCreateBootstrapService(errors, listener);
if (listener.getConfiguration().getBootstrap() != null) {
validateBootstrapHost(errors, listener);
validateBootstrapLoadBalancerIp(errors, listener);
validateBootstrapNodePort(errors, listener);
validateBootstrapLabelsAndAnnotations(errors, listener);
}
if (listener.getConfiguration().getBrokers() != null) {
for (GenericKafkaListenerConfigurationBroker broker : listener.getConfiguration().getBrokers()) {
validateBrokerHost(errors, listener, broker);
validateBrokerLoadBalancerIp(errors, listener, broker);
validateBrokerNodePort(errors, listener, broker);
validateBrokerLabelsAndAnnotations(errors, listener, broker);
}
}
if (listener.getConfiguration().getBrokerCertChainAndKey() != null) {
validateBrokerCertChainAndKey(errors, listener);
}
}
if (KafkaListenerType.INGRESS.equals(listener.getType())) {
validateIngress(errors, replicas, listener);
}
}
return errors;
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class ListenersValidatorTest method testValidateForbiddenPortByRange.
@ParallelTest
public void testValidateForbiddenPortByRange() {
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9000).withType(KafkaListenerType.INTERNAL).build();
List<GenericKafkaListener> listeners = asList(listener1);
assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder("port 9000 is forbidden and cannot be used"));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class ListenersValidatorTest method testValidateForbiddenPortByException.
@ParallelTest
public void testValidateForbiddenPortByException() {
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9404).withType(KafkaListenerType.INTERNAL).build();
List<GenericKafkaListener> listeners = asList(listener1);
assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder("port 9404 is forbidden and cannot be used"));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class ListenersValidatorTest method testIngressListenerWithoutTls.
@ParallelTest
public void testIngressListenerWithoutTls() {
String name = "ingress";
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName(name).withPort(9092).withType(KafkaListenerType.INGRESS).withTls(false).withNewConfiguration().withNewBootstrap().withHost("my-host").endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withHost("my-host").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("my-host").build()).endConfiguration().build();
List<GenericKafkaListener> listeners = asList(listener1);
List<String> expectedErrors = asList("listener " + name + " is Route or Ingress type listener and requires enabled TLS encryption");
assertThat(ListenersValidator.validateAndGetErrorMessages(2, listeners), containsInAnyOrder(expectedErrors.toArray()));
}
Aggregations