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;
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations