Search in sources :

Example 26 with GenericKafkaListenerConfigurationBroker

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

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

the class KafkaBrokerConfigurationBuilderTest method testWithExternalListenersIngress.

@ParallelTest
public void testWithExternalListenersIngress() {
    GenericKafkaListenerConfigurationBroker broker = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withHost("broker-0.mytld.com").build();
    GenericKafkaListener listener = new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.INGRESS).withTls(true).withNewConfiguration().withIngressClass("nginx-ingress").withNewBootstrap().withHost("bootstrap.mytld.com").endBootstrap().withBrokers(broker).endConfiguration().build();
    String configuration = new KafkaBrokerConfigurationBuilder(Reconciliation.DUMMY_RECONCILIATION).withListeners("my-cluster", "my-namespace", singletonList(listener), false).build();
    assertThat(configuration, isEquivalent("listener.name.controlplane-9090.ssl.client.auth=required", "listener.name.controlplane-9090.ssl.keystore.location=/tmp/kafka/cluster.keystore.p12", "listener.name.controlplane-9090.ssl.keystore.password=${CERTS_STORE_PASSWORD}", "listener.name.controlplane-9090.ssl.keystore.type=PKCS12", "listener.name.controlplane-9090.ssl.truststore.location=/tmp/kafka/cluster.truststore.p12", "listener.name.controlplane-9090.ssl.truststore.password=${CERTS_STORE_PASSWORD}", "listener.name.controlplane-9090.ssl.truststore.type=PKCS12", "listener.name.replication-9091.ssl.keystore.location=/tmp/kafka/cluster.keystore.p12", "listener.name.replication-9091.ssl.keystore.password=${CERTS_STORE_PASSWORD}", "listener.name.replication-9091.ssl.keystore.type=PKCS12", "listener.name.replication-9091.ssl.truststore.location=/tmp/kafka/cluster.truststore.p12", "listener.name.replication-9091.ssl.truststore.password=${CERTS_STORE_PASSWORD}", "listener.name.replication-9091.ssl.truststore.type=PKCS12", "listener.name.replication-9091.ssl.client.auth=required", "listeners=CONTROLPLANE-9090://0.0.0.0:9090,REPLICATION-9091://0.0.0.0:9091,EXTERNAL-9094://0.0.0.0:9094", "advertised.listeners=CONTROLPLANE-9090://my-cluster-kafka-${STRIMZI_BROKER_ID}.my-cluster-kafka-brokers.my-namespace.svc:9090,REPLICATION-9091://my-cluster-kafka-${STRIMZI_BROKER_ID}.my-cluster-kafka-brokers.my-namespace.svc:9091,EXTERNAL-9094://${STRIMZI_EXTERNAL_9094_ADVERTISED_HOSTNAME}:${STRIMZI_EXTERNAL_9094_ADVERTISED_PORT}", "listener.security.protocol.map=CONTROLPLANE-9090:SSL,REPLICATION-9091:SSL,EXTERNAL-9094:SSL", "inter.broker.listener.name=REPLICATION-9091", "sasl.enabled.mechanisms=", "ssl.secure.random.implementation=SHA1PRNG", "ssl.endpoint.identification.algorithm=HTTPS", "listener.name.external-9094.ssl.keystore.location=/tmp/kafka/cluster.keystore.p12", "listener.name.external-9094.ssl.keystore.password=${CERTS_STORE_PASSWORD}", "listener.name.external-9094.ssl.keystore.type=PKCS12"));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 28 with GenericKafkaListenerConfigurationBroker

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

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

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

the class KafkaClusterTest method testGetExternalAdvertisedUrlWithOverrides.

@ParallelTest
public void testGetExternalAdvertisedUrlWithOverrides() {
    GenericKafkaListenerConfigurationBroker nodePortListenerBrokerConfig0 = new GenericKafkaListenerConfigurationBroker();
    nodePortListenerBrokerConfig0.setBroker(0);
    nodePortListenerBrokerConfig0.setAdvertisedHost("my-host-0.cz");
    nodePortListenerBrokerConfig0.setAdvertisedPort(10000);
    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).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 0, "some-host.com"), is("EXTERNAL_9094_0://my-host-0.cz"));
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 0, ""), is("EXTERNAL_9094_0://my-host-0.cz"));
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 1, "some-host.com"), is("EXTERNAL_9094_1://some-host.com"));
    assertThat(kc.getAdvertisedHostname(kc.getListeners().get(0), 1, ""), is("EXTERNAL_9094_1://"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 0, 12345), is("EXTERNAL_9094_0://10000"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 0, 12345), is("EXTERNAL_9094_0://10000"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 1, 12345), is("EXTERNAL_9094_1://12345"));
    assertThat(kc.getAdvertisedPort(kc.getListeners().get(0), 1, 12345), is("EXTERNAL_9094_1://12345"));
}
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)

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