use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder in project strimzi by strimzi.
the class ListenersST method testOverrideNodePortConfiguration.
@ParallelNamespaceTest
@Tag(NODEPORT_SUPPORTED)
@Tag(EXTERNAL_CLIENTS_USED)
void testOverrideNodePortConfiguration(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(clusterOperator.getDeploymentNamespace(), extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
final int brokerNodePort = 32000;
final int brokerId = 0;
final int clusterBootstrapNodePort = 32100;
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 1).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9099).withTls(true).build(), new GenericKafkaListenerBuilder().withType(KafkaListenerType.NODEPORT).withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9100).withTls(false).withNewConfiguration().withNewBootstrap().withNodePort(clusterBootstrapNodePort).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(brokerId).withNodePort(brokerNodePort).build()).endConfiguration().build()).endKafka().endSpec().build());
LOGGER.info("Checking nodePort to {} for bootstrap service {}", clusterBootstrapNodePort, KafkaResources.externalBootstrapServiceName(clusterName));
assertThat(kubeClient(namespaceName).getService(namespaceName, KafkaResources.externalBootstrapServiceName(clusterName)).getSpec().getPorts().get(0).getNodePort(), is(clusterBootstrapNodePort));
String firstExternalService = clusterName + "-kafka-" + Constants.EXTERNAL_LISTENER_DEFAULT_NAME + "-" + 0;
LOGGER.info("Checking nodePort to {} for kafka-broker service {}", brokerNodePort, firstExternalService);
assertThat(kubeClient(namespaceName).getService(namespaceName, firstExternalService).getSpec().getPorts().get(0).getNodePort(), is(brokerNodePort));
ExternalKafkaClient externalKafkaClient = new ExternalKafkaClient.Builder().withTopicName(topicName).withNamespaceName(namespaceName).withClusterName(clusterName).withMessageCount(MESSAGE_COUNT).withListenerName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).build();
externalKafkaClient.verifyProducedAndConsumedMessages(externalKafkaClient.sendMessagesPlain(), externalKafkaClient.receiveMessagesPlain());
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder in project strimzi by strimzi.
the class KafkaListenerReconcilerIngressV1Beta1Test method testIngressV1.
@Test
public void testIngressV1(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("ingress").withPort(9094).withTls(true).withType(KafkaListenerType.INGRESS).withNewConfiguration().withNewBootstrap().withHost("bootstrap.mydomain.tld").endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withHost("broker-0.mydomain.tld").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("broker-1.mydomain.tld").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(2).withHost("broker-2.mydomain.tld").build()).endConfiguration().build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock ingress v1beta1 ops
IngressV1Beta1Operator mockIngressV1Beta1ops = supplier.ingressV1Beta1Operations;
ArgumentCaptor<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> ingressV1Beta1Captor = ArgumentCaptor.forClass(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress.class);
when(mockIngressV1Beta1ops.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(emptyList()));
when(mockIngressV1Beta1ops.reconcile(any(), anyString(), anyString(), ingressV1Beta1Captor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created(new io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress())));
when(mockIngressV1Beta1ops.hasIngressAddress(any(), eq(NAMESPACE), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
// Mock ingress v1 ops
IngressOperator mockIngressOps = supplier.ingressOperations;
ArgumentCaptor<Ingress> ingressCaptor = ArgumentCaptor.forClass(Ingress.class);
when(mockIngressOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(emptyList()));
when(mockIngressOps.reconcile(any(), anyString(), anyString(), ingressCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created(new Ingress())));
when(mockIngressOps.hasIngressAddress(any(), eq(NAMESPACE), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
MockKafkaListenersReconciler reconciler = new MockKafkaListenersReconciler(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME), kafkaCluster, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_22), supplier.secretOperations, supplier.serviceOperations, supplier.routeOperations, supplier.ingressOperations, supplier.ingressV1Beta1Operations);
Checkpoint async = context.checkpoint();
reconciler.reconcile().onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(ingressCaptor.getAllValues().size(), is(4));
assertThat(ingressV1Beta1Captor.getAllValues().size(), is(0));
verify(mockIngressV1Beta1ops, never()).list(any(), any());
verify(mockIngressV1Beta1ops, never()).reconcile(any(), any(), any(), any());
verify(mockIngressV1Beta1ops, never()).hasIngressAddress(any(), any(), any(), anyLong(), anyLong());
async.flag();
})));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder in project strimzi by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsAndOverrides.
@Test
public void testKafkaReconcilerStatusWithNodePortsAndOverrides(VertxTestContext context) {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("my-address-0").build();
GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("my-address-1").build();
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(broker0, broker1).endConfiguration().build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is("my-address-0:31234,5.124.16.8:31234,my-address-1:31234"));
assertThat(status.getListeners().get(0).getAddresses().size(), is(3));
assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("my-address-0"));
assertThat(status.getListeners().get(0).getAddresses().get(1).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(1).getHost(), is("5.124.16.8"));
assertThat(status.getListeners().get(0).getAddresses().get(2).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(2).getHost(), is("my-address-1"));
async.flag();
}));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsAndOverrides.
@Test
public void testKafkaReconcilerStatusWithNodePortsAndOverrides(VertxTestContext context) {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("my-address-0").build();
GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("my-address-1").build();
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(broker0, broker1).endConfiguration().build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is("my-address-0:31234,5.124.16.8:31234,my-address-1:31234"));
assertThat(status.getListeners().get(0).getAddresses().size(), is(3));
assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("my-address-0"));
assertThat(status.getListeners().get(0).getAddresses().get(1).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(1).getHost(), is("5.124.16.8"));
assertThat(status.getListeners().get(0).getAddresses().get(2).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(2).getHost(), is("my-address-1"));
async.flag();
}));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaClusterTest method testExternalIngressMissingConfiguration.
@ParallelTest
public void testExternalIngressMissingConfiguration() {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).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).endConfiguration().build()).endKafka().endSpec().build();
assertThrows(InvalidResourceException.class, () -> KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS));
}
Aggregations