From 310ef6e9995fab302f6af8b284d0a59ca0f212e9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 13 Aug 2020 12:52:54 -0700 Subject: [PATCH] Rename volumemount -> configtree Closes gh-22941 --- .../docs/asciidoc/spring-boot-features.adoc | 14 ++--- ...r.java => ConfigTreeConfigDataLoader.java} | 12 ++-- ...java => ConfigTreeConfigDataLocation.java} | 12 ++-- ...ConfigTreeConfigDataLocationResolver.java} | 11 ++-- ...rce.java => ConfigTreePropertySource.java} | 20 +++---- ...itional-spring-configuration-metadata.json | 2 +- .../main/resources/META-INF/spring.factories | 8 +-- ...a => ConfigTreeConfigDataLoaderTests.java} | 10 ++-- ...gTreeConfigDataLocationResolverTests.java} | 12 ++-- ...=> ConfigTreeConfigDataLocationTests.java} | 18 +++--- ...ava => ConfigTreePropertySourceTests.java} | 55 +++++++++---------- 11 files changed, 87 insertions(+), 87 deletions(-) rename spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/{VolumeMountConfigDataLoader.java => ConfigTreeConfigDataLoader.java} (66%) rename spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/{VolumeMountConfigDataLocation.java => ConfigTreeConfigDataLocation.java} (77%) rename spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/{VolumeMountConfigDataLocationResolver.java => ConfigTreeConfigDataLocationResolver.java} (66%) rename spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/{VolumeMountDirectoryPropertySource.java => ConfigTreePropertySource.java} (91%) rename spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/{VolumeMountConfigDataLoaderTests.java => ConfigTreeConfigDataLoaderTests.java} (80%) rename spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/{VolumeMountConfigDataLocationResolverTests.java => ConfigTreeConfigDataLocationResolverTests.java} (74%) rename spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/{VolumeMountConfigDataLocationTests.java => ConfigTreeConfigDataLocationTests.java} (62%) rename spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/{VolumeMountDirectoryPropertySourceTests.java => ConfigTreePropertySourceTests.java} (74%) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 5d7f76bea6..fd1f7e5976 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -675,7 +675,7 @@ Locations will be processed in the order that they are defined, with later impor [TIP] ==== Spring Boot includes pluggable API that allows various different location addresses to be supported. -By default you can import Java Properties, YAML and volume mounts. +By default you can import Java Properties, YAML and "`<>`". Third-party jars can offer support for additional technologies (there's no requirement for files to be local). For example, you can imagine config data being from external stores such as Consul, Apache ZooKeeper or Netflix Archaius. @@ -685,8 +685,8 @@ If you want to support your own locations, see the `ConfigDataLocationResolver` -[[boot-features-external-config-files-voumemounts]] -==== Using Volume Mount Properties +[[boot-features-external-config-files-configtree]] +==== Using Configuration Trees When running applications on a cloud platform (such as Kubernetes) you often need to read config values that the platform supplies. It's not uncommon to use environment variables for such purposes, but this can have drawbacks, especially if the value is supposed to be kept secret. @@ -696,10 +696,10 @@ For example, Kubernetes can volume mount both https://kubernetes.io/docs/tasks/c There are two common volume mount patterns that can be use: . A single file contains a complete set of properties (usually written as YAML). -. Multiple files are written to a directory with the filename becoming the '`key`' and the contents becoming the '`value`'. +. Multiple files are written to a directory tree, with the filename becoming the '`key`' and the contents becoming the '`value`'. For the first case, you can import the YAML or Properties file directly using `spring.config.import` as described <>. -For the second case, you need to use the `volumemount:` prefix so that Spring Boot knows it needs to expose all the files as properties. +For the second case, you need to use the `configtree:` prefix so that Spring Boot knows it needs to expose all the files as properties. As an example, let's imagine that Kubernetes has mounted the following volume: @@ -718,12 +718,12 @@ To import these properties, you can add the following to your `application.prope [source,properties,indent=0] ---- -spring.config.import=volumemount:/etc/config +spring.config.import=configtree:/etc/config ---- You can then access or inject `myapp.username` and `myapp.password` properties from the `Environment` in the usual way. -TIP: Volume mounted values can be bound to both string `String` and `byte[]` types depending on the contents expected. +TIP: Configuration tree values can be bound to both string `String` and `byte[]` types depending on the contents expected. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java similarity index 66% rename from spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLoader.java rename to spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java index 2fc409c178..86ae330683 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java @@ -20,21 +20,21 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Collections; -import org.springframework.boot.env.VolumeMountDirectoryPropertySource; +import org.springframework.boot.env.ConfigTreePropertySource; /** - * {@link ConfigDataLoader} for directory locations mounted as volumes. + * {@link ConfigDataLoader} for config tree locations. * * @author Madhura Bhave * @author Phillip Webb */ -class VolumeMountConfigDataLoader implements ConfigDataLoader { +class ConfigTreeConfigDataLoader implements ConfigDataLoader { @Override - public ConfigData load(VolumeMountConfigDataLocation location) throws IOException { + public ConfigData load(ConfigTreeConfigDataLocation location) throws IOException { Path path = location.getPath(); - String name = "Volume mount config '" + path + "'"; - VolumeMountDirectoryPropertySource source = new VolumeMountDirectoryPropertySource(name, path); + String name = "Config tree '" + path + "'"; + ConfigTreePropertySource source = new ConfigTreePropertySource(name, path); return new ConfigData(Collections.singletonList(source)); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLocation.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocation.java similarity index 77% rename from spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLocation.java rename to spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocation.java index 358d7c229d..824067d696 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLocation.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocation.java @@ -20,19 +20,21 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Objects; +import org.springframework.boot.env.ConfigTreePropertySource; import org.springframework.util.Assert; /** - * {@link ConfigDataLocation} backed by a directory mounted as a volume. + * {@link ConfigDataLocation} backed by a config tree directory. * * @author Madhura Bhave * @author Phillip Webb + * @see ConfigTreePropertySource */ -class VolumeMountConfigDataLocation extends ConfigDataLocation { +class ConfigTreeConfigDataLocation extends ConfigDataLocation { private final Path path; - VolumeMountConfigDataLocation(String path) { + ConfigTreeConfigDataLocation(String path) { Assert.notNull(path, "Path must not be null"); this.path = Paths.get(path).toAbsolutePath(); } @@ -49,7 +51,7 @@ class VolumeMountConfigDataLocation extends ConfigDataLocation { if (obj == null || getClass() != obj.getClass()) { return false; } - VolumeMountConfigDataLocation other = (VolumeMountConfigDataLocation) obj; + ConfigTreeConfigDataLocation other = (ConfigTreeConfigDataLocation) obj; return Objects.equals(this.path, other.path); } @@ -60,7 +62,7 @@ class VolumeMountConfigDataLocation extends ConfigDataLocation { @Override public String toString() { - return "volume mount [" + this.path + "]"; + return "config tree [" + this.path + "]"; } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLocationResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java similarity index 66% rename from spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLocationResolver.java rename to spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java index 9f3fd9e0fc..d6a84a9e5a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/VolumeMountConfigDataLocationResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java @@ -20,15 +20,14 @@ import java.util.Collections; import java.util.List; /** - * {@link ConfigDataLocationResolver} for volume mounted locations such as Kubernetes - * ConfigMaps and Secrets. + * {@link ConfigDataLocationResolver} for config tree locations. * * @author Madhura Bhave * @author Phillip Webb */ -class VolumeMountConfigDataLocationResolver implements ConfigDataLocationResolver { +class ConfigTreeConfigDataLocationResolver implements ConfigDataLocationResolver { - private static final String PREFIX = "volumemount:"; + private static final String PREFIX = "configtree:"; @Override public boolean isResolvable(ConfigDataLocationResolverContext context, String location) { @@ -36,8 +35,8 @@ class VolumeMountConfigDataLocationResolver implements ConfigDataLocationResolve } @Override - public List resolve(ConfigDataLocationResolverContext context, String location) { - VolumeMountConfigDataLocation resolved = new VolumeMountConfigDataLocation(location.substring(PREFIX.length())); + public List resolve(ConfigDataLocationResolverContext context, String location) { + ConfigTreeConfigDataLocation resolved = new ConfigTreeConfigDataLocation(location.substring(PREFIX.length())); return Collections.singletonList(resolved); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java similarity index 91% rename from spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java rename to spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java index 7bb667b5da..dfe552a8d9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java @@ -46,16 +46,16 @@ import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; /** - * {@link PropertySource} backed by a directory that contains files for each value. The - * {@link PropertySource} will recursively scan a given source directory and expose a + * {@link PropertySource} backed by a directory tree that contains files for each value. + * The {@link PropertySource} will recursively scan a given source directory and expose a * property for each file found. The property name will be the filename, and the property * value will be the contents of the file. *

* Directories are only scanned when the source is first created. The directory is not * monitored for updates, so files should not be added or removed. However, the contents * of a file can be updated as long as the property source was created with a - * {@link Option#ALWAYS_READ} option. Nested folders are included in the source, but with - * a {@code '.'} rather than {@code '/'} used as the path separator. + * {@link Option#ALWAYS_READ} option. Nested directories are included in the source, but + * with a {@code '.'} rather than {@code '/'} used as the path separator. *

* Property values are returned as {@link Value} instances which allows them to be treated * either as an {@link InputStreamSource} or as a {@link CharSequence}. In addition, if @@ -69,7 +69,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @since 2.4.0 */ -public class VolumeMountDirectoryPropertySource extends EnumerablePropertySource implements OriginLookup { +public class ConfigTreePropertySource extends EnumerablePropertySource implements OriginLookup { private static final int MAX_DEPTH = 100; @@ -80,25 +80,25 @@ public class VolumeMountDirectoryPropertySource extends EnumerablePropertySource private final Set