use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class TemplateProviderImpl method loadBridgeIngressKubernetesIngressTemplate.
@Override
public Ingress loadBridgeIngressKubernetesIngressTemplate(BridgeIngress bridgeIngress) {
Ingress ingress = loadYaml(Ingress.class, BRIDGE_INGRESS_KUBERNETES_INGRESS_PATH);
updateMetadata(bridgeIngress, ingress.getMetadata());
return ingress;
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class KubernetesNetworkingService method buildIngress.
private Ingress buildIngress(BridgeIngress bridgeIngress, Service service) {
Ingress ingress = templateProvider.loadBridgeIngressKubernetesIngressTemplate(bridgeIngress);
IngressBackend ingressBackend = new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build();
HTTPIngressPath httpIngressPath = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPath("/" + service.getMetadata().getName() + PATH_REGEX).withPathType("Prefix").build();
IngressRule ingressRule = new IngressRuleBuilder().withHttp(new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build()).build();
IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
ingress.setSpec(ingressSpec);
return ingress;
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.
the class KafkaListenersReconciler method ingressesV1Beta1Ready.
/**
* Makes sure all ingresses are ready and collects their addresses for Statuses,
* certificates and advertised addresses. This method for all ingresses:
* 1) Checks if the bootstrap ingress has been provisioned (has a loadbalancer address)
* 2) Collects the relevant addresses and stores them for use in certificates and in CR status
* 3) Checks it the broker ingresses have been provisioned (have an address)
* 4) Collects the route addresses for certificates and advertised hostnames
*
* @return Future which completes when all Ingresses are ready and their addresses are collected
*/
protected Future<Void> ingressesV1Beta1Ready() {
if (pfa.hasIngressV1()) {
return Future.succeededFuture();
}
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(kafka.getListeners());
// Has to use Raw type because of the CompositeFuture
@SuppressWarnings({ "rawtypes" }) List<Future> listenerFutures = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String bootstrapIngressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(reconciliation.name(), listener);
Future<Void> perListenerFut = ingressV1Beta1Operator.hasIngressAddress(reconciliation, reconciliation.namespace(), bootstrapIngressName, 1_000, operationTimeoutMs).compose(res -> {
String bootstrapAddress = listener.getConfiguration().getBootstrap().getHost();
LOGGER.debugCr(reconciliation, "Using address {} for v1beta1 Ingress {}", bootstrapAddress, bootstrapIngressName);
result.bootstrapDnsNames.add(bootstrapAddress);
ListenerStatus ls = new ListenerStatusBuilder().withName(listener.getName()).withAddresses(new ListenerAddressBuilder().withHost(bootstrapAddress).withPort(KafkaCluster.ROUTE_PORT).build()).build();
result.listenerStatuses.add(ls);
// Check if broker ingresses are ready
// Has to use Raw type because of the CompositeFuture
@SuppressWarnings({ "rawtypes" }) List<Future> perPodFutures = new ArrayList<>(kafka.getReplicas());
for (int pod = 0; pod < kafka.getReplicas(); pod++) {
perPodFutures.add(ingressV1Beta1Operator.hasIngressAddress(reconciliation, reconciliation.namespace(), ListenersUtils.backwardsCompatibleBrokerServiceName(reconciliation.name(), pod, listener), 1_000, operationTimeoutMs));
}
return CompositeFuture.join(perPodFutures);
}).compose(res -> {
for (int brokerId = 0; brokerId < kafka.getReplicas(); brokerId++) {
final int finalBrokerId = brokerId;
String brokerAddress = listener.getConfiguration().getBrokers().stream().filter(broker -> broker.getBroker() == finalBrokerId).map(GenericKafkaListenerConfigurationBroker::getHost).findAny().orElse(null);
LOGGER.debugCr(reconciliation, "Using address {} for v1beta1 Ingress {}", brokerAddress, ListenersUtils.backwardsCompatibleBrokerServiceName(reconciliation.name(), brokerId, listener));
result.brokerDnsNames.computeIfAbsent(brokerId, k -> new HashSet<>(2)).add(brokerAddress);
String advertisedHostname = ListenersUtils.brokerAdvertisedHost(listener, finalBrokerId);
if (advertisedHostname != null) {
result.brokerDnsNames.get(finalBrokerId).add(ListenersUtils.brokerAdvertisedHost(listener, finalBrokerId));
}
registerAdvertisedHostname(finalBrokerId, listener, brokerAddress);
registerAdvertisedPort(finalBrokerId, listener, KafkaCluster.INGRESS_PORT);
}
return Future.succeededFuture();
});
listenerFutures.add(perListenerFut);
}
return CompositeFuture.join(listenerFutures).map((Void) null);
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.
the class KafkaListenersReconciler method ingressesReady.
/**
* Makes sure all ingresses are ready and collects their addresses for Statuses,
* certificates and advertised addresses. This method for all ingresses:
* 1) Checks if the bootstrap ingress has been provisioned (has a loadbalancer address)
* 2) Collects the relevant addresses and stores them for use in certificates and in CR status
* 3) Checks it the broker ingresses have been provisioned (have an address)
* 4) Collects the route addresses for certificates and advertised hostnames
*
* @return Future which completes when all Ingresses are ready and their addresses are collected
*/
protected Future<Void> ingressesReady() {
if (!pfa.hasIngressV1()) {
return Future.succeededFuture();
}
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(kafka.getListeners());
// Has to use Raw type because of the CompositeFuture
@SuppressWarnings({ "rawtypes" }) List<Future> listenerFutures = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String bootstrapIngressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(reconciliation.name(), listener);
Future<Void> perListenerFut = ingressOperator.hasIngressAddress(reconciliation, reconciliation.namespace(), bootstrapIngressName, 1_000, operationTimeoutMs).compose(res -> {
String bootstrapAddress = listener.getConfiguration().getBootstrap().getHost();
LOGGER.debugCr(reconciliation, "Using address {} for Ingress {}", bootstrapAddress, bootstrapIngressName);
result.bootstrapDnsNames.add(bootstrapAddress);
ListenerStatus ls = new ListenerStatusBuilder().withName(listener.getName()).withAddresses(new ListenerAddressBuilder().withHost(bootstrapAddress).withPort(KafkaCluster.ROUTE_PORT).build()).build();
result.listenerStatuses.add(ls);
// Check if broker ingresses are ready
// Has to use Raw type because of the CompositeFuture
@SuppressWarnings({ "rawtypes" }) List<Future> perPodFutures = new ArrayList<>(kafka.getReplicas());
for (int pod = 0; pod < kafka.getReplicas(); pod++) {
perPodFutures.add(ingressOperator.hasIngressAddress(reconciliation, reconciliation.namespace(), ListenersUtils.backwardsCompatibleBrokerServiceName(reconciliation.name(), pod, listener), 1_000, operationTimeoutMs));
}
return CompositeFuture.join(perPodFutures);
}).compose(res -> {
for (int brokerId = 0; brokerId < kafka.getReplicas(); brokerId++) {
final int finalBrokerId = brokerId;
String brokerAddress = listener.getConfiguration().getBrokers().stream().filter(broker -> broker.getBroker() == finalBrokerId).map(GenericKafkaListenerConfigurationBroker::getHost).findAny().orElse(null);
LOGGER.debugCr(reconciliation, "Using address {} for Ingress {}", brokerAddress, ListenersUtils.backwardsCompatibleBrokerServiceName(reconciliation.name(), brokerId, listener));
result.brokerDnsNames.computeIfAbsent(brokerId, k -> new HashSet<>(2)).add(brokerAddress);
String advertisedHostname = ListenersUtils.brokerAdvertisedHost(listener, finalBrokerId);
if (advertisedHostname != null) {
result.brokerDnsNames.get(finalBrokerId).add(ListenersUtils.brokerAdvertisedHost(listener, finalBrokerId));
}
registerAdvertisedHostname(finalBrokerId, listener, brokerAddress);
registerAdvertisedPort(finalBrokerId, listener, KafkaCluster.INGRESS_PORT);
}
return Future.succeededFuture();
});
listenerFutures.add(perListenerFut);
}
return CompositeFuture.join(listenerFutures).map((Void) null);
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi 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;
}
Aggregations