ensure config map names are unique based on absolute path, allowing same file names to be specified in different places (#604)
This commit is contained in:
@@ -113,7 +113,7 @@ public class ConfigMapPropertySourceLocator implements PropertySourceLocator {
|
||||
}).filter(Files::isRegularFile).forEach(p -> {
|
||||
try {
|
||||
String content = new String(Files.readAllBytes(p)).trim();
|
||||
String filename = p.getFileName().toString().toLowerCase();
|
||||
String filename = p.toAbsolutePath().toString().toLowerCase();
|
||||
if (filename.endsWith(".properties")) {
|
||||
addPropertySourceIfNeeded(
|
||||
c -> PROPERTIES_TO_MAP
|
||||
|
||||
@@ -45,11 +45,14 @@ import static org.springframework.cloud.kubernetes.config.ConfigMapTestUtil.crea
|
||||
"spring.cloud.kubernetes.config.enableApi=false",
|
||||
"spring.cloud.kubernetes.config.paths="
|
||||
+ ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_FULL_PATH + ","
|
||||
+ ConfigMapsFromFilePathsTests.SECOND_FILE_NAME_FULL_PATH })
|
||||
+ ConfigMapsFromFilePathsTests.SECOND_FILE_NAME_FULL_PATH + ","
|
||||
+ ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_DUPLICATED_FULL_PATH})
|
||||
public class ConfigMapsFromFilePathsTests {
|
||||
|
||||
protected static final String FILES_ROOT_PATH = "/tmp/scktests";
|
||||
|
||||
protected static final String FILES_SUB_PATH = "another-directory";
|
||||
|
||||
protected static final String FIRST_FILE_NAME = "application.properties";
|
||||
|
||||
protected static final String SECOND_FILE_NAME = "extra.properties";
|
||||
@@ -65,6 +68,10 @@ public class ConfigMapsFromFilePathsTests {
|
||||
protected static final String UNUSED_FILE_NAME_FULL_PATH = FILES_ROOT_PATH + "/"
|
||||
+ UNUSED_FILE_NAME;
|
||||
|
||||
protected static final String FIRST_FILE_NAME_DUPLICATED_FULL_PATH = FILES_ROOT_PATH + "/"
|
||||
+ FILES_SUB_PATH + "/"
|
||||
+ FIRST_FILE_NAME;
|
||||
|
||||
@ClassRule
|
||||
public static KubernetesServer server = new KubernetesServer();
|
||||
|
||||
@@ -87,12 +94,13 @@ public class ConfigMapsFromFilePathsTests {
|
||||
System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "test");
|
||||
System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true");
|
||||
|
||||
Files.createDirectories(Paths.get(FILES_ROOT_PATH));
|
||||
Files.createDirectories(Paths.get(FILES_ROOT_PATH + "/" + FILES_SUB_PATH));
|
||||
createFileWithContent(FIRST_FILE_NAME_FULL_PATH,
|
||||
"bean.greeting=Hello from path!");
|
||||
createFileWithContent(SECOND_FILE_NAME_FULL_PATH, "bean.farewell=Bye from path!");
|
||||
createFileWithContent(UNUSED_FILE_NAME_FULL_PATH,
|
||||
"bean.morning=Morning from path!");
|
||||
createFileWithContent(FIRST_FILE_NAME_DUPLICATED_FULL_PATH, "bean.bonjour=Bonjour from path!");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -125,4 +133,10 @@ public class ConfigMapsFromFilePathsTests {
|
||||
.expectBody().jsonPath("content").isEqualTo("Good morning, World!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bonjourInputShouldReturnPropertyFromDuplicatedFile() {
|
||||
this.webClient.get().uri("/api/bonjour").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("content").isEqualTo("Bonjour from path!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,4 +52,10 @@ public class GreetingController {
|
||||
return new ResponseMessage(String.format(this.properties.getMorning(), name));
|
||||
}
|
||||
|
||||
@RequestMapping("/api/bonjour")
|
||||
public ResponseMessage bonjour(
|
||||
@RequestParam(value = "name", defaultValue = "World") String name) {
|
||||
return new ResponseMessage(String.format(this.properties.getBonjour(), name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ public class GreetingProperties {
|
||||
|
||||
private String morning = "Good morning, %s!";
|
||||
|
||||
private String bonjour = "Bonjour, %s!";
|
||||
|
||||
public String getGreeting() {
|
||||
return this.greeting;
|
||||
}
|
||||
@@ -51,4 +53,12 @@ public class GreetingProperties {
|
||||
this.morning = morning;
|
||||
}
|
||||
|
||||
public String getBonjour() {
|
||||
return this.bonjour;
|
||||
}
|
||||
|
||||
public void setBonjour(String bonjour) {
|
||||
this.bonjour = bonjour;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user