names = new HashSet<>();
names.add(name);
- if (environment != null) {
+ if (environment != null && includeProfileSpecificSources) {
for (String activeProfile : environment.getActiveProfiles()) {
names.add(name + "-" + activeProfile);
}
diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java
index d9ccde5d09..a35d167751 100644
--- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java
+++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java
@@ -89,7 +89,8 @@ else if (kubernetesClientProperties != null) {
}
return new KubernetesClientConfigMapPropertySource(coreV1Api, name, namespace, environment,
- normalizedSource.getPrefix(), this.properties.isFailFast());
+ normalizedSource.getPrefix(), normalizedSource.isIncludeProfileSpecificSources(),
+ this.properties.isFailFast());
}
}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapIncludeProfileSpecificSourcesTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapIncludeProfileSpecificSourcesTests.java
new file mode 100644
index 0000000000..12c1d26d9f
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapIncludeProfileSpecificSourcesTests.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2013-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config;
+
+import com.github.tomakehurst.wiremock.client.WireMock;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.IncludeProfileSpecificSourcesApp;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.reactive.server.WebTestClient;
+
+/**
+ * The stub data for this test is in : IncludeProfileSpecificSourcesConfigurationStub
+ *
+ * @author wind57
+ */
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
+ classes = IncludeProfileSpecificSourcesApp.class,
+ properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources",
+ "include.profile.specific.sources=true" })
+@AutoConfigureWebTestClient
+@ActiveProfiles("dev")
+class KubernetesClientConfigMapIncludeProfileSpecificSourcesTests {
+
+ @Autowired
+ private WebTestClient webClient;
+
+ @AfterEach
+ public void afterEach() {
+ WireMock.reset();
+ }
+
+ @AfterAll
+ public static void afterAll() {
+ WireMock.shutdownServer();
+ }
+
+ /**
+ *
+ * 'spring.cloud.kubernetes.config.includeProfileSpecificSources=false'
+ * 'spring.cloud.kubernetes.config.sources[0].includeProfileSpecificSources=true'
+ * 'spring.cloud.kubernetes.config.sources[0].name=config-map-one'
+ *
+ * We do not define config-map 'config-map-one', but we do define 'config-map-one-dev'.
+ *
+ * As such: @ConfigurationProperties("one") must be resolved from 'config-map-one-dev'
+ *
+ */
+ @Test
+ public void testOne() {
+ this.webClient.get().uri("/profile-specific/one").exchange().expectStatus().isOk().expectBody(String.class)
+ .value(Matchers.equalTo("one"));
+ }
+
+ /**
+ *
+ * 'spring.cloud.kubernetes.config.includeProfileSpecificSources=false'
+ * 'spring.cloud.kubernetes.config.sources[1].includeProfileSpecificSources=false'
+ * 'spring.cloud.kubernetes.config.sources[1].name=config-map-two'
+ *
+ * We define config-map 'config-map-two', but we also define 'config-map-two-dev'.
+ * This tests proves that data will be read from 'config-map-two' _only_, even if 'config-map-two-dev'
+ * also exists. This happens because of the 'includeProfileSpecificSources=false' property defined at the source level.
+ * If this would be incorrect, the value we read from '/profile-specific/two' would have been 'twoDev' and _not_ 'two',
+ * simply because 'config-map-two-dev' would override the property value.
+ *
+ * As such: @ConfigurationProperties("two") must be resolved from 'config-map-two'
+ *
+ */
+ @Test
+ public void testTwo() {
+ this.webClient.get().uri("/profile-specific/two").exchange().expectStatus().isOk().expectBody(String.class)
+ .value(Matchers.equalTo("two"));
+ }
+
+ /**
+ *
+ * 'spring.cloud.kubernetes.config.includeProfileSpecificSources=false'
+ * 'spring.cloud.kubernetes.config.sources[2].name=config-map-three'
+ *
+ * We define config-map 'config-map-three', but we also define 'config-map-three-dev'.
+ * This tests proves that data will be read from 'config-map-three' _only_, even if 'config-map-three-dev'
+ * also exists. This happens because the 'includeProfileSpecificSources' property is not defined at the source level,
+ * but it is defaulted from the root level, where we set it to false.
+ * If this would be incorrect, the value we read from '/profile-specific/three' would have been 'threeDev' and _not_ 'three',
+ * simply because 'config-map-three-dev' would override the property value.
+ *
+ * As such: @ConfigurationProperties("three") must be resolved from 'config-map-three'
+ *
+ */
+ @Test
+ public void testThree() {
+ this.webClient.get().uri("/profile-specific/three").exchange().expectStatus().isOk().expectBody(String.class)
+ .value(Matchers.equalTo("three"));
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapNameAsPrefixTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapNameAsPrefixTests.java
new file mode 100644
index 0000000000..8ad5656ead
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapNameAsPrefixTests.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2013-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config;
+
+import com.github.tomakehurst.wiremock.client.WireMock;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.WithPrefixApp;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.reactive.server.WebTestClient;
+
+/**
+ * The stub data for this test is in : ConfigMapNameAsPrefixConfigurationStub
+ *
+ * @author wind57
+ */
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = WithPrefixApp.class,
+ properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix", "config.map.name.as.prefix.stub=true" })
+@AutoConfigureWebTestClient
+public class KubernetesClientConfigMapNameAsPrefixTests {
+
+ @Autowired
+ private WebTestClient webClient;
+
+ @AfterEach
+ public void afterEach() {
+ WireMock.reset();
+ }
+
+ @AfterAll
+ public static void afterAll() {
+ WireMock.shutdownServer();
+ }
+
+ /**
+ *
+ * 'spring.cloud.kubernetes.config.useNameAsPrefix=true'
+ * 'spring.cloud.kubernetes.config.sources[0].useNameAsPrefix=false'
+ * ("one.property", "one")
+ *
+ * As such: @ConfigurationProperties("one")
+ *
+ */
+ @Test
+ public void testOne() {
+ this.webClient.get().uri("/prefix/one").exchange().expectStatus().isOk().expectBody(String.class)
+ .value(Matchers.equalTo("one"));
+ }
+
+ /**
+ *
+ * 'spring.cloud.kubernetes.config.useNameAsPrefix=true'
+ * 'spring.cloud.kubernetes.config.sources[1].explicitPrefix=two'
+ * ("property", "two")
+ *
+ * As such: @ConfigurationProperties("two")
+ *
+ */
+ @Test
+ public void testTwo() {
+ this.webClient.get().uri("/prefix/two").exchange().expectStatus().isOk().expectBody(String.class)
+ .value(Matchers.equalTo("two"));
+ }
+
+ /**
+ *
+ * 'spring.cloud.kubernetes.config.useNameAsPrefix=true'
+ * 'spring.cloud.kubernetes.config.sources[2].name=config-map-three'
+ * ("property", "three")
+ *
+ * As such: @ConfigurationProperties(prefix = "config-map-three")
+ *
+ */
+ @Test
+ public void testThree() {
+ this.webClient.get().uri("/prefix/three").exchange().expectStatus().isOk().expectBody(String.class)
+ .value(Matchers.equalTo("three"));
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java
index f97b8a4f07..1f18984b12 100644
--- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java
@@ -65,8 +65,6 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
- private static final String API = "/api/v1/namespaces/default/configmaps";
-
private static WireMockServer wireMockServer;
@BeforeAll
@@ -94,7 +92,7 @@ public void afterEach() {
@Test
void locateWithoutSources() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API)
+ stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("bootstrap-640");
@@ -109,7 +107,7 @@ void locateWithoutSources() {
@Test
void locateWithSources() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API)
+ stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("fake-name");
@@ -137,7 +135,7 @@ void locateWithSources() {
@Test
void testLocateWithoutNamespaceDeprecatedConstructor() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API)
+ stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("bootstrap-640");
@@ -159,7 +157,7 @@ void testLocateWithoutNamespaceDeprecatedConstructor() {
@Test
void testLocateWithoutNamespace() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API)
+ stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("bootstrap-640");
@@ -173,7 +171,8 @@ void testLocateWithoutNamespace() {
@Test
public void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
+ stubFor(get("/api/v1/namespaces/default/configmaps")
+ .willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("bootstrap-640");
@@ -190,7 +189,8 @@ public void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
@Test
public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
+ stubFor(get("/api/v1/namespaces/default/configmaps")
+ .willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("bootstrap-640");
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceTests.java
index b582a23658..1bbd563eb7 100644
--- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceTests.java
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceTests.java
@@ -68,8 +68,6 @@ class KubernetesClientConfigMapPropertySourceTests {
"dummy:\n property:\n string2: \"a\"\n int2: 1\n bool2: true\n")
.build());
- private static final String API = "/api/v1/namespaces/default/configmaps";
-
private static WireMockServer wireMockServer;
@BeforeAll
@@ -97,11 +95,11 @@ public void afterEach() {
@Test
public void propertiesFile() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API)
+ stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
KubernetesClientConfigMapPropertySource propertySource = new KubernetesClientConfigMapPropertySource(api,
- "bootstrap-640", "default", new MockEnvironment(), "", false);
- verify(getRequestedFor(urlEqualTo(API)));
+ "bootstrap-640", "default", new MockEnvironment(), "", true, false);
+ verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
assertThat(propertySource.getProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
@@ -114,10 +112,11 @@ public void propertiesFile() {
@Test
public void yamlFile() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(YAML_CONFIGMAP_LIST))));
+ stubFor(get("/api/v1/namespaces/default/configmaps")
+ .willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(YAML_CONFIGMAP_LIST))));
KubernetesClientConfigMapPropertySource propertySource = new KubernetesClientConfigMapPropertySource(api,
- "bootstrap-641", "default", new MockEnvironment(), "", false);
- verify(getRequestedFor(urlEqualTo(API)));
+ "bootstrap-641", "default", new MockEnvironment(), "", true, false);
+ verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
assertThat(propertySource.containsProperty("dummy.property.string2")).isTrue();
assertThat(propertySource.getProperty("dummy.property.string2")).isEqualTo("a");
assertThat(propertySource.containsProperty("dummy.property.int2")).isTrue();
@@ -130,11 +129,11 @@ public void yamlFile() {
@Test
public void propertiesFileWithPrefix() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API)
+ stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
KubernetesClientConfigMapPropertySource propertySource = new KubernetesClientConfigMapPropertySource(api,
- "bootstrap-640", "default", new MockEnvironment(), "prefix", false);
- verify(getRequestedFor(urlEqualTo(API)));
+ "bootstrap-640", "default", new MockEnvironment(), "prefix", true, false);
+ verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
assertThat(propertySource.containsProperty("prefix.spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
assertThat(propertySource.getProperty("prefix.spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
@@ -148,22 +147,24 @@ public void propertiesFileWithPrefix() {
@Test
public void constructorShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
+ stubFor(get("/api/v1/namespaces/default/configmaps")
+ .willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySource(api, "my-config", "default",
- new MockEnvironment(), "", true)).isInstanceOf(IllegalStateException.class)
+ new MockEnvironment(), "", false, true)).isInstanceOf(IllegalStateException.class)
.hasMessage("Unable to read ConfigMap with name 'my-config' in namespace 'default'");
- verify(getRequestedFor(urlEqualTo(API)));
+ verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
}
@Test
public void constructorShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
CoreV1Api api = new CoreV1Api();
- stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
+ stubFor(get("/api/v1/namespaces/default/configmaps")
+ .willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
assertThatNoException().isThrownBy((() -> new KubernetesClientConfigMapPropertySource(api, "my-config",
- "default", new MockEnvironment(), "", false)));
- verify(getRequestedFor(urlEqualTo(API)));
+ "default", new MockEnvironment(), "", false, false)));
+ verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
}
}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/WithPrefixApp.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/WithPrefixApp.java
new file mode 100644
index 0000000000..0bdbb15a00
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/WithPrefixApp.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties.One;
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties.Three;
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties.Two;
+
+@SpringBootApplication
+@EnableConfigurationProperties({ One.class, Two.class, Three.class })
+public class WithPrefixApp {
+
+ public static void main(String[] args) {
+ SpringApplication.run(WithPrefixApp.class, args);
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/controller/Controller.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/controller/Controller.java
new file mode 100644
index 0000000000..e4d655780c
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/controller/Controller.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.controller;
+
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties.One;
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties.Three;
+import org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties.Two;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class Controller {
+
+ private final One one;
+
+ private final Two two;
+
+ private final Three three;
+
+ public Controller(One one, Two two, Three three) {
+ this.one = one;
+ this.two = two;
+ this.three = three;
+ }
+
+ @GetMapping("/prefix/one")
+ public String one() {
+ return one.getProperty();
+ }
+
+ @GetMapping("/prefix/two")
+ public String two() {
+ return two.getProperty();
+ }
+
+ @GetMapping("/prefix/three")
+ public String three() {
+ return three.getProperty();
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/One.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/One.java
new file mode 100644
index 0000000000..4a9eb5e436
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/One.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("one")
+public class One {
+
+ private String property;
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/Three.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/Three.java
new file mode 100644
index 0000000000..ae83c9a944
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/Three.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "config-map-three")
+public class Three {
+
+ private String property;
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/Two.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/Two.java
new file mode 100644
index 0000000000..7a3d9d8dc7
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/config_map_name_as_prefix/properties/Two.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.config_map_name_as_prefix.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("two")
+public class Two {
+
+ private String property;
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/IncludeProfileSpecificSourcesApp.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/IncludeProfileSpecificSourcesApp.java
new file mode 100644
index 0000000000..d719c4220e
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/IncludeProfileSpecificSourcesApp.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties.One;
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties.Three;
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties.Two;
+
+@SpringBootApplication
+@EnableConfigurationProperties({ One.class, Two.class, Three.class })
+public class IncludeProfileSpecificSourcesApp {
+
+ public static void main(String[] args) {
+ SpringApplication.run(IncludeProfileSpecificSourcesApp.class, args);
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/controller/IncludeProfileSpecificSourcesController.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/controller/IncludeProfileSpecificSourcesController.java
new file mode 100644
index 0000000000..fd8e4db04d
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/controller/IncludeProfileSpecificSourcesController.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.controller;
+
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties.One;
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties.Three;
+import org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties.Two;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class IncludeProfileSpecificSourcesController {
+
+ private final One one;
+
+ private final Two two;
+
+ private final Three three;
+
+ public IncludeProfileSpecificSourcesController(One one, Two two, Three three) {
+ this.one = one;
+ this.two = two;
+ this.three = three;
+ }
+
+ @GetMapping("/profile-specific/one")
+ public String one() {
+ return one.getProperty();
+ }
+
+ @GetMapping("/profile-specific/two")
+ public String two() {
+ return two.getProperty();
+ }
+
+ @GetMapping("/profile-specific/three")
+ public String three() {
+ return three.getProperty();
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/One.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/One.java
new file mode 100644
index 0000000000..1e59b034ed
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/One.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("one")
+public class One {
+
+ private String property;
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/Three.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/Three.java
new file mode 100644
index 0000000000..e96da1ebd6
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/Three.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("three")
+public class Three {
+
+ private String property;
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/Two.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/Two.java
new file mode 100644
index 0000000000..4dde04d3a1
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/include_profile_specific_sources/properties/Two.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.applications.include_profile_specific_sources.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("two")
+public class Two {
+
+ private String property;
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/ConfigMapNameAsPrefixConfigurationStub.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/ConfigMapNameAsPrefixConfigurationStub.java
new file mode 100644
index 0000000000..a639d71378
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/ConfigMapNameAsPrefixConfigurationStub.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2013-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.boostrap.stubs;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.WireMock;
+import io.kubernetes.client.openapi.ApiClient;
+import io.kubernetes.client.openapi.JSON;
+import io.kubernetes.client.openapi.models.V1ConfigMap;
+import io.kubernetes.client.openapi.models.V1ConfigMapBuilder;
+import io.kubernetes.client.openapi.models.V1ConfigMapList;
+import io.kubernetes.client.openapi.models.V1ObjectMetaBuilder;
+import io.kubernetes.client.util.ClientBuilder;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+
+/**
+ * A test bootstrap that takes care to initialize ApiClient _before_ our main bootstrap
+ * context; with some stub data already present.
+ *
+ * @author wind57
+ */
+@Order(0)
+@Configuration
+@ConditionalOnProperty("config.map.name.as.prefix.stub")
+public class ConfigMapNameAsPrefixConfigurationStub {
+
+ @Bean
+ public WireMockServer wireMock() {
+ WireMockServer server = new WireMockServer(options().dynamicPort());
+ server.start();
+ WireMock.configureFor("localhost", server.port());
+ return server;
+ }
+
+ @Bean
+ public ApiClient apiClient(WireMockServer wireMockServer) {
+ ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockServer.port()).build();
+ io.kubernetes.client.openapi.Configuration.setDefaultApiClient(apiClient);
+ apiClient.setDebugging(true);
+ stubData();
+ return apiClient;
+ }
+
+ private void stubData() {
+ V1ConfigMap one = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-one").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("one.property", "one")).build();
+
+ V1ConfigMap two = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-two").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("property", "two")).build();
+
+ V1ConfigMap three = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-three").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("property", "three")).build();
+
+ V1ConfigMapList allConfigMaps = new V1ConfigMapList();
+ allConfigMaps.setItems(Arrays.asList(one, two, three));
+
+ // the actual stub for CoreV1Api calls
+ WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
+ .willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/IncludeProfileSpecificSourcesConfigurationStub.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/IncludeProfileSpecificSourcesConfigurationStub.java
new file mode 100644
index 0000000000..ee37d971c0
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/IncludeProfileSpecificSourcesConfigurationStub.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2013-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.kubernetes.client.config.boostrap.stubs;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.WireMock;
+import io.kubernetes.client.openapi.ApiClient;
+import io.kubernetes.client.openapi.JSON;
+import io.kubernetes.client.openapi.models.V1ConfigMap;
+import io.kubernetes.client.openapi.models.V1ConfigMapBuilder;
+import io.kubernetes.client.openapi.models.V1ConfigMapList;
+import io.kubernetes.client.openapi.models.V1ObjectMetaBuilder;
+import io.kubernetes.client.util.ClientBuilder;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+
+/**
+ * A test bootstrap that takes care to initialize ApiClient _before_ our main bootstrap
+ * context; with some stub data already.
+ *
+ * @author wind57
+ */
+@Order(0)
+@Configuration
+@ConditionalOnProperty("include.profile.specific.sources")
+class IncludeProfileSpecificSourcesConfigurationStub {
+
+ @Bean
+ public WireMockServer wireMock() {
+ WireMockServer server = new WireMockServer(options().dynamicPort());
+ server.start();
+ WireMock.configureFor("localhost", server.port());
+ return server;
+ }
+
+ @Bean
+ public ApiClient apiClient(WireMockServer wireMockServer) {
+ ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockServer.port()).build();
+ io.kubernetes.client.openapi.Configuration.setDefaultApiClient(apiClient);
+ apiClient.setDebugging(true);
+ stubData();
+ return apiClient;
+ }
+
+ private void stubData() {
+ V1ConfigMap one = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-one-dev").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("one.property", "one")).build();
+
+ V1ConfigMap two = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-two").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("two.property", "two")).build();
+
+ V1ConfigMap twoDev = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-two-dev").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("two.property", "twoDev")).build();
+
+ V1ConfigMap three = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-three").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("three.property", "three")).build();
+
+ V1ConfigMap threeDev = new V1ConfigMapBuilder()
+ .withMetadata(new V1ObjectMetaBuilder().withName("config-map-three-dev").withNamespace("spring-k8s")
+ .withResourceVersion("1").build())
+ .addToData(Collections.singletonMap("three.property", "threeDev")).build();
+
+ V1ConfigMapList allConfigMaps = new V1ConfigMapList();
+ allConfigMaps.setItems(Arrays.asList(one, two, twoDev, three, threeDev));
+
+ // the actual stub for CoreV1Api calls
+ WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
+ .willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
+ }
+
+}
diff --git a/spring-cloud-kubernetes-client-config/src/test/resources/META-INF/spring.factories b/spring-cloud-kubernetes-client-config/src/test/resources/META-INF/spring.factories
new file mode 100644
index 0000000000..5d0b2c08a6
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/resources/META-INF/spring.factories
@@ -0,0 +1,3 @@
+org.springframework.cloud.bootstrap.BootstrapConfiguration=\
+org.springframework.cloud.kubernetes.client.config.boostrap.stubs.IncludeProfileSpecificSourcesConfigurationStub, \
+org.springframework.cloud.kubernetes.client.config.boostrap.stubs.ConfigMapNameAsPrefixConfigurationStub
diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/resources/same-key-with-prefix.yaml b/spring-cloud-kubernetes-client-config/src/test/resources/config-map-name-as-prefix.yaml
similarity index 100%
rename from spring-cloud-kubernetes-fabric8-config/src/test/resources/same-key-with-prefix.yaml
rename to spring-cloud-kubernetes-client-config/src/test/resources/config-map-name-as-prefix.yaml
diff --git a/spring-cloud-kubernetes-client-config/src/test/resources/include-profile-specific-sources.yaml b/spring-cloud-kubernetes-client-config/src/test/resources/include-profile-specific-sources.yaml
new file mode 100644
index 0000000000..54999aaa3a
--- /dev/null
+++ b/spring-cloud-kubernetes-client-config/src/test/resources/include-profile-specific-sources.yaml
@@ -0,0 +1,14 @@
+spring:
+ application:
+ name: include-profile-specific-sources
+ cloud:
+ kubernetes:
+ config:
+ includeProfileSpecificSources: false
+ namespace: spring-k8s
+ sources:
+ - name: config-map-one
+ includeProfileSpecificSources: true
+ - name: config-map-two
+ includeProfileSpecificSources: false
+ - name: config-map-three
diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientAutoConfiguration.java
index 826e7e23b3..263e1d739b 100644
--- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientAutoConfiguration.java
+++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientAutoConfiguration.java
@@ -48,6 +48,7 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
@Configuration(proxyBeanMethods = false)
@ConditionalOnKubernetesDiscoveryEnabled
@@ -80,11 +81,15 @@ public static class KubernetesInformerDiscoveryConfiguration {
@Bean
@ConditionalOnMissingBean
public SpringCloudKubernetesInformerFactoryProcessor discoveryInformerConfigurer(
- KubernetesNamespaceProvider kubernetesNamespaceProvider,
- KubernetesDiscoveryProperties kubernetesDiscoveryProperties, ApiClient apiClient,
- CatalogSharedInformerFactory sharedInformerFactory) {
- return new SpringCloudKubernetesInformerFactoryProcessor(kubernetesDiscoveryProperties,
- kubernetesNamespaceProvider, apiClient, sharedInformerFactory);
+ KubernetesNamespaceProvider kubernetesNamespaceProvider, ApiClient apiClient,
+ CatalogSharedInformerFactory sharedInformerFactory, Environment environment) {
+ // Injecting KubernetesDiscoveryProperties here would cause it to be
+ // initialize too early
+ // Instead get the all-namespaces property value from the Environment directly
+ boolean allNamespaces = environment.getProperty("spring.cloud.kubernetes.discovery.all-namespaces",
+ Boolean.class, false);
+ return new SpringCloudKubernetesInformerFactoryProcessor(kubernetesNamespaceProvider, apiClient,
+ sharedInformerFactory, allNamespaces);
}
@Bean
diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java
index 23c4afbc38..32a7d7f41b 100644
--- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java
+++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java
@@ -102,7 +102,7 @@ public List getInstances(String serviceId) {
V1Service service = properties.isAllNamespaces() ? this.serviceLister.list().stream()
.filter(svc -> serviceId.equals(svc.getMetadata().getName())).findFirst().orElse(null)
: this.serviceLister.namespace(this.namespace).get(serviceId);
- if (service == null) {
+ if (service == null || !matchServiceLabels(service)) {
// no such service present in the cluster
return new ArrayList<>();
}
@@ -163,7 +163,8 @@ public List getInstances(String serviceId) {
return addresses.stream()
.map(addr -> new KubernetesServiceInstance(
addr.getTargetRef() != null ? addr.getTargetRef().getUid() : "", serviceId,
- addr.getIp(), port, metadata, false));
+ addr.getIp(), port, metadata, false, service.getMetadata().getNamespace(),
+ service.getMetadata().getClusterName()));
}).collect(Collectors.toList());
}
@@ -205,8 +206,8 @@ private int findEndpointPort(List endpointPorts, String primaryP
public List getServices() {
List services = this.properties.isAllNamespaces() ? this.serviceLister.list()
: this.serviceLister.namespace(this.namespace).list();
- return services.stream().filter(s -> s.getMetadata() != null) // safeguard
- .map(s -> s.getMetadata().getName()).collect(Collectors.toList());
+ return services.stream().filter(this::matchServiceLabels).map(s -> s.getMetadata().getName())
+ .collect(Collectors.toList());
}
@Override
@@ -230,4 +231,28 @@ public void afterPropertiesSet() throws Exception {
+ " services) , discovery client is now available");
}
+ private boolean matchServiceLabels(V1Service service) {
+ if (log.isDebugEnabled()) {
+ log.debug("Kubernetes Service Label Properties:");
+ if (this.properties.getServiceLabels() != null) {
+ this.properties.getServiceLabels().forEach((key, value) -> log.debug(key + ":" + value));
+ }
+ log.debug("Service " + service.getMetadata().getName() + " labels:");
+ if (service.getMetadata() != null && service.getMetadata().getLabels() != null) {
+ service.getMetadata().getLabels().forEach((key, value) -> log.debug(key + ":" + value));
+ }
+ }
+ // safeguard
+ if (service.getMetadata() == null) {
+ return false;
+ }
+ if (properties.getServiceLabels() == null || properties.getServiceLabels().isEmpty()) {
+ return true;
+ }
+ return properties.getServiceLabels().keySet().stream()
+ .allMatch(k -> service.getMetadata().getLabels() != null
+ && service.getMetadata().getLabels().containsKey(k)
+ && service.getMetadata().getLabels().get(k).equals(properties.getServiceLabels().get(k)));
+ }
+
}
diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/SpringCloudKubernetesInformerFactoryProcessor.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/SpringCloudKubernetesInformerFactoryProcessor.java
index c3a5ecf303..ef4d574cef 100644
--- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/SpringCloudKubernetesInformerFactoryProcessor.java
+++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/SpringCloudKubernetesInformerFactoryProcessor.java
@@ -38,7 +38,6 @@
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
-import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.core.ResolvableType;
/**
@@ -54,26 +53,24 @@ class SpringCloudKubernetesInformerFactoryProcessor extends KubernetesInformerFa
private final SharedInformerFactory sharedInformerFactory;
- private final KubernetesDiscoveryProperties kubernetesDiscoveryProperties;
+ private final boolean allNamespaces;
private final KubernetesNamespaceProvider kubernetesNamespaceProvider;
@Autowired
- SpringCloudKubernetesInformerFactoryProcessor(KubernetesDiscoveryProperties kubernetesDiscoveryProperties,
- KubernetesNamespaceProvider kubernetesNamespaceProvider, ApiClient apiClient,
- SharedInformerFactory sharedInformerFactory) {
+ SpringCloudKubernetesInformerFactoryProcessor(KubernetesNamespaceProvider kubernetesNamespaceProvider,
+ ApiClient apiClient, SharedInformerFactory sharedInformerFactory, boolean allNamespaces) {
super();
this.apiClient = apiClient;
this.sharedInformerFactory = sharedInformerFactory;
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
- this.kubernetesDiscoveryProperties = kubernetesDiscoveryProperties;
+ this.allNamespaces = allNamespaces;
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
- String namespace = kubernetesDiscoveryProperties.isAllNamespaces() ? Namespaces.NAMESPACE_ALL
- : kubernetesNamespaceProvider.getNamespace() == null ? Namespaces.NAMESPACE_DEFAULT
- : kubernetesNamespaceProvider.getNamespace();
+ String namespace = allNamespaces ? Namespaces.NAMESPACE_ALL : kubernetesNamespaceProvider.getNamespace() == null
+ ? Namespaces.NAMESPACE_DEFAULT : kubernetesNamespaceProvider.getNamespace();
this.apiClient.setHttpClient(this.apiClient.getHttpClient().newBuilder().readTimeout(Duration.ZERO).build());
diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java
index c6adf38483..c435047b5c 100644
--- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java
+++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java
@@ -17,6 +17,7 @@
package org.springframework.cloud.kubernetes.client.discovery;
import java.util.HashMap;
+import java.util.Map;
import io.kubernetes.client.informer.SharedInformerFactory;
import io.kubernetes.client.informer.cache.Cache;
@@ -59,6 +60,11 @@ public class KubernetesInformerDiscoveryClientTests {
.metadata(new V1ObjectMeta().name("test-svc-1").namespace("namespace2"))
.spec(new V1ServiceSpec().loadBalancerIP("1.1.1.1")).status(new V1ServiceStatus());
+ private static final V1Service testService3 = new V1Service()
+ .metadata(new V1ObjectMeta().name("test-svc-3").namespace("namespace1").putLabelsItem("spring", "true")
+ .putLabelsItem("k8s", "true"))
+ .spec(new V1ServiceSpec().loadBalancerIP("1.1.1.1")).status(new V1ServiceStatus());
+
private static final V1Endpoints testEndpoints1 = new V1Endpoints()
.metadata(new V1ObjectMeta().name("test-svc-1").namespace("namespace1"))
.addSubsetsItem(new V1EndpointSubset().addPortsItem(new V1EndpointPort().port(8080))
@@ -91,6 +97,11 @@ public class KubernetesInformerDiscoveryClientTests {
.addPortsItem(new V1EndpointPort().name("tcp2").port(443))
.addAddressesItem(new V1EndpointAddress().ip("1.1.1.1")));
+ private static final V1Endpoints testEndpoints3 = new V1Endpoints()
+ .metadata(new V1ObjectMeta().name("test-svc-3").namespace("namespace1"))
+ .addSubsetsItem(new V1EndpointSubset().addPortsItem(new V1EndpointPort().port(8080))
+ .addAddressesItem(new V1EndpointAddress().ip("2.2.2.2")));
+
@Test
public void testDiscoveryGetServicesAllNamespaceShouldWork() {
Lister serviceLister = setupServiceLister(testService1, testService2);
@@ -106,6 +117,44 @@ public void testDiscoveryGetServicesAllNamespaceShouldWork() {
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
}
+ @Test
+ public void testDiscoveryWithServiceLabels() {
+ Lister serviceLister = setupServiceLister(testService1, testService2, testService3);
+
+ Map labels = new HashMap<>();
+ labels.put("k8s", "true");
+ labels.put("spring", "true");
+
+ when(kubernetesDiscoveryProperties.getServiceLabels()).thenReturn(labels);
+
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("",
+ sharedInformerFactory, serviceLister, null, null, null, kubernetesDiscoveryProperties);
+
+ assertThat(discoveryClient.getServices().toArray()).containsOnly(testService3.getMetadata().getName());
+
+ verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
+ }
+
+ @Test
+ public void testDiscoveryInstancesWithServiceLabels() {
+ Lister serviceLister = setupServiceLister(testService1, testService2, testService3);
+ Lister endpointsLister = setupEndpointsLister(testEndpoints1, testEndpoints3);
+
+ Map labels = new HashMap<>();
+ labels.put("k8s", "true");
+ labels.put("spring", "true");
+
+ when(kubernetesDiscoveryProperties.isAllNamespaces()).thenReturn(true);
+ when(kubernetesDiscoveryProperties.getServiceLabels()).thenReturn(labels);
+
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("",
+ sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
+
+ assertThat(discoveryClient.getInstances("test-svc-1").toArray()).isEmpty();
+ assertThat(discoveryClient.getInstances("test-svc-3").toArray()).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-3", "2.2.2.2", 8080, new HashMap<>(), false, "namespace1", null));
+ }
+
@Test
public void testDiscoveryGetServicesOneNamespaceShouldWork() {
Lister serviceLister = setupServiceLister(testService1, testService2);
@@ -130,8 +179,8 @@ public void testDiscoveryGetInstanceAllNamespaceShouldWork() {
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(2)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
@@ -147,8 +196,8 @@ public void testDiscoveryGetInstanceOneNamespaceShouldWork() {
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
}
@@ -180,8 +229,8 @@ public void testDiscoveryGetInstanceWithNotReadyAddressesIncludedShouldWork() {
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
verify(kubernetesDiscoveryProperties, times(1)).isIncludeNotReadyAddresses();
@@ -226,8 +275,8 @@ public void instanceWithMultiplePortsAndPrimaryPortNameConfiguredWithLabelShould
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 443, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 443, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
verify(kubernetesDiscoveryProperties, times(1)).isIncludeNotReadyAddresses();
@@ -245,8 +294,8 @@ public void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelShoul
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
}
@@ -262,8 +311,8 @@ public void instanceWithMultiplePortsAndGenericPrimaryPortNameConfiguredShouldWo
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 443, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 443, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).isIncludeNotReadyAddresses();
@@ -281,8 +330,8 @@ public void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameShoul
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
}
@@ -297,8 +346,8 @@ public void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFal
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 443, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 443, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
}
@@ -313,8 +362,8 @@ public void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPo
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
}
@@ -330,8 +379,8 @@ public void instanceWithMultiplePortsAndWithoutAnyConfigurationShouldPickTheFirs
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
- assertThat(discoveryClient.getInstances("test-svc-1"))
- .containsOnly(new KubernetesServiceInstance("", "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false));
+ assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new KubernetesServiceInstance("",
+ "test-svc-1", "1.1.1.1", 80, new HashMap<>(), false, "namespace1", null));
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
verify(kubernetesDiscoveryProperties, times(1)).getPrimaryPortName();
}
diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java
index 519f2bb801..84dcaf9b81 100644
--- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java
+++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java
@@ -116,8 +116,9 @@ public void testDiscoveryGetInstanceAllNamespaceShouldWork() {
new KubernetesNamespaceProvider(new MockEnvironment()), sharedInformerFactory, serviceLister,
endpointsLister, null, null, kubernetesDiscoveryProperties);
- StepVerifier.create(discoveryClient.getInstances("test-svc-1"))
- .expectNext(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false))
+ StepVerifier
+ .create(discoveryClient.getInstances("test-svc-1")).expectNext(new KubernetesServiceInstance("",
+ "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false, "namespace1", null))
.expectComplete().verify();
verify(kubernetesDiscoveryProperties, times(2)).isAllNamespaces();
@@ -135,8 +136,9 @@ public void testDiscoveryGetInstanceOneNamespaceShouldWork() {
kubernetesNamespaceProvider, sharedInformerFactory, serviceLister, endpointsLister, null, null,
kubernetesDiscoveryProperties);
- StepVerifier.create(discoveryClient.getInstances("test-svc-1"))
- .expectNext(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false))
+ StepVerifier
+ .create(discoveryClient.getInstances("test-svc-1")).expectNext(new KubernetesServiceInstance("",
+ "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false, "namespace1", null))
.expectComplete().verify();
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
diff --git a/spring-cloud-kubernetes-commons/pom.xml b/spring-cloud-kubernetes-commons/pom.xml
index e7c682de51..ff8123c8e1 100644
--- a/spring-cloud-kubernetes-commons/pom.xml
+++ b/spring-cloud-kubernetes-commons/pom.xml
@@ -20,6 +20,10 @@
org.springframework.cloud
spring-cloud-commons