Search in sources :

Example 56 with GenericKafkaListener

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

the class KafkaClusterOAuthValidationTest method testOAuthAuthzWithoutAuthn.

@ParallelTest
public void testOAuthAuthzWithoutAuthn() {
    assertThrows(InvalidResourceException.class, () -> {
        List<GenericKafkaListener> listeners = asList(new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(new KafkaListenerAuthenticationScramSha512Builder().build()).build());
        Kafka kafkaAssembly = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().withNewSpec().withNewKafka().withReplicas(3).withStorage(new EphemeralStorage()).withListeners(listeners).withAuthorization(new KafkaAuthorizationKeycloakBuilder().withTokenEndpointUri("http://token-endpoint").withClientId("my-client-id").withDelegateToKafkaAcls(true).withGrantsRefreshPeriodSeconds(60).withGrantsRefreshPoolSize(5).withSuperUsers("alice", "CN=alice").build()).endKafka().withNewZookeeper().withReplicas(3).withStorage(new EphemeralStorage()).endZookeeper().endSpec().build();
        KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    });
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) KafkaAuthorizationKeycloakBuilder(io.strimzi.api.kafka.model.KafkaAuthorizationKeycloakBuilder) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) KafkaListenerAuthenticationScramSha512Builder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationScramSha512Builder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 57 with GenericKafkaListener

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

the class KafkaCluster method generateExternalRoutes.

/**
 * Generates list of routes for pod. These routes are used for exposing it externally using OpenShift Routes.
 *
 * @param pod Number of the pod for which this route should be generated
 * @return The list with generated Routes
 */
public List<Route> generateExternalRoutes(int pod) {
    List<GenericKafkaListener> routeListeners = ListenersUtils.routeListeners(listeners);
    List<Route> routes = new ArrayList<>(routeListeners.size());
    for (GenericKafkaListener listener : routeListeners) {
        String routeName = ListenersUtils.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
        Route route = new RouteBuilder().withNewMetadata().withName(routeName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templatePerPodRouteLabels, ListenersUtils.brokerLabels(listener, pod))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(templatePerPodRouteAnnotations, ListenersUtils.brokerAnnotations(listener, pod))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withNewTo().withKind("Service").withName(routeName).endTo().withNewPort().withNewTargetPort(listener.getPort()).endPort().withNewTls().withTermination("passthrough").endTls().endSpec().build();
        String host = ListenersUtils.brokerHost(listener, pod);
        if (host != null) {
            route.getSpec().setHost(host);
        }
        routes.add(route);
    }
    return routes;
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) ArrayList(java.util.ArrayList) Route(io.fabric8.openshift.api.model.Route)

Example 58 with GenericKafkaListener

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

the class KafkaCluster method generateExternalIngresses.

/**
 * Generates list of ingress for pod. This ingress is used for exposing it externally using Nginx Ingress.
 *
 * @param pod Number of the pod for which this ingress should be generated
 * @return The list of generated Ingresses
 */
public List<Ingress> generateExternalIngresses(int pod) {
    List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
    List<Ingress> ingresses = new ArrayList<>(ingressListeners.size());
    for (GenericKafkaListener listener : ingressListeners) {
        String ingressName = ListenersUtils.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
        String host = ListenersUtils.brokerHost(listener, pod);
        String ingressClass = ListenersUtils.ingressClass(listener);
        HTTPIngressPath path = new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withNewBackend().withNewService().withName(ingressName).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(templatePerPodIngressLabels, ListenersUtils.brokerLabels(listener, pod))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templatePerPodIngressAnnotations, ListenersUtils.brokerAnnotations(listener, pod))).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 59 with GenericKafkaListener

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

the class KafkaCluster method generateExternalBootstrapServices.

/**
 * Generates list of external bootstrap services. These services are used for exposing it externally.
 * Separate services are used to make sure that we do expose the right port in the right way.
 *
 * @return The list with generated Services
 */
public List<Service> generateExternalBootstrapServices() {
    List<GenericKafkaListener> externalListeners = ListenersUtils.externalListeners(listeners);
    List<Service> services = new ArrayList<>(externalListeners.size());
    for (GenericKafkaListener listener : externalListeners) {
        if (ListenersUtils.skipCreateBootstrapService(listener)) {
            continue;
        }
        String serviceName = ListenersUtils.backwardsCompatibleBootstrapServiceName(cluster, listener);
        List<ServicePort> ports = Collections.singletonList(createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.bootstrapNodePort(listener), "TCP"));
        Service service = createService(serviceName, ListenersUtils.serviceType(listener), ports, getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templateExternalBootstrapServiceLabels, ListenersUtils.bootstrapLabels(listener))), getSelectorLabels(), Util.mergeLabelsOrAnnotations(ListenersUtils.bootstrapAnnotations(listener), templateExternalBootstrapServiceAnnotations), ListenersUtils.ipFamilyPolicy(listener), ListenersUtils.ipFamilies(listener));
        if (KafkaListenerType.LOADBALANCER == listener.getType()) {
            String loadBalancerIP = ListenersUtils.bootstrapLoadBalancerIP(listener);
            if (loadBalancerIP != null) {
                service.getSpec().setLoadBalancerIP(loadBalancerIP);
            }
            List<String> loadBalancerSourceRanges = ListenersUtils.loadBalancerSourceRanges(listener);
            if (loadBalancerSourceRanges != null && !loadBalancerSourceRanges.isEmpty()) {
                service.getSpec().setLoadBalancerSourceRanges(loadBalancerSourceRanges);
            }
            List<String> finalizers = ListenersUtils.finalizers(listener);
            if (finalizers != null && !finalizers.isEmpty()) {
                service.getMetadata().setFinalizers(finalizers);
            }
        }
        if (KafkaListenerType.LOADBALANCER == listener.getType() || KafkaListenerType.NODEPORT == listener.getType()) {
            ExternalTrafficPolicy etp = ListenersUtils.externalTrafficPolicy(listener);
            if (etp != null) {
                service.getSpec().setExternalTrafficPolicy(etp.toValue());
            } else {
                service.getSpec().setExternalTrafficPolicy(ExternalTrafficPolicy.CLUSTER.toValue());
            }
        }
        services.add(service);
    }
    return services;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ExternalTrafficPolicy(io.strimzi.api.kafka.model.template.ExternalTrafficPolicy)

Example 60 with GenericKafkaListener

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

the class KafkaCluster method getServicePorts.

/**
 * Generates ports for bootstrap service.
 * The bootstrap service contains only the client interfaces.
 * Not the replication interface which doesn't need bootstrap service.
 *
 * @return List with generated ports
 */
private List<ServicePort> getServicePorts() {
    List<GenericKafkaListener> internalListeners = ListenersUtils.internalListeners(listeners);
    List<ServicePort> ports = new ArrayList<>(internalListeners.size() + 1);
    ports.add(createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, "TCP"));
    for (GenericKafkaListener listener : internalListeners) {
        ports.add(createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), "TCP"));
    }
    return ports;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) ArrayList(java.util.ArrayList)

Aggregations

GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)160 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)116 ParallelTest (io.strimzi.test.annotations.ParallelTest)102 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)50 ArrayList (java.util.ArrayList)38 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)18 Matchers.containsString (org.hamcrest.Matchers.containsString)16 KafkaListenerAuthenticationOAuth (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuth)12 KafkaListenerAuthenticationOAuthBuilder (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder)12 Kafka (io.strimzi.api.kafka.model.Kafka)10 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)8 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)8 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 NetworkPolicyIngressRule (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRule)6 NetworkPolicyIngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRuleBuilder)6 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)6