Skip to content

Commit b47de1e

Browse files
authored
Merge pull request #2039 from wind57/fix-1681
Fix #1681
2 parents 806c7c2 + 7fa15f7 commit b47de1e

File tree

91 files changed

+5456
-1428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+5456
-1428
lines changed

docs/modules/ROOT/pages/property-source-config/configmap-propertysource.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ spring:
540540
includeProfileSpecificSources: false
541541
----
542542

543-
NOTE: Since version `5.0.0-M1`, `includeProfileSpecificSources` is only supported for named sources (`spring.cloud.kubernetes.sources.name=XXX`); support for labeled sources has been removed.
543+
NOTE: Since version `5.0.0`, `includeProfileSpecificSources` is only supported for named sources (`spring.cloud.kubernetes.sources.name=XXX`); support for labeled sources has been removed.
544544

545545

546546
Notice that just like before, there are two levels where you can specify this property: for all config maps or
@@ -588,6 +588,9 @@ NOTE: If you already have `spring-retry` and `spring-boot-starter-aspectj` on th
588588
and want to enable fail-fast, but do not want retry to be enabled; you can disable retry for `ConfigMap` `PropertySources`
589589
by setting `spring.cloud.kubernetes.config.retry.enabled=false`.
590590

591+
592+
NOTE: Since version `5.0.0`, we have introduced the possibility to read sources individually. Until now, we would go to the namespace and read all the configmaps / secrets available and then filter out the ones requested. Since `5.0.0-M3` you can specify that you want to read them individually, by setting the property: `spring.cloud.kubernetes.config.read-type=SINGLE`. The previous option to read them all in a namespace is controlled by `spring.cloud.kubernetes.config.read-type=BATCH` and it is the default option.
593+
591594
.Properties:
592595
[options="header,footer"]
593596
|===

docs/modules/ROOT/pages/spring-cloud-kubernetes-configserver.adoc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,39 @@ A default image is located on https://hub.docker.com/r/springcloud/spring-cloud-
1111
the code and image yourself. However, if you need to customize the config server behavior or prefer to build the image yourself you can easily build your own
1212
image from the https://github.com/spring-cloud/spring-cloud-kubernetes/tree/main/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver[source code on GitHub] and use that.
1313

14-
## Configuration
14+
== Configuration
1515

16-
### Enabling The Kubernetes Environment Repository
16+
=== Enabling The Kubernetes Environment Repository
1717
To enable the Kubernetes environment repository the `kubernetes` profile must be included in the list of active profiles.
1818
You may activate other profiles as well to use other environment repository implementations.
1919

20-
### Config Map and Secret PropertySources
20+
=== Config Map and Secret PropertySources
2121
By default, only Config Map data will be fetched. To enable Secrets as well you will need to set `spring.cloud.kubernetes.secrets.enableApi=true`.
2222
You can disable the Config Map `PropertySource` by setting `spring.cloud.kubernetes.config.enableApi=false`.
2323

24-
### Fetching Config Map and Secret Data From Additional Namespaces
24+
=== Fetching Config Map and Secret Data From Additional Namespaces
2525
By default, the Kubernetes environment repository will only fetch Config Map and Secrets from the namespace in which it is deployed.
2626
If you want to include data from other namespaces you can set `spring.cloud.kubernetes.configserver.config-map-namespaces` and/or `spring.cloud.kubernetes.configserver.secrets-namespaces` to a comma separated
2727
list of namespace values.
2828

2929
NOTE: If you set `spring.cloud.kubernetes.configserver.config-map-namespaces` and/or `spring.cloud.kubernetes.configserver.secrets-namespaces`
3030
you will need to include the namespace in which the Config Server is deployed in order to continue to fetch Config Map and Secret data from that namespace.
3131

32-
### Using Advanced Features Of Spring Vault
32+
=== Using Advanced Features Of Spring Vault
3333
In order to use some of the https://docs.spring.io/spring-cloud-config/reference/server/environment-repository/vault-backend.html[more advanced Spring Vault features] of the **Spring Cloud Config Server**, https://mvnrepository.com/artifact/org.springframework.vault/spring-vault-core[`spring-vault-core`] must be on the classpath. By default, Spring Cloud Kubernetes can generate a Docker image for deploying Config Server to Kubernetes, but it does not include `spring-vault-core` in the classpath. If you need `spring-vault-core` to enable certain functionality in the Config Server you can build your own version of Docker image by enabling the `vault` Maven profile when running Maven build.
3434

3535
Example:
36-
```bash
36+
37+
[source,bash]
38+
----
3739
$ ../../mvnw clean install -Pvault
38-
```
40+
----
3941

40-
### Kubernetes Access Controls
42+
=== Kubernetes Access Controls
4143
The Kubernetes Config Server uses the Kubernetes API server to fetch Config Map and Secret data. In order for it to do that
4244
it needs ability to `get` and `list` Config Map and Secrets (depending on what you enable/disable).
4345

44-
## Deployment Yaml
46+
== Deployment Yaml
4547

4648
Below is a sample deployment, service and permissions configuration you can use to deploy a basic Config Server to Kubernetes.
4749

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigContext.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.kubernetes.client.openapi.apis.CoreV1Api;
2020

2121
import org.springframework.cloud.kubernetes.commons.config.NormalizedSource;
22+
import org.springframework.cloud.kubernetes.commons.config.ReadType;
2223
import org.springframework.core.env.Environment;
2324

2425
/**
@@ -27,10 +28,5 @@
2728
* @author wind57
2829
*/
2930
public record KubernetesClientConfigContext(CoreV1Api client, NormalizedSource normalizedSource, String namespace,
30-
Environment environment, boolean includeDefaultProfileData) {
31-
32-
public KubernetesClientConfigContext(CoreV1Api client, NormalizedSource normalizedSource, String namespace,
33-
Environment environment) {
34-
this(client, normalizedSource, namespace, environment, true);
35-
}
31+
Environment environment, boolean includeDefaultProfileData, ReadType readType) {
3632
}

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigDataLocationResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected void registerBeans(ConfigDataLocationResolverContext resolverContext,
6464
coreV1Api, configMapProperties, namespaceProvider);
6565
if (isRetryEnabledForConfigMap(configMapProperties)) {
6666
configMapPropertySourceLocator = new ConfigDataRetryableConfigMapPropertySourceLocator(
67-
configMapPropertySourceLocator, configMapProperties, new KubernetesClientConfigMapsCache());
67+
configMapPropertySourceLocator, configMapProperties);
6868
}
6969

7070
registerSingle(bootstrapContext, ConfigMapPropertySourceLocator.class, configMapPropertySourceLocator,
@@ -76,7 +76,7 @@ protected void registerBeans(ConfigDataLocationResolverContext resolverContext,
7676
coreV1Api, namespaceProvider, secretsProperties);
7777
if (isRetryEnabledForSecrets(secretsProperties)) {
7878
secretsPropertySourceLocator = new ConfigDataRetryableSecretsPropertySourceLocator(
79-
secretsPropertySourceLocator, secretsProperties, new KubernetesClientSecretsCache());
79+
secretsPropertySourceLocator, secretsProperties);
8080
}
8181

8282
registerSingle(bootstrapContext, SecretsPropertySourceLocator.class, secretsPropertySourceLocator,

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
2323
import org.springframework.cloud.kubernetes.commons.config.ConfigMapPropertySourceLocator;
2424
import org.springframework.cloud.kubernetes.commons.config.NormalizedSource;
25+
import org.springframework.cloud.kubernetes.commons.config.ReadType;
2526
import org.springframework.core.annotation.Order;
2627
import org.springframework.core.env.ConfigurableEnvironment;
28+
import org.springframework.core.env.Environment;
2729
import org.springframework.core.env.MapPropertySource;
30+
import org.springframework.core.env.PropertySource;
2831

2932
import static org.springframework.cloud.kubernetes.client.KubernetesClientUtils.getApplicationNamespace;
33+
import static org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesBatchRead.discardConfigMaps;
3034

3135
/**
3236
* @author Ryan Baxter
@@ -41,19 +45,26 @@ public class KubernetesClientConfigMapPropertySourceLocator extends ConfigMapPro
4145

4246
public KubernetesClientConfigMapPropertySourceLocator(CoreV1Api coreV1Api, ConfigMapConfigProperties properties,
4347
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
44-
super(properties, new KubernetesClientConfigMapsCache());
48+
super(properties);
4549
this.coreV1Api = coreV1Api;
4650
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
4751
}
4852

53+
public PropertySource<?> locate(Environment environment) {
54+
PropertySource<?> propertySource = super.locate(environment);
55+
discardConfigMaps();
56+
return propertySource;
57+
}
58+
4959
@Override
50-
protected MapPropertySource getMapPropertySource(NormalizedSource source, ConfigurableEnvironment environment) {
60+
protected MapPropertySource getMapPropertySource(NormalizedSource source, ConfigurableEnvironment environment,
61+
ReadType readType) {
5162

5263
String normalizedNamespace = source.namespace().orElse(null);
5364
String namespace = getApplicationNamespace(normalizedNamespace, source.target(), kubernetesNamespaceProvider);
5465

5566
KubernetesClientConfigContext context = new KubernetesClientConfigContext(coreV1Api, source, namespace,
56-
environment);
67+
environment, true, readType);
5768
return new KubernetesClientConfigMapPropertySource(context);
5869
}
5970

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapsCache.java

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)