Search in sources :

Example 81 with Ingress

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;
}
Also used : BridgeIngress(com.redhat.service.smartevents.shard.operator.resources.BridgeIngress) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 82 with 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;
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) BridgeIngress(com.redhat.service.smartevents.shard.operator.resources.BridgeIngress) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 83 with 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);
}
Also used : X509Certificate(java.security.cert.X509Certificate) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) IngressV1Beta1Operator(io.strimzi.operator.common.operator.resource.IngressV1Beta1Operator) IngressOperator(io.strimzi.operator.common.operator.resource.IngressOperator) HashMap(java.util.HashMap) ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) CompositeFuture(io.vertx.core.CompositeFuture) Route(io.fabric8.openshift.api.model.Route) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Ca(io.strimzi.operator.cluster.model.Ca) Locale(java.util.Locale) Map(java.util.Map) Service(io.fabric8.kubernetes.api.model.Service) CertAndKeySecretSource(io.strimzi.api.kafka.model.CertAndKeySecretSource) ListenersUtils(io.strimzi.operator.cluster.model.ListenersUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) DnsNameGenerator(io.strimzi.operator.cluster.model.DnsNameGenerator) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) Base64(java.util.Base64) List(java.util.List) Util(io.strimzi.operator.common.Util) NodeAddressType(io.strimzi.api.kafka.model.listener.NodeAddressType) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Secret(io.fabric8.kubernetes.api.model.Secret) RouteOperator(io.strimzi.operator.common.operator.resource.RouteOperator) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CertificateEncodingException(java.security.cert.CertificateEncodingException) ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ArrayList(java.util.ArrayList) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) HashSet(java.util.HashSet)

Example 84 with Ingress

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);
}
Also used : X509Certificate(java.security.cert.X509Certificate) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) IngressV1Beta1Operator(io.strimzi.operator.common.operator.resource.IngressV1Beta1Operator) IngressOperator(io.strimzi.operator.common.operator.resource.IngressOperator) HashMap(java.util.HashMap) ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) CompositeFuture(io.vertx.core.CompositeFuture) Route(io.fabric8.openshift.api.model.Route) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Ca(io.strimzi.operator.cluster.model.Ca) Locale(java.util.Locale) Map(java.util.Map) Service(io.fabric8.kubernetes.api.model.Service) CertAndKeySecretSource(io.strimzi.api.kafka.model.CertAndKeySecretSource) ListenersUtils(io.strimzi.operator.cluster.model.ListenersUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) DnsNameGenerator(io.strimzi.operator.cluster.model.DnsNameGenerator) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) Base64(java.util.Base64) List(java.util.List) Util(io.strimzi.operator.common.Util) NodeAddressType(io.strimzi.api.kafka.model.listener.NodeAddressType) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Secret(io.fabric8.kubernetes.api.model.Secret) RouteOperator(io.strimzi.operator.common.operator.resource.RouteOperator) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CertificateEncodingException(java.security.cert.CertificateEncodingException) ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ArrayList(java.util.ArrayList) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) HashSet(java.util.HashSet)

Example 85 with Ingress

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

Aggregations

Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)158 Service (io.fabric8.kubernetes.api.model.Service)47 Test (org.junit.jupiter.api.Test)42 Test (org.testng.annotations.Test)36 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)31 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)28 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)25 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 ArrayList (java.util.ArrayList)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)21 HashMap (java.util.HashMap)21 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)16 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)14 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)14 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)14 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)14 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)14 Reconciliation (io.strimzi.operator.common.Reconciliation)14 IngressOperator (io.strimzi.operator.common.operator.resource.IngressOperator)14