Merge remote-tracking branch 'origin/1.1.x'

This commit is contained in:
Ryan Baxter
2020-10-12 11:25:07 -04:00
4 changed files with 31 additions and 4 deletions

View File

@@ -104,7 +104,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.apply(KEY_VALUE_TO_PROPERTIES.apply(c)), content,
filename, composite);

View File

@@ -43,11 +43,14 @@ import static org.springframework.cloud.kubernetes.config.ConfigMapTestUtil.crea
properties = { "spring.application.name=configmap-path-example",
"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";
@@ -60,6 +63,9 @@ 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();
@@ -79,11 +85,11 @@ public class ConfigMapsFromFilePathsTests {
System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false");
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
@@ -116,4 +122,10 @@ public class ConfigMapsFromFilePathsTests {
.isEqualTo("Good morning, World!");
}
@Test
public void bonjourInputShouldReturnPropertyFromDuplicatedFile() {
this.webClient.get().uri("/api/bonjour").exchange().expectStatus().isOk().expectBody().jsonPath("content")
.isEqualTo("Bonjour from path!");
}
}

View File

@@ -49,4 +49,9 @@ 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));
}
}

View File

@@ -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;
}
}