@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); String serviceName = service.getMetadata().getName(); if(port == null) { throw new RuntimeException("Couldn't find port: " + portName + " for service " + service.getMetadata().getName()); } IngressList ingresses = client.extensions().ingresses().inNamespace(namespace).list(); if(ingresses != null && !ingresses.getItems().isEmpty()) { return URLFromServiceUtil.getURLFromIngressList(ingresses.getItems(), namespace, serviceName, port); } return null; }
public String getURL(Service service, String portName, String namespace, KubernetesClient client) { ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); String serviceProto = port.getProtocol(); NodePortUrlComponents urlComponents = null; Integer nodePort = port.getNodePort(); if(nodePort != null) { try { NodeList nodeList = client.nodes().list(); if(nodeList != null && nodeList.getItems() != null) { for(Node item : nodeList.getItems()) { urlComponents = getUrlComponentsFromNodeList(item.getStatus(), nodePort); if(urlComponents != null) { break; } } } } catch (KubernetesClientException exception) { logger.warn("Could not find a node! " + exception); } } return urlComponents != null ? (serviceProto + "://" + urlComponents.getClusterIP() + ":" + urlComponents.getPortNumber()).toLowerCase() : null; }
@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; }
@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; }