Merge branch '3.0.x'
This commit is contained in:
@@ -29,7 +29,6 @@ import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigServerBootstrapper;
|
||||
import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigServerInstanceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
@@ -53,14 +52,11 @@ class ConfigServerBootstrapper extends KubernetesConfigServerBootstrapper {
|
||||
|
||||
final static class KubernetesFunction implements ConfigServerInstanceProvider.Function {
|
||||
|
||||
private final BootstrapContext context;
|
||||
|
||||
private KubernetesFunction(BootstrapContext context) {
|
||||
this.context = context;
|
||||
private KubernetesFunction() {
|
||||
}
|
||||
|
||||
static KubernetesFunction create(BootstrapContext context) {
|
||||
return new KubernetesFunction(context);
|
||||
return new KubernetesFunction();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,18 +69,12 @@ class ConfigServerBootstrapper extends KubernetesConfigServerBootstrapper {
|
||||
// Kubernetes DiscoveryClient
|
||||
return Collections.emptyList();
|
||||
}
|
||||
KubernetesDiscoveryProperties discoveryProperties = createKubernetesDiscoveryProperties(binder,
|
||||
bindHandler);
|
||||
KubernetesClientProperties clientProperties = createKubernetesClientProperties(binder, bindHandler);
|
||||
return getInstanceProvider(discoveryProperties, clientProperties, context, binder, bindHandler, log)
|
||||
.getInstances(serviceId);
|
||||
return getInstanceProvider(binder, bindHandler).getInstances(serviceId);
|
||||
}
|
||||
|
||||
private KubernetesConfigServerInstanceProvider getInstanceProvider(
|
||||
KubernetesDiscoveryProperties discoveryProperties, KubernetesClientProperties clientProperties,
|
||||
BootstrapContext context, Binder binder, BindHandler bindHandler, Log log) {
|
||||
private KubernetesConfigServerInstanceProvider getInstanceProvider(Binder binder, BindHandler bindHandler) {
|
||||
KubernetesDiscoveryClientProperties kubernetesDiscoveryClientProperties = binder
|
||||
.bind("spring.cloud.kubernetes.discovery", Bindable.of(KubernetesDiscoveryClientProperties.class),
|
||||
.bind(KubernetesDiscoveryProperties.PREFIX, Bindable.of(KubernetesDiscoveryClientProperties.class),
|
||||
bindHandler)
|
||||
.orElseGet(KubernetesDiscoveryClientProperties::new);
|
||||
KubernetesDiscoveryClientAutoConfiguration.Servlet autoConfiguration = new KubernetesDiscoveryClientAutoConfiguration.Servlet();
|
||||
|
||||
@@ -68,9 +68,23 @@ class ConfigServerBootstrapperTests {
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
wireMockServer.start();
|
||||
WireMock.configureFor(wireMockServer.port());
|
||||
String APPS_NAME = "[{\"instanceId\":\"uid2\",\"serviceId\":\"spring-cloud-kubernetes-configserver\",\"host\":\"localhost\",\"port\":"
|
||||
+ wireMockServer.port() + ",\"uri\":\"" + wireMockServer.baseUrl()
|
||||
+ "\",\"secure\":false,\"metadata\":{\"spring\":\"true\",\"http\":\"8080\",\"k8s\":\"true\"},\"namespace\":\"namespace1\",\"cluster\":null,\"scheme\":\"http\"}]";
|
||||
String APPS_NAME = """
|
||||
[{
|
||||
"instanceId": "uid2",
|
||||
"serviceId": "spring-cloud-kubernetes-configserver",
|
||||
"host": "localhost",
|
||||
"port": "%s",
|
||||
"uri": "%s",
|
||||
"secure":false,
|
||||
"metadata":{"spring": "true", "http": "8080", "k8s": "true"},
|
||||
"namespace": "namespace1",
|
||||
"cluster": null,
|
||||
"scheme":"http"
|
||||
}]
|
||||
""".formatted(wireMockServer.port(), wireMockServer.baseUrl());
|
||||
|
||||
System.out.println(APPS_NAME);
|
||||
|
||||
stubFor(get("/apps/spring-cloud-kubernetes-configserver").willReturn(
|
||||
aResponse().withStatus(200).withBody(APPS_NAME).withHeader("content-type", "application/json")));
|
||||
Environment environment = new Environment("test", "default");
|
||||
|
||||
@@ -34,12 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
|
||||
ReactiveCommonsClientAutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithDefaults() {
|
||||
void shouldWorkWithDefaults() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
@@ -51,7 +51,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
|
||||
void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.cloud.discovery.enabled=false",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
@@ -63,7 +63,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenKubernetesDiscoveryDisabled() {
|
||||
void shouldNotHaveDiscoveryClientWhenKubernetesDiscoveryDisabled() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.cloud.kubernetes.discovery.enabled=false",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
@@ -75,7 +75,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveReactiveDiscoveryClient() {
|
||||
void shouldHaveReactiveDiscoveryClient() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
@@ -87,7 +87,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenReactiveDiscoveryDisabled() {
|
||||
void shouldNotHaveDiscoveryClientWhenReactiveDiscoveryDisabled() {
|
||||
contextRunner.withPropertyValues("spring.cloud.discovery.reactive.enabled=false").run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
@@ -95,7 +95,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenKubernetesDisabled() {
|
||||
void shouldNotHaveDiscoveryClientWhenKubernetesDisabled() {
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
@@ -103,7 +103,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worksWithoutActuator() {
|
||||
void worksWithoutActuator() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
|
||||
@@ -45,9 +45,55 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class KubernetesDiscoveryClientTests {
|
||||
|
||||
private static final String APPS = "[{\"name\":\"test-svc-1\",\"serviceInstances\":[{\"instanceId\":\"uid1\",\"serviceId\":\"test-svc-1\",\"host\":\"2.2.2.2\",\"port\":8080,\"uri\":\"http://2.2.2.2:8080\",\"secure\":false,\"metadata\":{\"http\":\"8080\"},\"namespace\":\"namespace1\",\"cluster\":null,\"scheme\":\"http\"}]},{\"name\":\"test-svc-3\",\"serviceInstances\":[{\"instanceId\":\"uid2\",\"serviceId\":\"test-svc-3\",\"host\":\"2.2.2.2\",\"port\":8080,\"uri\":\"http://2.2.2.2:8080\",\"secure\":false,\"metadata\":{\"spring\":\"true\",\"http\":\"8080\",\"k8s\":\"true\"},\"namespace\":\"namespace2\",\"cluster\":null,\"scheme\":\"http\"}]}]";
|
||||
private static final String APPS = """
|
||||
[{
|
||||
"name": "test-svc-1",
|
||||
"serviceInstances":
|
||||
[{
|
||||
"instanceId": "uid1",
|
||||
"serviceId": "test-svc-1",
|
||||
"host": "2.2.2.2",
|
||||
"port": 8080,
|
||||
"uri": "http://2.2.2.2:8080",
|
||||
"secure": false,
|
||||
"metadata":{"http": "8080"},
|
||||
"namespace": "namespace1",
|
||||
"cluster": null,
|
||||
"scheme": "http"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "test-svc-3",
|
||||
"serviceInstances":
|
||||
[{
|
||||
"instanceId": "uid2",
|
||||
"serviceId": "test-svc-3",
|
||||
"host": "2.2.2.2",
|
||||
"port": 8080,
|
||||
"uri": "http://2.2.2.2:8080",
|
||||
"secure": false,
|
||||
"metadata": {"spring": "true", "http": "8080", "k8s": "true"},
|
||||
"namespace": "namespace2",
|
||||
"cluster":null,
|
||||
"scheme":"http"
|
||||
}]
|
||||
}]
|
||||
""";
|
||||
|
||||
private static final String APPS_NAME = "[{\"instanceId\":\"uid2\",\"serviceId\":\"test-svc-3\",\"host\":\"2.2.2.2\",\"port\":8080,\"uri\":\"http://2.2.2.2:8080\",\"secure\":false,\"metadata\":{\"spring\":\"true\",\"http\":\"8080\",\"k8s\":\"true\"},\"namespace\":\"namespace2\",\"cluster\":null,\"scheme\":\"http\"}]";
|
||||
private static final String APPS_NAME = """
|
||||
[{
|
||||
"instanceId": "uid2",
|
||||
"serviceId": "test-svc-3",
|
||||
"host": "2.2.2.2",
|
||||
"port": 8080,
|
||||
"uri": "http://2.2.2.2:8080",
|
||||
"secure": false,
|
||||
"metadata": {"spring": "true", "http": "8080", "k8s": "true"},
|
||||
"namespace": "namespace2",
|
||||
"cluster": null,
|
||||
"scheme": "http"
|
||||
}]
|
||||
""";
|
||||
|
||||
private static WireMockServer wireMockServer;
|
||||
|
||||
|
||||
@@ -38,9 +38,55 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
|
||||
*/
|
||||
class KubernetesReactiveDiscoveryClientTests {
|
||||
|
||||
private static final String APPS = "[{\"name\":\"test-svc-1\",\"serviceInstances\":[{\"instanceId\":\"uid1\",\"serviceId\":\"test-svc-1\",\"host\":\"2.2.2.2\",\"port\":8080,\"uri\":\"http://2.2.2.2:8080\",\"secure\":false,\"metadata\":{\"http\":\"8080\"},\"namespace\":\"namespace1\",\"cluster\":null,\"scheme\":\"http\"}]},{\"name\":\"test-svc-3\",\"serviceInstances\":[{\"instanceId\":\"uid2\",\"serviceId\":\"test-svc-3\",\"host\":\"2.2.2.2\",\"port\":8080,\"uri\":\"http://2.2.2.2:8080\",\"secure\":false,\"metadata\":{\"spring\":\"true\",\"http\":\"8080\",\"k8s\":\"true\"},\"namespace\":\"namespace1\",\"cluster\":null,\"scheme\":\"http\"}]}]";
|
||||
private static final String APPS = """
|
||||
[{
|
||||
"name": "test-svc-1",
|
||||
"serviceInstances":
|
||||
[{
|
||||
"instanceId": "uid1",
|
||||
"serviceId": "test-svc-1",
|
||||
"host": "2.2.2.2",
|
||||
"port": 8080,
|
||||
"uri": "http://2.2.2.2:8080",
|
||||
"secure": false,
|
||||
"metadata": {"http":"8080"},
|
||||
"namespace": "namespace1",
|
||||
"cluster": null,
|
||||
"scheme": "http"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "test-svc-3",
|
||||
"serviceInstances":
|
||||
[{
|
||||
"instanceId": "uid2",
|
||||
"serviceId": "test-svc-3",
|
||||
"host": "2.2.2.2",
|
||||
"port": 8080,
|
||||
"uri": "http://2.2.2.2:8080",
|
||||
"secure": false,
|
||||
"metadata": {"spring": "true", "http": "8080", "k8s": "true"},
|
||||
"namespace": "namespace1",
|
||||
"cluster": null,
|
||||
"scheme": "http"
|
||||
}]
|
||||
}]
|
||||
""";
|
||||
|
||||
private static final String APPS_NAME = "[{\"instanceId\":\"uid2\",\"serviceId\":\"test-svc-3\",\"host\":\"2.2.2.2\",\"port\":8080,\"uri\":\"http://2.2.2.2:8080\",\"secure\":false,\"metadata\":{\"spring\":\"true\",\"http\":\"8080\",\"k8s\":\"true\"},\"namespace\":\"namespace1\",\"cluster\":null,\"scheme\":\"http\"}]";
|
||||
private static final String APPS_NAME = """
|
||||
[{
|
||||
"instanceId": "uid2",
|
||||
"serviceId": "test-svc-3",
|
||||
"host": "2.2.2.2",
|
||||
"port": 8080,
|
||||
"uri": "http://2.2.2.2:8080",
|
||||
"secure": false,
|
||||
"metadata": {"spring": "true", "http": "8080", "k8s": "true"},
|
||||
"namespace": "namespace1",
|
||||
"cluster": null,
|
||||
"scheme": "http"
|
||||
}]
|
||||
""";
|
||||
|
||||
private static WireMockServer wireMockServer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user