spring-cloud-kubernetes
spring-cloud-kubernetes copied to clipboard
start fail in spring cloud gateway with elasticsearch
Describe the bug start fail in spring cloud gateway with elasticsearch
ExceptionStackTrace: Caused by: java.lang.IllegalStateException: null at java.util.Optional.orElseThrow(Optional.java:290) at org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClient.findEndpointPort(KubernetesDiscoveryClient.java:189) at org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClient.getInstances(KubernetesDiscoveryClient.java:157) at org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient.getInstances(CompositeDiscoveryClient.java:53) at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.tryOnNext(FluxMapFuseable.java:301) at reactor.core.publisher.FluxIterable$IterableSubscriptionConditional.slowPath(FluxIterable.java:515)
Reason: When I install elasticsearch by cloud-on-k8s(https://github.com/elastic/cloud-on-k8s), it auto create a service myes-es-default without Port, but, must have Port in spring-cloud-kubernetes
Hello! I ran into this as well and wanted to talk about my findings in case root cause has not been assessed!
Elasticsearch endpoint does not specify a port, which as far as k8s is concerned is OK.
logging elastic-webhook-server 100.99.232.133:9443
logging elasticsearch-es-default 100.106.192.199
logging elasticsearch-es-http 100.106.192.199:9200
logging elasticsearch-es-transport 100.106.192.199:9300
Calling public List<ServiceInstance> getInstances(String serviceId), means that you'll eventually call private EndpointPort findEndpointPort(EndpointSubset s).
Looking at the code you'll see:
https://github.com/spring-cloud/spring-cloud-kubernetes/blob/e27dbbc66d8f4dfacc8385b8918aaf8165b0f596/spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClient.java#L202-L221
Thus, you'll get an IllegalStateException
, when no exception should be thrown. The port should either not be set, or be put as a default.
Does this align with your thinking @ryanjbaxter?
@joshrosso that makes sense, can you create a PR for the 1.1.x branch?
@ryanjbaxter yes
Awesome thanks!