public static List<String> toServiceEndpointUrl(String serviceId, String serviceProtocol) { List<String> endpoints = new ArrayList<>(); String namespace = Systems.getEnvVarOrSystemProperty(KUBERNETES_NAMESPACE, DEFAULT_NAMESPACE); String serviceProto = serviceProtocol != null ? serviceProtocol : DEFAULT_PROTO; try { for (String endpoint : KubernetesHelper.lookupServiceInDns(serviceId)) { endpoints.add(serviceProto + "://" + endpoint); } } catch (UnknownHostException e) { // ignore and fallback to the api. } if (!endpoints.isEmpty()) { return endpoints; } for (io.fabric8.kubernetes.api.model.Endpoints item : KUBERNETES.getEndpoints(namespace).getItems()) { if (item.getMetadata().getName().equals(serviceId) && (namespace == null || namespace.equals(item.getMetadata().getNamespace()))) { for (EndpointSubset subset : item.getSubsets()) { for (EndpointAddress address : subset.getAddresses()) { endpoints.add(serviceProto + "://" + address.getIp()); } } break; } } return endpoints; }
public static String toServiceUrl( String serviceName, String serviceProtocol, boolean serviceExternal) { String serviceNamespace = Systems.getEnvVarOrSystemProperty(KUBERNETES_NAMESPACE, DEFAULT_NAMESPACE); return KUBERNETES.getServiceURL( serviceName, serviceNamespace, serviceProtocol, serviceExternal); }
@Override public Service getService(String name) { String serviceNamespace = Systems.getEnvVarOrSystemProperty(KUBERNETES_NAMESPACE, DEFAULT_NAMESPACE); if (kubernetesClient == null) { kubernetesClient = beanFactory.getBean(KubernetesClient.class); } return kubernetesClient.services().inNamespace(serviceNamespace).withName(name).get(); }