@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }
private static String getKeycloakAuthUrl(NamespacedOpenShiftClient client, Map<String, String> env) { Route keycloakRoute = client.routes().withName("keycloak").get(); String keycloakOauthUrl = null; if (keycloakRoute != null && !keycloakRoute.getSpec().getHost().contains("127.0.0.1")) { keycloakOauthUrl = String.format("https://%s/auth", keycloakRoute.getSpec().getHost()); } else { keycloakOauthUrl = getEnv(env, "STANDARD_AUTHSERVICE_SERVICE_HOST").map(ip -> "https://" + ip + ":8443/auth").orElse(null); } return keycloakOauthUrl; }
@Override public Optional<String> getExposedHost(String name) { Route route = openShiftClient.routes().withName(openshiftName(name)).get(); return Optional.ofNullable(route) .flatMap(r -> Optional.ofNullable(r.getSpec())) .map(RouteSpec::getHost); }
private void enableTls(final Route route) { RouteSpec spec = route.getSpec(); spec.setTls(getTLSConfig()); }
private Route updateRoute(Route route, Service service) { route.getSpec().getTo().setName(service.getMetadata().getName()); return route; }
private Route updateRoute(Route route, Service service) { route.getSpec().getTo().setName(service.getMetadata().getName()); return route; }
public static void setRoutes(RouteList routeList, String routerHost) { InetAddress routerAddr; try { routerAddr = routerHost == null ? null : InetAddress.getByName(routerHost); } catch (UnknownHostException e) { throw new IllegalArgumentException("Invalid IP for router host", e); } if (routeList != null) { synchronized (ROUTING) { for (Route route : routeList.getItems()) { String host = route.getSpec().getHost(); if (routerAddr != null) { System.out.println(String.format("Adding route (router -> host): %s -> %s", routerHost, host)); ROUTING.put(host, routerAddr); } else { ROUTING.remove(host); } } } } }
public Endpoint getKeycloakEndpoint() { OpenShiftClient openShift = client.adapt(OpenShiftClient.class); Route route = openShift.routes().inNamespace(globalNamespace).withName("keycloak").get(); Endpoint endpoint = new Endpoint(route.getSpec().getHost(), 443); log.info("Testing endpoint : " + endpoint); if (TestUtils.resolvable(endpoint)) { return endpoint; } else { log.info("Endpoint didn't resolve, falling back to service endpoint"); return getEndpoint("standard-authservice", "https"); } }
private void fillRouteServers(Route route, Map<String, ServerImpl> servers) { Annotations.newDeserializer(route.getMetadata().getAnnotations()) .servers() .forEach( (name, config) -> servers.put( name, newServer( config.getProtocol(), route.getSpec().getHost(), null, config.getPath(), config.getAttributes()))); } }
public void applyRoute(Route entity, String sourceName) { OpenShiftClient openShiftClient = getOpenShiftClient(); if (openShiftClient != null) { String id = getName(entity); Objects.requireNonNull(id, "No name for " + entity + " " + sourceName); String namespace = KubernetesHelper.getNamespace(entity); if (StringUtils.isBlank(namespace)) { namespace = getNamespace(); } Route route = openShiftClient.routes().inNamespace(namespace).withName(id).get(); if (route == null) { try { log.info("Creating Route " + namespace + ":" + id + " " + (entity.getSpec() != null ? "host: " + entity.getSpec().getHost() : "No Spec !")); openShiftClient.routes().inNamespace(namespace).create(entity); } catch (Exception e) { onApplyError("Failed to create Route from " + sourceName + ". " + e + ". " + entity, e); } } } }
public RouteBuilder(Route instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; }
public RouteFluentImpl(Route instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public RouteBuilder( RouteFluent<?> fluent , Route instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public RouteBuilder( Route instance ){
public RouteBuilder(RouteFluent<?> fluent,Route instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; } public RouteBuilder(Route instance){
public RouteBuilder( RouteFluent<?> fluent , Route instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public RouteBuilder( Route instance ){
public RouteBuilder( Route instance ){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public RouteBuilder( Route instance ){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }