diff --git a/docs/src/main/asciidoc/discovery-client.adoc b/docs/src/main/asciidoc/discovery-client.adoc index a6438bbf..49b12b6c 100644 --- a/docs/src/main/asciidoc/discovery-client.adoc +++ b/docs/src/main/asciidoc/discovery-client.adoc @@ -64,6 +64,16 @@ spring.cloud.kubernetes.discovery.all-namespaces=true ---- ==== +To discover service endpoint addresses that are not marked as "ready" by the kubernetes api server, you can set the following property in `application.properties` (default: false): + +==== +[source] +---- +spring.cloud.kubernetes.discovery.include-not-ready-addresses=true +---- +NOTE: This might be useful when discovering services for monitoring purposes, and would enable inspecting the `/health` endpoint of not-ready service instances. +==== + If, for any reason, you need to disable the `DiscoveryClient`, you can set the following property in `application.properties`: ==== diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java index ba338928..f9dfd404 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java @@ -51,6 +51,12 @@ public class KubernetesDiscoveryProperties { **/ private long cacheLoadingTimeoutSeconds = 60; + /** + * If endpoint addresses not marked 'ready' by the k8s api server should be + * discovered. + */ + private boolean includeNotReadyAddresses = false; + /** * SpEL expression to filter services AFTER they have been retrieved from the * Kubernetes API server. @@ -145,6 +151,14 @@ public class KubernetesDiscoveryProperties { this.allNamespaces = allNamespaces; } + public boolean isIncludeNotReadyAddresses() { + return includeNotReadyAddresses; + } + + public void setIncludeNotReadyAddresses(boolean includeNotReadyAddresses) { + this.includeNotReadyAddresses = includeNotReadyAddresses; + } + public int getOrder() { return this.order; } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 39e78e16..472fbd74 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -40,6 +40,7 @@ import org.springframework.expression.Expression; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.SimpleEvaluationContext; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import static java.util.stream.Collectors.toMap; @@ -152,6 +153,15 @@ public class KubernetesDiscoveryClient implements DiscoveryClient { } List addresses = s.getAddresses(); + + if (this.properties.isIncludeNotReadyAddresses() + && !CollectionUtils.isEmpty(s.getNotReadyAddresses())) { + if (addresses == null) { + addresses = new ArrayList(); + } + addresses.addAll(s.getNotReadyAddresses()); + } + for (EndpointAddress endpointAddress : addresses) { String instanceId = null; if (endpointAddress.getTargetRef() != null) {