Search in sources :

Example 1 with IngressBackendBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project fabric8-maven-plugin by fabric8io.

the class IngressEnricher method addIngress.

private void addIngress(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder) {
    ObjectMeta serviceMetadata = serviceBuilder.getMetadata();
    if (serviceMetadata != null && isExposedService(serviceMetadata) && shouldCreateExternalURLForService(serviceBuilder)) {
        String serviceName = serviceMetadata.getName();
        if (!hasIngress(listBuilder, serviceName)) {
            Integer servicePort = getServicePort(serviceBuilder);
            if (servicePort != null) {
                IngressBuilder ingressBuilder = new IngressBuilder().withMetadata(serviceMetadata).withNewSpec().endSpec();
                // removing `expose : true` label from metadata.
                ingressBuilder.withNewMetadataLike(removeExposeLabel(ingressBuilder.getMetadata()));
                if (StringUtils.isNotBlank(routeDomainPostfix)) {
                    routeDomainPostfix = serviceName + "." + FileUtil.stripPrefix(routeDomainPostfix, ".");
                    ingressBuilder = ingressBuilder.withSpec(new IngressSpecBuilder().addNewRule().withHost(routeDomainPostfix).withNewHttp().withPaths(new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(KubernetesHelper.createIntOrString(getServicePort(serviceBuilder))).endBackend().build()).endHttp().endRule().build());
                } else {
                    ingressBuilder.withSpec(new IngressSpecBuilder().withBackend(new IngressBackendBuilder().withNewServiceName(serviceName).withNewServicePort(getServicePort(serviceBuilder)).build()).build());
                }
                listBuilder.addToItems(ingressBuilder.build());
            }
        }
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBackendBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.extensions.IngressSpecBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.extensions.HTTPIngressPathBuilder)

Example 2 with IngressBackendBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project che-server by eclipse-che.

the class ExternalServerIngressBuilder method build.

public Ingress build() {
    ServiceBackendPortBuilder serviceBackendPortBuilder = new ServiceBackendPortBuilder();
    // cannot set both port and name
    if (!isNullOrEmpty(servicePortName)) {
        serviceBackendPortBuilder.withName(servicePortName);
    } else if (servicePort != null) {
        serviceBackendPortBuilder.withNumber(servicePort);
    }
    IngressServiceBackend ingressServiceBackend = new IngressServiceBackendBuilder().withPort(serviceBackendPortBuilder.build()).withName(serviceName).build();
    IngressBackend ingressBackend = new IngressBackendBuilder().withService(ingressServiceBackend).build();
    HTTPIngressPathBuilder httpIngressPathBuilder = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPathType(INGRESS_PATH_TYPE);
    if (!isNullOrEmpty(path)) {
        httpIngressPathBuilder.withPath(path);
    }
    HTTPIngressPath httpIngressPath = httpIngressPathBuilder.build();
    HTTPIngressRuleValue httpIngressRuleValue = new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build();
    IngressRuleBuilder ingressRuleBuilder = new IngressRuleBuilder().withHttp(httpIngressRuleValue);
    if (!isNullOrEmpty(host)) {
        ingressRuleBuilder.withHost(host);
    }
    IngressRule ingressRule = ingressRuleBuilder.build();
    IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
    Map<String, String> ingressAnnotations = new HashMap<>(annotations);
    ingressAnnotations.putAll(Annotations.newSerializer().servers(serversConfigs).machineName(machineName).annotations());
    return new IngressBuilder().withSpec(ingressSpec).withMetadata(new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).withLabels(labels).build()).build();
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HashMap(java.util.HashMap) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 3 with IngressBackendBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project devspaces-images by redhat-developer.

the class ExternalServerIngressBuilder method build.

public Ingress build() {
    ServiceBackendPortBuilder serviceBackendPortBuilder = new ServiceBackendPortBuilder();
    // cannot set both port and name
    if (!isNullOrEmpty(servicePortName)) {
        serviceBackendPortBuilder.withName(servicePortName);
    } else if (servicePort != null) {
        serviceBackendPortBuilder.withNumber(servicePort);
    }
    IngressServiceBackend ingressServiceBackend = new IngressServiceBackendBuilder().withPort(serviceBackendPortBuilder.build()).withName(serviceName).build();
    IngressBackend ingressBackend = new IngressBackendBuilder().withService(ingressServiceBackend).build();
    HTTPIngressPathBuilder httpIngressPathBuilder = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPathType(INGRESS_PATH_TYPE);
    if (!isNullOrEmpty(path)) {
        httpIngressPathBuilder.withPath(path);
    }
    HTTPIngressPath httpIngressPath = httpIngressPathBuilder.build();
    HTTPIngressRuleValue httpIngressRuleValue = new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build();
    IngressRuleBuilder ingressRuleBuilder = new IngressRuleBuilder().withHttp(httpIngressRuleValue);
    if (!isNullOrEmpty(host)) {
        ingressRuleBuilder.withHost(host);
    }
    IngressRule ingressRule = ingressRuleBuilder.build();
    IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
    Map<String, String> ingressAnnotations = new HashMap<>(annotations);
    ingressAnnotations.putAll(Annotations.newSerializer().servers(serversConfigs).machineName(machineName).annotations());
    return new IngressBuilder().withSpec(ingressSpec).withMetadata(new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).withLabels(labels).build()).build();
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HashMap(java.util.HashMap) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 4 with IngressBackendBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project ingress-access-operator by neo9.

the class ServiceExposerReconciler method reconcile.

public void reconcile(Service service) {
    String serviceNamespaceAndName = getResourceNamespaceAndName(service);
    log.trace("start working with service {}", serviceNamespaceAndName);
    Ingress oldIngress = ingressRepository.get(service.getMetadata().getNamespace(), service.getMetadata().getName());
    if (nonNull(oldIngress) && !isManagedByOperator(oldIngress)) {
        throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldIngress));
    }
    String hostname = generateHostname(service);
    log.debug("generating ingress for hostname : {}", hostname);
    Map<String, String> ingressAnnotations = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_ANNOTATIONS, service, ""));
    Map<String, String> ingressLabels = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_LABELS, service, ""));
    SpecNested<IngressBuilder> ingressBuilderSpecNested = new IngressBuilder().withNewMetadata().withNamespace(service.getMetadata().getNamespace()).withName(service.getMetadata().getName()).addToAnnotations(ingressAnnotations).addToLabels(ingressLabels).addToLabels(MANAGED_BY_OPERATOR_KEY, MANAGED_BY_OPERATOR_VALUE).endMetadata().withNewSpec().withRules(new IngressRuleBuilder().withHost(hostname).withHttp(new HTTPIngressRuleValueBuilder().withPaths(new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withBackend(new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build()).build()).build()).build());
    if (shouldEnableTls(ingressAnnotations)) {
        ingressBuilderSpecNested = ingressBuilderSpecNested.withTls(new IngressTLSBuilder().addToHosts(hostname).withSecretName(String.format("%s-tls", service.getMetadata().getName())).build());
    }
    Ingress ingress = ingressBuilderSpecNested.endSpec().build();
    ingressRepository.createOrReplace(ingress);
    log.trace("end of working with service {}", serviceNamespaceAndName);
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) ResourceNotManagedByOperatorException(io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)

Example 5 with IngressBackendBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder 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)

Aggregations

IngressBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder)6 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)5 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)5 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)5 IngressServiceBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder)5 ServiceBackendPortBuilder (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder)5 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)4 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)4 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)4 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)4 IngressSpecBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder)4 HashMap (java.util.HashMap)4 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPathBuilder)3 IngressBackendBuilder (io.fabric8.kubernetes.api.model.extensions.IngressBackendBuilder)3 IngressBuilder (io.fabric8.kubernetes.api.model.extensions.IngressBuilder)3 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)3 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 HTTPIngressPath (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPath)2