Search in sources :

Example 1 with RouteTargetReference

use of io.fabric8.openshift.api.model.RouteTargetReference in project fabric8-maven-plugin by fabric8io.

the class ApplyMojo method createRouteForService.

private Route createRouteForService(String routeDomainPostfix, String namespace, Service service) {
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && hasExactlyOneService(service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
        // objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (!Strings.isNullOrBlank(routeDomainPostfix)) {
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        } else {
            routeSpec.setHost("");
        }
        route.setSpec(routeSpec);
        String json;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
        log.debug("Created route: " + json);
    }
    return route;
}
Also used : RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Route(io.fabric8.openshift.api.model.Route)

Example 2 with RouteTargetReference

use of io.fabric8.openshift.api.model.RouteTargetReference in project fabric8 by fabric8io.

the class Routes method createRouteForService.

public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Logger log) {
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && shouldCreateRouteForService(log, service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
        // objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (Strings.isNotBlank(routeDomainPostfix)) {
            // Let Openshift determine the route host when the domain is not set
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            String namespaceSuffix = "-" + namespace;
            routeSpec.setHost(host + namespaceSuffix + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        }
        route.setSpec(routeSpec);
        String json = null;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
    }
    return route;
}
Also used : RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Route(io.fabric8.openshift.api.model.Route)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Route (io.fabric8.openshift.api.model.Route)2 RouteSpec (io.fabric8.openshift.api.model.RouteSpec)2 RouteTargetReference (io.fabric8.openshift.api.model.RouteTargetReference)2 RouteTargetReferenceBuilder (io.fabric8.openshift.api.model.RouteTargetReferenceBuilder)2 KubernetesHelper.createIntOrString (io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString)1