use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener 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;
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener 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;
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class KafkaCluster method getVolumeMounts.
private List<VolumeMount> getVolumeMounts() {
List<VolumeMount> volumeMountList = new ArrayList<>();
volumeMountList.addAll(VolumeUtils.createVolumeMounts(storage, mountPath, false));
volumeMountList.add(createTempDirVolumeMount());
volumeMountList.add(VolumeUtils.createVolumeMount(CLUSTER_CA_CERTS_VOLUME, CLUSTER_CA_CERTS_VOLUME_MOUNT));
volumeMountList.add(VolumeUtils.createVolumeMount(BROKER_CERTS_VOLUME, BROKER_CERTS_VOLUME_MOUNT));
volumeMountList.add(VolumeUtils.createVolumeMount(CLIENT_CA_CERTS_VOLUME, CLIENT_CA_CERTS_VOLUME_MOUNT));
volumeMountList.add(VolumeUtils.createVolumeMount(logAndMetricsConfigVolumeName, logAndMetricsConfigMountPath));
volumeMountList.add(VolumeUtils.createVolumeMount("ready-files", "/var/opt/kafka"));
if (rack != null || isExposedWithNodePort()) {
volumeMountList.add(VolumeUtils.createVolumeMount(INIT_VOLUME_NAME, INIT_VOLUME_MOUNT));
}
for (GenericKafkaListener listener : listeners) {
String identifier = ListenersUtils.identifier(listener);
if (listener.isTls() && listener.getConfiguration() != null && listener.getConfiguration().getBrokerCertChainAndKey() != null) {
volumeMountList.add(VolumeUtils.createVolumeMount("custom-" + identifier + "-certs", "/opt/kafka/certificates/custom-" + identifier + "-certs"));
}
if (isListenerWithOAuth(listener)) {
KafkaListenerAuthenticationOAuth oauth = (KafkaListenerAuthenticationOAuth) listener.getAuth();
volumeMountList.addAll(AuthenticationUtils.configureOauthCertificateVolumeMounts("oauth-" + identifier, oauth.getTlsTrustedCertificates(), OAUTH_TRUSTED_CERTS_BASE_VOLUME_MOUNT + "/oauth-" + identifier + "-certs"));
}
if (isListenerWithCustomAuth(listener)) {
KafkaListenerAuthenticationCustom custom = (KafkaListenerAuthenticationCustom) listener.getAuth();
volumeMountList.addAll(AuthenticationUtils.configureGenericSecretVolumeMounts("custom-listener-" + identifier, custom.getSecrets(), CUSTOM_AUTHN_SECRETS_VOLUME_MOUNT + "/custom-listener-" + identifier));
}
}
if (authorization instanceof KafkaAuthorizationKeycloak) {
KafkaAuthorizationKeycloak keycloakAuthz = (KafkaAuthorizationKeycloak) authorization;
volumeMountList.addAll(AuthenticationUtils.configureOauthCertificateVolumeMounts("authz-keycloak", keycloakAuthz.getTlsTrustedCertificates(), OAUTH_TRUSTED_CERTS_BASE_VOLUME_MOUNT + "/authz-keycloak-certs"));
}
return volumeMountList;
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.
the class KafkaCluster method getContainerPortList.
private List<ContainerPort> getContainerPortList() {
List<ContainerPort> ports = new ArrayList<>(listeners.size() + 3);
ports.add(createContainerPort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, "TCP"));
ports.add(createContainerPort(REPLICATION_PORT_NAME, REPLICATION_PORT, "TCP"));
for (GenericKafkaListener listener : listeners) {
ports.add(createContainerPort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), "TCP"));
}
if (isMetricsEnabled) {
ports.add(createContainerPort(METRICS_PORT_NAME, METRICS_PORT, "TCP"));
}
return ports;
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener 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;
}
Aggregations