Search in sources :

Example 66 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.

the class KafkaCluster method generateExternalBootstrapIngresses.

/**
 * Generates a list of bootstrap ingress which can be used to bootstrap clients outside of Kubernetes.
 *
 * @return The list of generated Ingresses
 */
public List<Ingress> generateExternalBootstrapIngresses() {
    List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
    List<Ingress> ingresses = new ArrayList<>(ingressListeners.size());
    for (GenericKafkaListener listener : ingressListeners) {
        String ingressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(cluster, listener);
        String serviceName = ListenersUtils.backwardsCompatibleBootstrapServiceName(cluster, listener);
        String host = ListenersUtils.bootstrapHost(listener);
        String ingressClass = ListenersUtils.ingressClass(listener);
        HTTPIngressPath path = new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withNewBackend().withNewService().withName(serviceName).withNewPort().withNumber(listener.getPort()).endPort().endService().endBackend().build();
        IngressRule rule = new IngressRuleBuilder().withHost(host).withNewHttp().withPaths(path).endHttp().build();
        IngressTLS tls = new IngressTLSBuilder().withHosts(host).build();
        Ingress ingress = new IngressBuilder().withNewMetadata().withName(ingressName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templateExternalBootstrapIngressLabels, ListenersUtils.bootstrapLabels(listener))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templateExternalBootstrapIngressAnnotations, ListenersUtils.bootstrapAnnotations(listener))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withIngressClassName(ingressClass).withRules(rule).withTls(tls).endSpec().build();
        ingresses.add(ingress);
    }
    return ingresses;
}
Also used : NetworkPolicyIngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRuleBuilder) IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) NetworkPolicyIngressRule(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRule) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder) IngressTLS(io.fabric8.kubernetes.api.model.networking.v1.IngressTLS)

Example 67 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.

the class KafkaCluster method generateExternalBootstrapIngressesV1Beta1.

/**
 * Generates a list of bootstrap ingress which can be used to bootstrap clients outside of Kubernetes.
 *
 * @return The list of generated Ingresses
 */
public List<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> generateExternalBootstrapIngressesV1Beta1() {
    List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
    List<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> ingresses = new ArrayList<>(ingressListeners.size());
    for (GenericKafkaListener listener : ingressListeners) {
        String ingressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(cluster, listener);
        String serviceName = ListenersUtils.backwardsCompatibleBootstrapServiceName(cluster, listener);
        String host = ListenersUtils.bootstrapHost(listener);
        String ingressClass = ListenersUtils.ingressClass(listener);
        io.fabric8.kubernetes.api.model.networking.v1beta1.HTTPIngressPath path = new io.fabric8.kubernetes.api.model.networking.v1beta1.HTTPIngressPathBuilder().withPath("/").withNewBackend().withNewServicePort(listener.getPort()).withServiceName(serviceName).endBackend().build();
        io.fabric8.kubernetes.api.model.networking.v1beta1.IngressRule rule = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressRuleBuilder().withHost(host).withNewHttp().withPaths(path).endHttp().build();
        io.fabric8.kubernetes.api.model.networking.v1beta1.IngressTLS tls = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressTLSBuilder().withHosts(host).build();
        io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingress = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder().withNewMetadata().withName(ingressName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templateExternalBootstrapIngressLabels, ListenersUtils.bootstrapLabels(listener))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templateExternalBootstrapIngressAnnotations, ListenersUtils.bootstrapAnnotations(listener))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withIngressClassName(ingressClass).withRules(rule).withTls(tls).endSpec().build();
        ingresses.add(ingress);
    }
    return ingresses;
}
Also used : ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)

Example 68 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.

the class KafkaListenersReconciler method ingresses.

/**
 * Makes sure all desired ingresses are updated and the rest is deleted.
 *
 * @return  Future which completes when all ingresses are created or deleted.
 */
protected Future<Void> ingresses() {
    if (!pfa.hasIngressV1()) {
        return Future.succeededFuture();
    }
    List<Ingress> ingresses = new ArrayList<>(kafka.generateExternalBootstrapIngresses());
    int replicas = kafka.getReplicas();
    for (int i = 0; i < replicas; i++) {
        ingresses.addAll(kafka.generateExternalIngresses(i));
    }
    return ingressOperator.listAsync(reconciliation.namespace(), kafka.getSelectorLabels()).compose(existingIngresses -> {
        // Has to use Raw type because of the CompositeFuture
        @SuppressWarnings({ "rawtypes" }) List<Future> ingressFutures = new ArrayList<>(ingresses.size());
        List<String> existingIngressNames = existingIngresses.stream().map(ingress -> ingress.getMetadata().getName()).collect(Collectors.toList());
        LOGGER.debugCr(reconciliation, "Reconciling existing Ingresses {} against the desired ingresses", existingIngressNames);
        // Update desired ingresses
        for (Ingress ingress : ingresses) {
            String ingressName = ingress.getMetadata().getName();
            existingIngressNames.remove(ingressName);
            ingressFutures.add(ingressOperator.reconcile(reconciliation, reconciliation.namespace(), ingressName, ingress));
        }
        LOGGER.debugCr(reconciliation, "Ingresses {} should be deleted", existingIngressNames);
        // Delete ingresses which match our selector but are not desired anymore
        for (String ingressName : existingIngressNames) {
            ingressFutures.add(ingressOperator.reconcile(reconciliation, reconciliation.namespace(), ingressName, null));
        }
        return CompositeFuture.join(ingressFutures).map((Void) null);
    });
}
Also used : X509Certificate(java.security.cert.X509Certificate) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) IngressV1Beta1Operator(io.strimzi.operator.common.operator.resource.IngressV1Beta1Operator) IngressOperator(io.strimzi.operator.common.operator.resource.IngressOperator) HashMap(java.util.HashMap) ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) CompositeFuture(io.vertx.core.CompositeFuture) Route(io.fabric8.openshift.api.model.Route) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Ca(io.strimzi.operator.cluster.model.Ca) Locale(java.util.Locale) Map(java.util.Map) Service(io.fabric8.kubernetes.api.model.Service) CertAndKeySecretSource(io.strimzi.api.kafka.model.CertAndKeySecretSource) ListenersUtils(io.strimzi.operator.cluster.model.ListenersUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) DnsNameGenerator(io.strimzi.operator.cluster.model.DnsNameGenerator) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) Base64(java.util.Base64) List(java.util.List) Util(io.strimzi.operator.common.Util) NodeAddressType(io.strimzi.api.kafka.model.listener.NodeAddressType) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Secret(io.fabric8.kubernetes.api.model.Secret) RouteOperator(io.strimzi.operator.common.operator.resource.RouteOperator) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CertificateEncodingException(java.security.cert.CertificateEncodingException) ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future)

Example 69 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.

the class KafkaListenerReconcilerIngressV1Beta1Test method testIngressV1Beta1.

@Test
public void testIngressV1Beta1(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_16), 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(0));
        assertThat(ingressV1Beta1Captor.getAllValues().size(), is(4));
        verify(mockIngressOps, never()).list(any(), any());
        verify(mockIngressOps, never()).reconcile(any(), any(), any(), any());
        verify(mockIngressOps, never()).hasIngressAddress(any(), any(), any(), anyLong(), anyLong());
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IngressV1Beta1Operator(io.strimzi.operator.common.operator.resource.IngressV1Beta1Operator) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) IngressOperator(io.strimzi.operator.common.operator.resource.IngressOperator) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections.emptyList(java.util.Collections.emptyList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito.never(org.mockito.Mockito.never) Labels(io.strimzi.operator.common.model.Labels) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) RouteOperator(io.strimzi.operator.common.operator.resource.RouteOperator) Checkpoint(io.vertx.junit5.Checkpoint) Kafka(io.strimzi.api.kafka.model.Kafka) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) Kafka(io.strimzi.api.kafka.model.Kafka) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) IngressV1Beta1Operator(io.strimzi.operator.common.operator.resource.IngressV1Beta1Operator) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Labels(io.strimzi.operator.common.model.Labels) IngressOperator(io.strimzi.operator.common.operator.resource.IngressOperator) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Test(org.junit.jupiter.api.Test)

Example 70 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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(KafkaResources.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(KafkaResources.kafkaStatefulSetName(cluster) + "-" + i));
        assertThat(srv.getSpec().getType(), is("ClusterIP"));
        assertThat(srv.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), is(KafkaResources.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(KafkaResources.bootstrapServiceName(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(KafkaResources.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(KafkaResources.bootstrapServiceName(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(KafkaResources.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(KafkaResources.kafkaStatefulSetName(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(KafkaResources.kafkaStatefulSetName(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(KafkaResources.kafkaStatefulSetName(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(KafkaResources.kafkaStatefulSetName(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

Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)158 Service (io.fabric8.kubernetes.api.model.Service)47 Test (org.junit.jupiter.api.Test)42 Test (org.testng.annotations.Test)36 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)31 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)28 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)25 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 ArrayList (java.util.ArrayList)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)21 HashMap (java.util.HashMap)21 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)16 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)14 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)14 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)14 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)14 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)14 Reconciliation (io.strimzi.operator.common.Reconciliation)14 IngressOperator (io.strimzi.operator.common.operator.resource.IngressOperator)14