|
45 | 45 |
|
46 | 46 | import static io.micronaut.kubernetes.client.v1.secrets.Secret.OPAQUE_SECRET_TYPE;
|
47 | 47 | import static io.micronaut.kubernetes.util.KubernetesUtils.computePodLabelSelector;
|
| 48 | +import static java.util.Collections.singletonMap; |
48 | 49 |
|
49 | 50 | /**
|
50 | 51 | * A {@link ConfigurationClient} implementation that provides {@link PropertySource}s read from Kubernetes ConfigMap's.
|
|
59 | 60 | @BootstrapContextCompatible
|
60 | 61 | public class KubernetesConfigurationClient implements ConfigurationClient {
|
61 | 62 |
|
| 63 | + public static final String CONFIG_MAP_LIST_RESOURCE_VERSION = "configMapListResourceVersion"; |
62 | 64 | public static final String CONFIG_MAP_RESOURCE_VERSION = "configMapResourceVersion";
|
| 65 | + public static final String KUBERNETES_CONFIG_MAP_LIST_NAME = "Kubernetes ConfigMapList"; |
63 | 66 | public static final String KUBERNETES_CONFIG_MAP_NAME_SUFFIX = " (Kubernetes ConfigMap)";
|
64 | 67 | public static final String KUBERNETES_SECRET_NAME_SUFFIX = " (Kubernetes Secret)";
|
65 | 68 |
|
@@ -154,15 +157,30 @@ private Flowable<PropertySource> getPropertySourcesFromConfigMaps() {
|
154 | 157 | LOG.debug("Found {} config maps. Applying includes/excludes filters (if any)", configMapList.getItems().size());
|
155 | 158 | }
|
156 | 159 | })
|
157 |
| - .flatMapIterable(ConfigMapList::getItems) |
158 |
| - .filter(includesFilter) |
159 |
| - .filter(excludesFilter) |
160 |
| - .doOnNext(configMap -> { |
161 |
| - if (LOG.isDebugEnabled()) { |
162 |
| - LOG.debug("Adding config map with name {}", configMap.getMetadata().getName()); |
163 |
| - } |
164 |
| - }) |
165 |
| - .map(KubernetesUtils::configMapAsPropertySource); |
| 160 | + .flatMap(configMapList -> Flowable.just(configMapListAsPropertySource(configMapList)) |
| 161 | + .mergeWith(Flowable.fromIterable(configMapList.getItems()) |
| 162 | + .filter(includesFilter) |
| 163 | + .filter(excludesFilter) |
| 164 | + .doOnNext(configMap -> { |
| 165 | + if (LOG.isDebugEnabled()) { |
| 166 | + LOG.debug("Adding config map with name {}", configMap.getMetadata().getName()); |
| 167 | + } |
| 168 | + }) |
| 169 | + .map(KubernetesUtils::configMapAsPropertySource))); |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Converts a {@link ConfigMapList} into a {@link PropertySource}. |
| 174 | + * |
| 175 | + * @param configMapList the ConfigMapList |
| 176 | + * @return A PropertySource |
| 177 | + */ |
| 178 | + private static PropertySource configMapListAsPropertySource(ConfigMapList configMapList) { |
| 179 | + String resourceVersion = configMapList.getMetadata().getResourceVersion(); |
| 180 | + if (LOG.isDebugEnabled()) { |
| 181 | + LOG.debug("Adding config map list with version {}", resourceVersion); |
| 182 | + } |
| 183 | + return PropertySource.of(KUBERNETES_CONFIG_MAP_LIST_NAME, singletonMap(CONFIG_MAP_LIST_RESOURCE_VERSION, resourceVersion), EnvironmentPropertySource.POSITION + 100); |
166 | 184 | }
|
167 | 185 |
|
168 | 186 | private Flowable<PropertySource> getPropertySourcesFromSecrets() {
|
|
0 commit comments