Search in sources :

Example 91 with GenericKafkaListener

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;
        }
    }
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) KafkaListenerAuthenticationOAuth(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuth)

Example 92 with GenericKafkaListener

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;
}
Also used : ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) ListenersUtils.isListenerWithOAuth(io.strimzi.operator.cluster.model.ListenersUtils.isListenerWithOAuth) Set(java.util.Set) Collectors(java.util.stream.Collectors) KafkaListenerAuthenticationOAuth(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuth) HashSet(java.util.HashSet) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) KafkaListenerAuthenticationTls(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationTls) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) GenericKafkaListenerConfiguration(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfiguration) JsonPathFilterQuery(io.strimzi.kafka.oauth.jsonpath.JsonPathFilterQuery) JsonPathQuery(io.strimzi.kafka.oauth.jsonpath.JsonPathQuery) Pattern(java.util.regex.Pattern) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) HashSet(java.util.HashSet)

Example 93 with GenericKafkaListener

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"));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 94 with GenericKafkaListener

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"));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 95 with GenericKafkaListener

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()));
}
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)

Aggregations

GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)160 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)116 ParallelTest (io.strimzi.test.annotations.ParallelTest)102 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)50 ArrayList (java.util.ArrayList)38 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)18 Matchers.containsString (org.hamcrest.Matchers.containsString)16 KafkaListenerAuthenticationOAuth (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuth)12 KafkaListenerAuthenticationOAuthBuilder (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder)12 Kafka (io.strimzi.api.kafka.model.Kafka)10 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)8 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)8 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 NetworkPolicyIngressRule (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRule)6 NetworkPolicyIngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRuleBuilder)6 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)6