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);
});
}
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;
}
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;
}
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;
}
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;
}
Aggregations