Search in sources :

Example 91 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator 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;
}
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)

Example 92 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator 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;
}
Also used : ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)

Example 93 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator by strimzi.

the class KafkaCluster method generateExternalIngressesV1Beta1.

/**
 * 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<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> generateExternalIngressesV1Beta1(int pod) {
    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.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
        String host = ListenersUtils.brokerHost(listener, pod);
        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(ingressName).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(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 : ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)

Example 94 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator by strimzi.

the class IngressV1Beta1Operator method isIngressAddressReady.

/**
 * Checks if the Ingress already has assigned ingress address.
 *
 * @param namespace The namespace.
 * @param name The route name.
 * @return Whether the Ingress already has assigned ingress address.
 */
public boolean isIngressAddressReady(String namespace, String name) {
    Resource<Ingress> resourceOp = operation().inNamespace(namespace).withName(name);
    Ingress resource = resourceOp.get();
    if (resource != null && resource.getStatus() != null && resource.getStatus().getLoadBalancer() != null && resource.getStatus().getLoadBalancer().getIngress() != null && resource.getStatus().getLoadBalancer().getIngress().size() > 0) {
        if (resource.getStatus().getLoadBalancer().getIngress().get(0).getHostname() != null || resource.getStatus().getLoadBalancer().getIngress().get(0).getIp() != null) {
            return true;
        }
    }
    return false;
}
Also used : Ingress(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress)

Example 95 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project keycloak by keycloak.

the class KeycloakIngress method newIngress.

private Ingress newIngress() {
    var port = (keycloak.getSpec().isHttp()) ? Constants.KEYCLOAK_HTTP_PORT : Constants.KEYCLOAK_HTTPS_PORT;
    var backendProtocol = (keycloak.getSpec().isHttp()) ? "HTTP" : "HTTPS";
    Ingress ingress = new IngressBuilder().withNewMetadata().withName(getName()).withNamespace(getNamespace()).addToAnnotations("nginx.ingress.kubernetes.io/backend-protocol", backendProtocol).endMetadata().withNewSpec().withNewDefaultBackend().withNewService().withName(keycloak.getMetadata().getName() + Constants.KEYCLOAK_SERVICE_SUFFIX).withNewPort().withNumber(port).endPort().endService().endDefaultBackend().addNewRule().withNewHttp().addNewPath().withPath("/").withPathType("ImplementationSpecific").withNewBackend().withNewService().withName(keycloak.getMetadata().getName() + Constants.KEYCLOAK_SERVICE_SUFFIX).withNewPort().withNumber(port).endPort().endService().endBackend().endPath().endHttp().endRule().endSpec().build();
    if (!keycloak.getSpec().isHostnameDisabled()) {
        ingress.getSpec().getRules().get(0).setHost(keycloak.getSpec().getHostname());
    }
    return ingress;
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

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