Search in sources :

Example 11 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testExternalIngressClass.

@ParallelTest
public void testExternalIngressClass() {
    GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-0.com").withBroker(0).build();
    GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-1.com").withBroker(1).build();
    GenericKafkaListenerConfigurationBroker broker2 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-2.com").withBroker(2).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, broker1, broker2).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    // Check bootstrap ingress
    Ingress bing = kc.generateExternalBootstrapIngresses().get(0);
    assertThat(bing.getSpec().getIngressClassName(), is("nginx-internal"));
    io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress bingV1Beta1 = kc.generateExternalBootstrapIngressesV1Beta1().get(0);
    assertThat(bingV1Beta1.getSpec().getIngressClassName(), is("nginx-internal"));
    // Check per pod ingress
    for (int i = 0; i < replicas; i++) {
        Ingress ing = kc.generateExternalIngresses(i).get(0);
        assertThat(ing.getSpec().getIngressClassName(), is("nginx-internal"));
        io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingV1Beta1 = kc.generateExternalIngressesV1Beta1(i).get(0);
        assertThat(ingV1Beta1.getSpec().getIngressClassName(), is("nginx-internal"));
    }
}
Also used : GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 12 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testExternalNodePortOverrides.

@ParallelTest
public void testExternalNodePortOverrides() {
    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);
    // Check StatefulSet changes
    StatefulSet sts = kc.generateStatefulSet(true, null, null, null);
    List<ContainerPort> ports = sts.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts();
    assertThat(ports.contains(kc.createContainerPort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, "TCP")), is(true));
    // Check external bootstrap service
    Service ext = kc.generateExternalBootstrapServices().get(0);
    assertThat(ext.getMetadata().getName(), is(KafkaCluster.externalBootstrapServiceName(cluster)));
    assertThat(ext.getSpec().getType(), is("NodePort"));
    assertThat(ext.getSpec().getSelector(), is(kc.getSelectorLabels().toMap()));
    assertThat(ext.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, 32001, "TCP"))));
    checkOwnerReference(kc.createOwnerReference(), ext);
    // Check per pod services
    for (int i = 0; i < replicas; i++) {
        Service srv = kc.generateExternalServices(i).get(0);
        assertThat(srv.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(srv.getSpec().getType(), is("NodePort"));
        assertThat(srv.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), is(KafkaCluster.kafkaPodName(cluster, i)));
        if (i == 0) {
            // pod with index 0 will have overriden port
            assertThat(srv.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, 32101, "TCP"))));
        } else {
            assertThat(srv.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, "TCP"))));
        }
        checkOwnerReference(kc.createOwnerReference(), srv);
    }
}
Also used : GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) Service(io.fabric8.kubernetes.api.model.Service) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 13 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testExternalLoadBalancersWithLoadBalancerIPOverride.

@ParallelTest
public void testExternalLoadBalancersWithLoadBalancerIPOverride() {
    GenericKafkaListenerConfigurationBootstrap bootstrapConfig = new GenericKafkaListenerConfigurationBootstrapBuilder().withLoadBalancerIP("10.0.0.1").build();
    GenericKafkaListenerConfigurationBroker brokerConfig0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withLoadBalancerIP("10.0.0.2").build();
    GenericKafkaListenerConfigurationBroker brokerConfig2 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(2).withLoadBalancerIP("10.0.0.3").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.LOADBALANCER).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).getSpec().getLoadBalancerIP(), is("10.0.0.1"));
    assertThat(kc.generateExternalServices(0).get(0).getSpec().getLoadBalancerIP(), is("10.0.0.2"));
    assertThat(kc.generateExternalServices(1).get(0).getSpec().getLoadBalancerIP(), is(nullValue()));
    assertThat(kc.generateExternalServices(2).get(0).getSpec().getLoadBalancerIP(), is("10.0.0.3"));
}
Also used : GenericKafkaListenerConfigurationBootstrapBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder) GenericKafkaListenerConfigurationBootstrap(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrap) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) 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 14 with GenericKafkaListenerConfigurationBroker

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

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker 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)

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