spring-cloud / spring-cloud-kubernetes

Kubernetes integration with Spring Cloud Discovery Client, Configuration, etc...
Apache License 2.0
3.47k stars 1.03k forks source link

Support Spring Cloud Config Client using Kubernetes as Discovery Client #333

Closed ooiweijie closed 5 years ago

ooiweijie commented 5 years ago

Spring Cloud Config Client should be able to use Kubernetes as the Discovery Client. Right now, if the following properties are used, the SCCC (name = config-server) will always attempt to retrieve the config from localhost:8888:

spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

Only when the config server's uri is specified can the config be retrieved successfully:

spring.cloud.config.enabled=true
spring.cloud.config.uri=http://config-server:8888

background: https://stackoverflow.com/questions/54702501/does-spring-cloud-config-client-support-using-kubernetes-as-a-discovery-client

geoand commented 5 years ago

@ryanjbaxter @spencergibb what would we need to do to support this?

ryanjbaxter commented 5 years ago

I am actually unsure as to why this does not work today. The basic idea is that the config client should use the discovery client implementation on the classpath to look up the URL to the config server. I am not sure what would prevent that from working when using the Kubernetes discovery client implementation. First place to look would be the config client code that is enabled when spring.cloud.config.discovery.enabled is enabled.

spencergibb commented 5 years ago

There some bootstrapping that has to happen for the discovery client to load properly.

https://github.com/spring-cloud/spring-cloud-consul/tree/master/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient

geoand commented 5 years ago

I don't know much about the ConfigServer, but I'll look into this soon hopefully

vxavictor513 commented 5 years ago

@spencergibb Isn't the bootstrapping already here?

https://github.com/spring-cloud/spring-cloud-kubernetes/tree/master/spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery

spencergibb commented 5 years ago

Indeed it is

ooiweijie commented 5 years ago

@spencergibb @ryanjbaxter @geoand Upon re-examining my codes, I realised that I have an extra line of code that overrides the value of spring.cloud.config.discovery.enabled to false. Upon removing that line of code and supplying the service id of the config server, it worked!

I truly apologise for any confusions that my question may have caused.

geoand commented 5 years ago

Glad to hear it worked @ooiweijie 😊