From 557fc8e9f2ba5b8db3dd61a9812abee17d772ffb Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Tue, 19 Apr 2016 12:31:10 +0300 Subject: [PATCH] First draft of configmap support as a property source. Add configmap archaius integration. --- pom.xml | 12 +- spring-cloud-kubernetes-archaius/pom.xml | 73 +++++++++ .../archaius/ArchaiusConfigMapSource.java | 51 +++++++ .../ArchaiusConfigMapSourceConfiguration.java | 140 ++++++++++++++++++ .../ArchaiusConfigMapSourceRegistar.java | 91 ++++++++++++ spring-cloud-kubernetes-core/pom.xml | 11 ++ .../ConfigMapBootstrapConfiguration.java | 46 ++++++ .../config/ConfigMapConfigProperties.java | 52 +++++++ .../config/ConfigMapPropertySource.java | 67 +++++++++ .../ConfigMapPropertySourceLocator.java | 51 +++++++ .../main/resources/META-INF/spring.factories | 3 + spring-cloud-starter-kubernetes-all/pom.xml | 6 +- 12 files changed, 599 insertions(+), 4 deletions(-) create mode 100644 spring-cloud-kubernetes-archaius/pom.xml create mode 100644 spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSource.java create mode 100644 spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceConfiguration.java create mode 100644 spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceRegistar.java create mode 100644 spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapBootstrapConfiguration.java create mode 100644 spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapConfigProperties.java create mode 100644 spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySource.java create mode 100644 spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySourceLocator.java diff --git a/pom.xml b/pom.xml index 1381a8d0..3d519439 100644 --- a/pom.xml +++ b/pom.xml @@ -76,19 +76,18 @@ - 1.3.74 + 1.3.83 1.16.8 2.5 1.3.3.RELEASE 1.0.4.RELEASE - 1.0.4.RELEASE 1.0.0.RC1 1.0.6.RELEASE 4.2.5.RELEASE 0.14.2 - 2.2.98 + 2.2.103 3.5 @@ -100,6 +99,7 @@ spring-cloud-kubernetes-zipkin spring-cloud-kubernetes-compat spring-cloud-kubernetes-hystrix + spring-cloud-kubernetes-archaius spring-cloud-starter-kubernetes-netflix spring-cloud-starter-kubernetes-zipkin spring-cloud-starter-kubernetes-all @@ -114,6 +114,12 @@ ${project.version} + + io.fabric8 + spring-cloud-kubernetes-archaius + ${project.version} + + io.fabric8 spring-cloud-kubernetes-discovery diff --git a/spring-cloud-kubernetes-archaius/pom.xml b/spring-cloud-kubernetes-archaius/pom.xml new file mode 100644 index 00000000..da1f47b9 --- /dev/null +++ b/spring-cloud-kubernetes-archaius/pom.xml @@ -0,0 +1,73 @@ + + + + + + spring-cloud-kubernetes-project + io.fabric8 + 0.1-SNAPSHOT + + 4.0.0 + + io.fabric8 + spring-cloud-kubernetes-archaius + Fabric8 :: Spring Cloud Kubernetes :: Archaius + + + + + io.fabric8 + kubernetes-client + + + + org.springframework.cloud + spring-cloud-commons + true + + + + org.springframework.cloud + spring-cloud-context + true + + + + org.springframework.cloud + spring-cloud-netflix-core + true + + + + com.netflix.archaius + archaius-core + true + + + + org.projectlombok + lombok + provided + true + + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSource.java b/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSource.java new file mode 100644 index 00000000..a375b6a9 --- /dev/null +++ b/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSource.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.archaius; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Configuration +@Import(ArchaiusConfigMapSourceRegistar.class) +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface ArchaiusConfigMapSource { + + + /** + * Synonym for name (the name of the ConfigMap). + */ + String value() default ""; + + /** + * The name of the {@link io.fabric8.kubernetes.api.model.ConfigMap}. + */ + String name() default ""; + + /** + * The namespacex of the {@link io.fabric8.kubernetes.api.model.ConfigMap}. + */ + String namespace() default ""; +} diff --git a/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceConfiguration.java b/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceConfiguration.java new file mode 100644 index 00000000..0899dad5 --- /dev/null +++ b/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceConfiguration.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.archaius; + +import com.google.common.base.Strings; +import com.netflix.config.WatchedConfigurationSource; +import com.netflix.config.WatchedUpdateListener; +import com.netflix.config.WatchedUpdateResult; +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.Watch; +import io.fabric8.kubernetes.client.Watcher; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; + +import java.io.Closeable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +public class ArchaiusConfigMapSourceConfiguration implements InitializingBean, DisposableBean, WatchedConfigurationSource, Closeable { + + private final KubernetesClient client; + private final String name; + private final String namespace; + private final List listeners = new ArrayList<>(); + + private final AtomicBoolean started = new AtomicBoolean(false); + private final ExecutorService executorService = Executors.newSingleThreadExecutor(); + private AtomicReference> currentData = new AtomicReference<>(); + private Watch watch; + + private volatile Watcher watcher = new Watcher() { + @Override + public void eventReceived(Action action, ConfigMap configMap) { + offer(WatchedUpdateResult.createFull(asObjectMap(configMap.getData()))); + } + + @Override + public void onClose(KubernetesClientException e) { + + } + }; + + public ArchaiusConfigMapSourceConfiguration(KubernetesClient client, String name, String namespace) { + this.client = client; + this.name = name; + this.namespace = namespace; + } + + + public void start() { + ConfigMap map = Strings.isNullOrEmpty(namespace) + ? client.configMaps().withName(name).get() + : client.configMaps().inNamespace(namespace).withName(name).get(); + + if (map != null) { + currentData.set(asObjectMap(map.getData())); + } + watch = Strings.isNullOrEmpty(namespace) + ? client.configMaps().withName(name).watch(watcher) + : client.configMaps().inNamespace(namespace).withName(namespace).watch(watcher); + started.set(true); + } + + @Override + public void close() throws IOException { + started.set(false); + if (watch != null) { + watch.close(); + } + executorService.shutdown(); + } + + @Override + public synchronized void addUpdateListener(WatchedUpdateListener watchedUpdateListener) { + listeners.add(watchedUpdateListener); + } + + @Override + public synchronized void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) { + listeners.remove(watchedUpdateListener); + } + + @Override + public Map getCurrentData() throws Exception { + return currentData.get(); + } + + private void offer(WatchedUpdateResult event) { + submit(() -> { + listeners.stream().forEach(l -> l.updateConfiguration(event)); + currentData.set(event.getComplete()); + }); + } + + private synchronized void submit(final Runnable command) { + if (started.get()) { + executorService.submit(command); + } + } + + private static Map asObjectMap(Map source) { + return source.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + @Override + public void destroy() throws Exception { + close(); + } + + @Override + public void afterPropertiesSet() throws Exception { + start(); + } +} diff --git a/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceRegistar.java b/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceRegistar.java new file mode 100644 index 00000000..0bbd89da --- /dev/null +++ b/spring-cloud-kubernetes-archaius/src/main/java/io/fabric8/spring/cloud/kubernetes/archaius/ArchaiusConfigMapSourceRegistar.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.archaius; + +import com.netflix.config.DynamicWatchedConfiguration; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.util.StringUtils; + +import java.util.Map; + +class ArchaiusConfigMapSourceRegistar implements ImportBeanDefinitionRegistrar { + + private static final String KUBERNETES_CLIENT_REF = "kubernetesClient"; + + private static final String VALUE_ATTR = "value"; + private static final String NAME_ATTR = "name"; + private static final String NAMESPACE_ATTR = "namespace"; + + private static final String CONFIG_MAP_SOURCE_SUFFIX = ".ConfigMapSourceConfiguration"; + private static final String DYNAMIC_WATCH_CONFIG_SUFFIX = ".DynamicWatchedConfiguration"; + + @Override + public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { + + Map source = metadata.getAnnotationAttributes(ArchaiusConfigMapSource.class.getName(), true); + String name = getSourceName(source); + String namespace = getSourceNamespace(source); + if (name != null) { + registerSourceConfiguration(registry, name, namespace); + } + } + + private String getSourceName(Map source) { + if (source == null) { + return null; + } + String value = (String) source.get(VALUE_ATTR); + if (!StringUtils.hasText(value)) { + value = (String) source.get(NAME_ATTR); + } + if (StringUtils.hasText(value)) { + return value; + } + throw new IllegalStateException( + "Either 'name' or 'value' must be provided in @ConfigMapSource"); + } + + private String getSourceNamespace(Map source) { + if (source == null) { + return null; + } + String namespace = (String) source.get(NAMESPACE_ATTR); + if (StringUtils.hasText(namespace)) { + return namespace; + } + return null; + } + + private void registerSourceConfiguration(BeanDefinitionRegistry registry, Object name, Object namespace) { + BeanDefinitionBuilder configMapSourceConfigBuilder = BeanDefinitionBuilder.genericBeanDefinition(ArchaiusConfigMapSourceConfiguration.class); + BeanDefinitionBuilder dynamicWatchedConfigBuilder = BeanDefinitionBuilder.genericBeanDefinition(DynamicWatchedConfiguration.class); + + configMapSourceConfigBuilder.addConstructorArgReference(KUBERNETES_CLIENT_REF); + configMapSourceConfigBuilder.addConstructorArgValue(name); + configMapSourceConfigBuilder.addConstructorArgValue(namespace); + String configMapSourceConfigName = name + CONFIG_MAP_SOURCE_SUFFIX; + registry.registerBeanDefinition(configMapSourceConfigName, configMapSourceConfigBuilder.getBeanDefinition()); + + String dynamicWatchedConfigName = name + DYNAMIC_WATCH_CONFIG_SUFFIX; + dynamicWatchedConfigBuilder.addConstructorArgReference(configMapSourceConfigName); + registry.registerBeanDefinition(dynamicWatchedConfigName, dynamicWatchedConfigBuilder.getBeanDefinition()); + } +} \ No newline at end of file diff --git a/spring-cloud-kubernetes-core/pom.xml b/spring-cloud-kubernetes-core/pom.xml index 44e68da9..ac0dff68 100644 --- a/spring-cloud-kubernetes-core/pom.xml +++ b/spring-cloud-kubernetes-core/pom.xml @@ -41,6 +41,17 @@ org.springframework.boot spring-boot-autoconfigure + + org.springframework.cloud + spring-cloud-context + true + + + org.projectlombok + lombok + + provided + \ No newline at end of file diff --git a/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapBootstrapConfiguration.java b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapBootstrapConfiguration.java new file mode 100644 index 00000000..543bc4e9 --- /dev/null +++ b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapBootstrapConfiguration.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.config; + +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.spring.cloud.kubernetes.KubernetesAutoConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@ConditionalOnProperty(value = "spring.cloud.kubernetes.enabled", matchIfMissing = true) +public class ConfigMapBootstrapConfiguration { + + @Configuration + @EnableConfigurationProperties(ConfigMapConfigProperties.class) + @Import(KubernetesAutoConfiguration.class) + @ConditionalOnProperty(name = "spring.cloud.kubernetes.config.enabled", matchIfMissing = true) + protected static class KubernetesPropertySourceConfiguration { + @Autowired + private KubernetesClient client; + + @Bean + public ConfigMapPropertySourceLocator configMapPropertySourceLocator(ConfigMapConfigProperties properties) { + return new ConfigMapPropertySourceLocator(client, properties); + } + } +} diff --git a/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapConfigProperties.java b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapConfigProperties.java new file mode 100644 index 00000000..245692ab --- /dev/null +++ b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapConfigProperties.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("spring.cloud.kubernetes.config") +public class ConfigMapConfigProperties { + + private boolean enabled = true; + private String name; + private String namespace; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } +} diff --git a/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySource.java b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySource.java new file mode 100644 index 00000000..74a2df7f --- /dev/null +++ b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySource.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.config; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.client.KubernetesClient; +import org.springframework.core.env.MapPropertySource; + +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +public class ConfigMapPropertySource extends MapPropertySource { + + private static final String PREFIX = "configmap"; + private static final String SEPARATOR = "."; + + private final KubernetesClient client; + private final String name; + private final String namespace; + + public ConfigMapPropertySource(KubernetesClient client, String name) { + this(client, name, null); + } + + public ConfigMapPropertySource(KubernetesClient client, String name, String namespace) { + super(getName(client, name, namespace), asObjectMap(getData(client, name, namespace))); + this.client = client; + this.name = name; + this.namespace = namespace; + } + + private static String getName(KubernetesClient client, String name, String namespace) { + StringBuilder sb = new StringBuilder(); + sb.append(PREFIX).append(SEPARATOR).append(name).append(SEPARATOR).append(namespace == null || namespace.isEmpty() ? client.getNamespace() : namespace); + return sb.toString(); + } + + private static Map getData(KubernetesClient client, String name, String namespace) { + ConfigMap map = namespace == null || namespace.isEmpty() + ? client.configMaps().withName(name).get() + : client.configMaps().inNamespace(namespace).withName(name).get(); + + return map != null ? map.getData() : Collections.emptyMap(); + } + + private static Map asObjectMap(Map source) { + return source.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } +} diff --git a/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySourceLocator.java new file mode 100644 index 00000000..ecedbf0d --- /dev/null +++ b/spring-cloud-kubernetes-core/src/main/java/io/fabric8/spring/cloud/kubernetes/config/ConfigMapPropertySourceLocator.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 to the original 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 + * + * http://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 io.fabric8.spring.cloud.kubernetes.config; + +import io.fabric8.kubernetes.client.KubernetesClient; +import org.springframework.cloud.bootstrap.config.PropertySourceLocator; +import org.springframework.core.annotation.Order; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertySource; + +@Order(0) +public class ConfigMapPropertySourceLocator implements PropertySourceLocator { + + private static final String SPRING_APPLICATION_NAME = "spring.application.name"; + + private final KubernetesClient client; + private final ConfigMapConfigProperties properties; + + public ConfigMapPropertySourceLocator(KubernetesClient client, ConfigMapConfigProperties properties) { + this.client = client; + this.properties = properties; + } + + @Override + public PropertySource locate(Environment environment) { + if (environment instanceof ConfigurableEnvironment) { + ConfigurableEnvironment env = (ConfigurableEnvironment) environment; + String appName = env.getProperty(SPRING_APPLICATION_NAME); + String name = properties.getName() == null || properties.getName().isEmpty() ? appName : properties.getName(); + String namespace = properties.getNamespace(); + return new ConfigMapPropertySource(client, name, namespace); + } + return null; + } +} diff --git a/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories b/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories index 6ed9c329..d055546b 100644 --- a/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories @@ -1,5 +1,8 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ io.fabric8.spring.cloud.kubernetes.KubernetesAutoConfiguration +org.springframework.cloud.bootstrap.BootstrapConfiguration=\ +io.fabric8.spring.cloud.kubernetes.config.ConfigMapBootstrapConfiguration + org.springframework.context.ApplicationContextInitializer=\ io.fabric8.spring.cloud.kubernetes.profile.KubernetesApplicationContextInitializer diff --git a/spring-cloud-starter-kubernetes-all/pom.xml b/spring-cloud-starter-kubernetes-all/pom.xml index 49bdbf12..f0143df8 100644 --- a/spring-cloud-starter-kubernetes-all/pom.xml +++ b/spring-cloud-starter-kubernetes-all/pom.xml @@ -41,6 +41,11 @@ spring-cloud-kubernetes-discovery + + io.fabric8 + spring-cloud-kubernetes-archaius + + io.fabric8 spring-cloud-kubernetes-ribbon @@ -70,7 +75,6 @@ org.aspectj aspectjrt - \ No newline at end of file