Search in sources :

Example 1 with ExternalTrafficPolicy

use of io.strimzi.api.kafka.model.template.ExternalTrafficPolicy in project strimzi by strimzi.

the class KafkaCluster method generateExternalServices.

/**
 * Generates list of service for pod. These services are used for exposing it externally.
 *
 * @param pod Number of the pod for which this service should be generated
 * @return The list with generated Services
 */
public List<Service> generateExternalServices(int pod) {
    List<GenericKafkaListener> externalListeners = ListenersUtils.externalListeners(listeners);
    List<Service> services = new ArrayList<>(externalListeners.size());
    for (GenericKafkaListener listener : externalListeners) {
        String serviceName = ListenersUtils.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
        List<ServicePort> ports = Collections.singletonList(createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.brokerNodePort(listener, pod), "TCP"));
        Labels selector = getSelectorLabels().withStatefulSetPod(kafkaPodName(cluster, pod));
        Service service = createService(serviceName, ListenersUtils.serviceType(listener), ports, getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templatePerPodServiceLabels, ListenersUtils.brokerLabels(listener, pod))), selector, Util.mergeLabelsOrAnnotations(ListenersUtils.brokerAnnotations(listener, pod), templatePerPodServiceAnnotations), ListenersUtils.ipFamilyPolicy(listener), ListenersUtils.ipFamilies(listener));
        if (KafkaListenerType.LOADBALANCER == listener.getType()) {
            String loadBalancerIP = ListenersUtils.brokerLoadBalancerIP(listener, pod);
            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) Labels(io.strimzi.operator.common.model.Labels) ExternalTrafficPolicy(io.strimzi.api.kafka.model.template.ExternalTrafficPolicy)

Example 2 with ExternalTrafficPolicy

use of io.strimzi.api.kafka.model.template.ExternalTrafficPolicy 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 3 with ExternalTrafficPolicy

use of io.strimzi.api.kafka.model.template.ExternalTrafficPolicy in project strimzi 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 4 with ExternalTrafficPolicy

use of io.strimzi.api.kafka.model.template.ExternalTrafficPolicy in project strimzi-kafka-operator by strimzi.

the class KafkaCluster method generateExternalServices.

/**
 * Generates list of service for pod. These services are used for exposing it externally.
 *
 * @param pod Number of the pod for which this service should be generated
 * @return The list with generated Services
 */
public List<Service> generateExternalServices(int pod) {
    List<GenericKafkaListener> externalListeners = ListenersUtils.externalListeners(listeners);
    List<Service> services = new ArrayList<>(externalListeners.size());
    for (GenericKafkaListener listener : externalListeners) {
        String serviceName = ListenersUtils.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
        List<ServicePort> ports = Collections.singletonList(createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.brokerNodePort(listener, pod), "TCP"));
        Labels selector = getSelectorLabels().withStatefulSetPod(kafkaPodName(cluster, pod));
        Service service = createService(serviceName, ListenersUtils.serviceType(listener), ports, getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templatePerPodServiceLabels, ListenersUtils.brokerLabels(listener, pod))), selector, Util.mergeLabelsOrAnnotations(ListenersUtils.brokerAnnotations(listener, pod), templatePerPodServiceAnnotations), ListenersUtils.ipFamilyPolicy(listener), ListenersUtils.ipFamilies(listener));
        if (KafkaListenerType.LOADBALANCER == listener.getType()) {
            String loadBalancerIP = ListenersUtils.brokerLoadBalancerIP(listener, pod);
            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) Labels(io.strimzi.operator.common.model.Labels) ExternalTrafficPolicy(io.strimzi.api.kafka.model.template.ExternalTrafficPolicy)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)4 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)4 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)4 ExternalTrafficPolicy (io.strimzi.api.kafka.model.template.ExternalTrafficPolicy)4 ArrayList (java.util.ArrayList)4 Labels (io.strimzi.operator.common.model.Labels)2