Search in sources :

Example 6 with GenericKafkaListenerConfigurationBroker

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

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

the class KafkaClusterTest method testExternalIngress.

@ParallelTest
public void testExternalIngress() {
    GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-0.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.com")).withBroker(0).build();
    GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-1.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.com")).withBroker(1).build();
    GenericKafkaListenerConfigurationBroker broker2 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-2.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.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().withNewBootstrap().withHost("my-kafka-bootstrap.com").withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-bootstrap.com")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(broker0, broker1, broker2).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(kc.isExposedWithIngress(), is(true));
    // 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("ClusterIP"));
    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, "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("ClusterIP"));
        assertThat(srv.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), is(KafkaCluster.kafkaPodName(cluster, i)));
        assertThat(srv.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, "TCP"))));
        checkOwnerReference(kc.createOwnerReference(), srv);
    }
    // Check bootstrap ingress
    Ingress bing = kc.generateExternalBootstrapIngresses().get(0);
    assertThat(bing.getMetadata().getName(), is(KafkaCluster.serviceName(cluster)));
    assertThat(bing.getSpec().getIngressClassName(), is(nullValue()));
    assertThat(bing.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-bootstrap.com"));
    assertThat(bing.getMetadata().getLabels().get("label"), is("label-value"));
    assertThat(bing.getSpec().getTls().size(), is(1));
    assertThat(bing.getSpec().getTls().get(0).getHosts().size(), is(1));
    assertThat(bing.getSpec().getTls().get(0).getHosts().get(0), is("my-kafka-bootstrap.com"));
    assertThat(bing.getSpec().getRules().size(), is(1));
    assertThat(bing.getSpec().getRules().get(0).getHost(), is("my-kafka-bootstrap.com"));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getName(), is(KafkaCluster.externalBootstrapServiceName(cluster)));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber(), is(9094));
    checkOwnerReference(kc.createOwnerReference(), bing);
    io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress bingV1Beta1 = kc.generateExternalBootstrapIngressesV1Beta1().get(0);
    assertThat(bingV1Beta1.getMetadata().getName(), is(KafkaCluster.serviceName(cluster)));
    assertThat(bingV1Beta1.getSpec().getIngressClassName(), is(nullValue()));
    assertThat(bingV1Beta1.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-bootstrap.com"));
    assertThat(bingV1Beta1.getMetadata().getLabels().get("label"), is("label-value"));
    assertThat(bingV1Beta1.getSpec().getTls().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getTls().get(0).getHosts().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getTls().get(0).getHosts().get(0), is("my-kafka-bootstrap.com"));
    assertThat(bingV1Beta1.getSpec().getRules().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHost(), is("my-kafka-bootstrap.com"));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServiceName(), is(KafkaCluster.externalBootstrapServiceName(cluster)));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServicePort(), is(new IntOrString(9094)));
    checkOwnerReference(kc.createOwnerReference(), bingV1Beta1);
    // Check per pod ingress
    for (int i = 0; i < replicas; i++) {
        Ingress ing = kc.generateExternalIngresses(i).get(0);
        assertThat(ing.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ing.getSpec().getIngressClassName(), is(nullValue()));
        assertThat(ing.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-broker.com"));
        assertThat(ing.getMetadata().getLabels().get("label"), is("label-value"));
        assertThat(ing.getSpec().getTls().size(), is(1));
        assertThat(ing.getSpec().getTls().get(0).getHosts().size(), is(1));
        assertThat(ing.getSpec().getTls().get(0).getHosts().get(0), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ing.getSpec().getRules().size(), is(1));
        assertThat(ing.getSpec().getRules().get(0).getHost(), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber(), is(9094));
        checkOwnerReference(kc.createOwnerReference(), ing);
        io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingV1Beta1 = kc.generateExternalIngressesV1Beta1(i).get(0);
        assertThat(ingV1Beta1.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ingV1Beta1.getSpec().getIngressClassName(), is(nullValue()));
        assertThat(ingV1Beta1.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-broker.com"));
        assertThat(ingV1Beta1.getMetadata().getLabels().get("label"), is("label-value"));
        assertThat(ingV1Beta1.getSpec().getTls().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getTls().get(0).getHosts().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getTls().get(0).getHosts().get(0), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ingV1Beta1.getSpec().getRules().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHost(), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServiceName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServicePort(), is(new IntOrString(9094)));
        checkOwnerReference(kc.createOwnerReference(), ingV1Beta1);
    }
}
Also used : GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Kafka(io.strimzi.api.kafka.model.Kafka) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) Service(io.fabric8.kubernetes.api.model.Service) 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) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 8 with GenericKafkaListenerConfigurationBroker

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker in project strimzi 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();
    try {
        KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
        fail("Expected exception was not thrown");
    } catch (InvalidResourceException e) {
    // pass
    }
}
Also used : 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 9 with GenericKafkaListenerConfigurationBroker

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

the class KafkaStatusTest method testKafkaListenerNodePortAddressInStatusWithOverrides.

@Test
public void testKafkaListenerNodePortAddressInStatusWithOverrides(VertxTestContext context) throws ParseException {
    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(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(broker0, broker1).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    // Mock the KafkaSetOperator
    StatefulSetOperator mockStsOps = supplier.stsOperations;
    when(mockStsOps.getAsync(eq(namespace), eq(KafkaCluster.kafkaClusterName(clusterName)))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
    // Mock the StrimziPodSet operator
    CrdOperator<KubernetesClient, StrimziPodSet, StrimziPodSetList> mockPodSetOps = supplier.strimziPodSetOperator;
    when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    // Mock the ConfigMapOperator
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    when(mockCmOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafkaCluster.generateMetricsAndLogConfigMap(new MetricsAndLogging(null, null))));
    // Mock Pods Operator
    Pod pod0 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
    Pod pod1 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName(clusterName + "-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 Node operator
    NodeOperator mockNodeOps = supplier.nodeOperator;
    when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(getClusterNodes()));
    MockNodePortStatusKafkaAssemblyOperator kao = new MockNodePortStatusKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        assertThat(kafkaCaptor.getValue(), is(notNullValue()));
        assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
        KafkaStatus status = kafkaCaptor.getValue().getStatus();
        assertThat(status.getListeners().size(), is(1));
        assertThat(status.getListeners().get(0).getType(), is("external"));
        assertThat(status.getListeners().get(0).getName(), is("external"));
        List<ListenerAddress> addresses = status.getListeners().get(0).getAddresses();
        assertThat(addresses.size(), is(3));
        List<ListenerAddress> expected = new ArrayList<>();
        expected.add(new ListenerAddressBuilder().withHost("my-address-0").withPort(31234).build());
        expected.add(new ListenerAddressBuilder().withHost("my-address-1").withPort(31234).build());
        expected.add(new ListenerAddressBuilder().withHost("5.124.16.8").withPort(31234).build());
        async.flag();
    });
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) Kafka(io.strimzi.api.kafka.model.Kafka) ArrayList(java.util.ArrayList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ListenerAddress(io.strimzi.api.kafka.model.status.ListenerAddress) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeOperator(io.strimzi.operator.common.operator.resource.NodeOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Labels(io.strimzi.operator.common.model.Labels) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 10 with GenericKafkaListenerConfigurationBroker

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

the class KafkaClusterTest method testExternalIngress.

@ParallelTest
public void testExternalIngress() {
    GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-0.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.com")).withBroker(0).build();
    GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-1.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.com")).withBroker(1).build();
    GenericKafkaListenerConfigurationBroker broker2 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-2.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.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().withNewBootstrap().withHost("my-kafka-bootstrap.com").withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-bootstrap.com")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(broker0, broker1, broker2).endConfiguration().build()).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    assertThat(kc.isExposedWithIngress(), is(true));
    // 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("ClusterIP"));
    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, "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("ClusterIP"));
        assertThat(srv.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), is(KafkaCluster.kafkaPodName(cluster, i)));
        assertThat(srv.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, "TCP"))));
        checkOwnerReference(kc.createOwnerReference(), srv);
    }
    // Check bootstrap ingress
    Ingress bing = kc.generateExternalBootstrapIngresses().get(0);
    assertThat(bing.getMetadata().getName(), is(KafkaCluster.serviceName(cluster)));
    assertThat(bing.getSpec().getIngressClassName(), is(nullValue()));
    assertThat(bing.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-bootstrap.com"));
    assertThat(bing.getMetadata().getLabels().get("label"), is("label-value"));
    assertThat(bing.getSpec().getTls().size(), is(1));
    assertThat(bing.getSpec().getTls().get(0).getHosts().size(), is(1));
    assertThat(bing.getSpec().getTls().get(0).getHosts().get(0), is("my-kafka-bootstrap.com"));
    assertThat(bing.getSpec().getRules().size(), is(1));
    assertThat(bing.getSpec().getRules().get(0).getHost(), is("my-kafka-bootstrap.com"));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getName(), is(KafkaCluster.externalBootstrapServiceName(cluster)));
    assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber(), is(9094));
    checkOwnerReference(kc.createOwnerReference(), bing);
    io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress bingV1Beta1 = kc.generateExternalBootstrapIngressesV1Beta1().get(0);
    assertThat(bingV1Beta1.getMetadata().getName(), is(KafkaCluster.serviceName(cluster)));
    assertThat(bingV1Beta1.getSpec().getIngressClassName(), is(nullValue()));
    assertThat(bingV1Beta1.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-bootstrap.com"));
    assertThat(bingV1Beta1.getMetadata().getLabels().get("label"), is("label-value"));
    assertThat(bingV1Beta1.getSpec().getTls().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getTls().get(0).getHosts().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getTls().get(0).getHosts().get(0), is("my-kafka-bootstrap.com"));
    assertThat(bingV1Beta1.getSpec().getRules().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHost(), is("my-kafka-bootstrap.com"));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServiceName(), is(KafkaCluster.externalBootstrapServiceName(cluster)));
    assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServicePort(), is(new IntOrString(9094)));
    checkOwnerReference(kc.createOwnerReference(), bingV1Beta1);
    // Check per pod ingress
    for (int i = 0; i < replicas; i++) {
        Ingress ing = kc.generateExternalIngresses(i).get(0);
        assertThat(ing.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ing.getSpec().getIngressClassName(), is(nullValue()));
        assertThat(ing.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-broker.com"));
        assertThat(ing.getMetadata().getLabels().get("label"), is("label-value"));
        assertThat(ing.getSpec().getTls().size(), is(1));
        assertThat(ing.getSpec().getTls().get(0).getHosts().size(), is(1));
        assertThat(ing.getSpec().getTls().get(0).getHosts().get(0), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ing.getSpec().getRules().size(), is(1));
        assertThat(ing.getSpec().getRules().get(0).getHost(), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber(), is(9094));
        checkOwnerReference(kc.createOwnerReference(), ing);
        io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingV1Beta1 = kc.generateExternalIngressesV1Beta1(i).get(0);
        assertThat(ingV1Beta1.getMetadata().getName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ingV1Beta1.getSpec().getIngressClassName(), is(nullValue()));
        assertThat(ingV1Beta1.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-broker.com"));
        assertThat(ingV1Beta1.getMetadata().getLabels().get("label"), is("label-value"));
        assertThat(ingV1Beta1.getSpec().getTls().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getTls().get(0).getHosts().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getTls().get(0).getHosts().get(0), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ingV1Beta1.getSpec().getRules().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHost(), is(String.format("my-broker-kafka-%d.com", i)));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServiceName(), is(KafkaCluster.externalServiceName(cluster, i)));
        assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServicePort(), is(new IntOrString(9094)));
        checkOwnerReference(kc.createOwnerReference(), ingV1Beta1);
    }
}
Also used : GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Kafka(io.strimzi.api.kafka.model.Kafka) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) Service(io.fabric8.kubernetes.api.model.Service) 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) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) 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