Skip to content

Commit 6b230b6

Browse files
committed
dirty
1 parent 7507162 commit 6b230b6

File tree

47 files changed

+644
-523
lines changed

Some content is hidden

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

47 files changed

+644
-523
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2013-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,10 +27,5 @@
2727
* @author wind57
2828
*/
2929
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-
}
30+
Environment environment, boolean includeDefaultProfileData, boolean namespacedBatchRead) {
3631
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ 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,
68+
new KubernetesClientSourcesNamespaceBatched());
6869
}
6970

7071
registerSingle(bootstrapContext, ConfigMapPropertySourceLocator.class, configMapPropertySourceLocator,
@@ -76,7 +77,7 @@ protected void registerBeans(ConfigDataLocationResolverContext resolverContext,
7677
coreV1Api, namespaceProvider, secretsProperties);
7778
if (isRetryEnabledForSecrets(secretsProperties)) {
7879
secretsPropertySourceLocator = new ConfigDataRetryableSecretsPropertySourceLocator(
79-
secretsPropertySourceLocator, secretsProperties, new KubernetesClientSecretsCache());
80+
secretsPropertySourceLocator, secretsProperties, new KubernetesClientSourcesNamespaceBatched());
8081
}
8182

8283
registerSingle(bootstrapContext, SecretsPropertySourceLocator.class, secretsPropertySourceLocator,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ public class KubernetesClientConfigMapPropertySourceLocator extends ConfigMapPro
4141

4242
public KubernetesClientConfigMapPropertySourceLocator(CoreV1Api coreV1Api, ConfigMapConfigProperties properties,
4343
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
44-
super(properties, new KubernetesClientConfigMapsCache());
44+
super(properties, new KubernetesClientSourcesNamespaceBatched());
4545
this.coreV1Api = coreV1Api;
4646
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
4747
}
4848

4949
@Override
50-
protected MapPropertySource getMapPropertySource(NormalizedSource source, ConfigurableEnvironment environment) {
50+
protected MapPropertySource getMapPropertySource(NormalizedSource source, ConfigurableEnvironment environment,
51+
boolean namespacedBatchRead) {
5152

5253
String normalizedNamespace = source.namespace().orElse(null);
5354
String namespace = getApplicationNamespace(normalizedNamespace, source.target(), kubernetesNamespaceProvider);
5455

5556
KubernetesClientConfigContext context = new KubernetesClientConfigContext(coreV1Api, source, namespace,
56-
environment);
57+
environment, true, namespacedBatchRead);
5758
return new KubernetesClientConfigMapPropertySource(context);
5859
}
5960

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

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
import org.springframework.core.env.Environment;
3434

3535
import static org.springframework.cloud.kubernetes.client.KubernetesClientUtils.getApplicationNamespace;
36+
import static org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesNamespaceBatched.strippedConfigMapsBatchRead;
37+
import static org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesNamespaceBatched.strippedSecretsBatchRead;
38+
import static org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesNonNamespaceBatched.strippedConfigMapsNonBatchRead;
39+
import static org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesNonNamespaceBatched.strippedSecretsNonBatchRead;
3640

3741
/**
3842
* @author Ryan Baxter
@@ -61,38 +65,29 @@ public static Set<String> namespaces(KubernetesNamespaceProvider provider, Confi
6165
return namespaces;
6266
}
6367

64-
/**
65-
* <pre>
66-
* 1. read all secrets in the provided namespace
67-
* 2. from the above, filter the ones that we care about (filter by labels)
68-
* 3. see if any of the secrets from (2) has a single yaml/properties file
69-
* 4. gather all the names of the secrets + data they hold
70-
* </pre>
71-
*/
72-
static MultipleSourcesContainer secretsDataByLabels(CoreV1Api coreV1Api, String namespace,
73-
Map<String, String> labels, Environment environment) {
74-
List<StrippedSourceContainer> strippedSecrets = strippedSecrets(coreV1Api, namespace);
75-
if (strippedSecrets.isEmpty()) {
76-
return MultipleSourcesContainer.empty();
77-
}
78-
return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, DECODE);
79-
}
80-
8168
/**
8269
* <pre>
8370
* 1. read all config maps in the provided namespace
84-
* 2. from the above, filter the ones that we care about (filter by labels)
85-
* 3. see if any from (2) has a single yaml/properties file
71+
* 2. from the above, filter the ones that we care about (by name)
72+
* 3. see if any of the config maps has a single yaml/properties file
8673
* 4. gather all the names of the config maps + data they hold
8774
* </pre>
8875
*/
89-
static MultipleSourcesContainer configMapsDataByLabels(CoreV1Api coreV1Api, String namespace,
90-
Map<String, String> labels, Environment environment) {
91-
List<StrippedSourceContainer> strippedConfigMaps = strippedConfigMaps(coreV1Api, namespace);
92-
if (strippedConfigMaps.isEmpty()) {
93-
return MultipleSourcesContainer.empty();
76+
static MultipleSourcesContainer configMapsDataByName(CoreV1Api client, String namespace,
77+
LinkedHashSet<String> sourceNames, Environment environment, boolean namespacedBatchRead) {
78+
79+
List<StrippedSourceContainer> strippedConfigMaps;
80+
81+
if (namespacedBatchRead) {
82+
LOG.debug("Will read all configmaps in namespace : " + namespace);
83+
strippedConfigMaps = strippedConfigMapsBatchRead(client, namespace);
9484
}
95-
return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, DECODE);
85+
else {
86+
LOG.debug("Will read individual configmaps in namespace : " + namespace + " with names : " + sourceNames);
87+
strippedConfigMaps = strippedConfigMapsNonBatchRead(client, namespace, sourceNames);
88+
}
89+
90+
return ConfigUtils.processNamedData(strippedConfigMaps, environment, sourceNames, namespace, false);
9691
}
9792

9893
/**
@@ -103,49 +98,71 @@ static MultipleSourcesContainer configMapsDataByLabels(CoreV1Api coreV1Api, Stri
10398
* 4. gather all the names of the secrets + decoded data they hold
10499
* </pre>
105100
*/
106-
static MultipleSourcesContainer secretsDataByName(CoreV1Api coreV1Api, String namespace,
107-
LinkedHashSet<String> sourceNames, Environment environment, boolean includeDefaultProfileData) {
108-
List<StrippedSourceContainer> strippedSecrets = strippedSecrets(coreV1Api, namespace);
109-
if (strippedSecrets.isEmpty()) {
110-
return MultipleSourcesContainer.empty();
101+
static MultipleSourcesContainer secretsDataByName(CoreV1Api client, String namespace,
102+
LinkedHashSet<String> sourceNames, Environment environment, boolean namespacedBatchRead) {
103+
104+
List<StrippedSourceContainer> strippedSecrets;
105+
106+
if (namespacedBatchRead) {
107+
LOG.debug("Will read all secrets in namespace : " + namespace);
108+
strippedSecrets = strippedSecretsBatchRead(client, namespace);
109+
}
110+
else {
111+
LOG.debug("Will read individual secrets in namespace : " + namespace + " with names : " + sourceNames);
112+
strippedSecrets = strippedSecretsNonBatchRead(client, namespace, sourceNames);
111113
}
112-
return ConfigUtils.processNamedData(strippedSecrets, environment, sourceNames, namespace, DECODE,
113-
includeDefaultProfileData);
114+
115+
return ConfigUtils.processNamedData(strippedSecrets, environment, sourceNames, namespace, false);
114116
}
115117

116118
/**
117119
* <pre>
118120
* 1. read all config maps in the provided namespace
119-
* 2. from the above, filter the ones that we care about (by name)
120-
* 3. see if any of the config maps has a single yaml/properties file
121+
* 2. from the above, filter the ones that we care about (filter by labels)
122+
* 3. see if any from (2) has a single yaml/properties file
121123
* 4. gather all the names of the config maps + data they hold
122124
* </pre>
123125
*/
124-
static MultipleSourcesContainer configMapsDataByName(CoreV1Api coreV1Api, String namespace,
125-
LinkedHashSet<String> sourceNames, Environment environment, boolean includeDefaultProfileData) {
126-
List<StrippedSourceContainer> strippedConfigMaps = strippedConfigMaps(coreV1Api, namespace);
127-
if (strippedConfigMaps.isEmpty()) {
128-
return MultipleSourcesContainer.empty();
129-
}
130-
return ConfigUtils.processNamedData(strippedConfigMaps, environment, sourceNames, namespace, DECODE,
131-
includeDefaultProfileData);
132-
}
126+
static MultipleSourcesContainer configMapsDataByLabels(CoreV1Api client, String namespace,
127+
Map<String, String> labels, Environment environment, boolean namespacedBatchRead) {
128+
129+
List<StrippedSourceContainer> strippedConfigMaps;
133130

134-
private static List<StrippedSourceContainer> strippedConfigMaps(CoreV1Api coreV1Api, String namespace) {
135-
List<StrippedSourceContainer> strippedConfigMaps = KubernetesClientConfigMapsCache.byNamespace(coreV1Api,
136-
namespace);
137-
if (strippedConfigMaps.isEmpty()) {
138-
LOG.debug("No configmaps in namespace '" + namespace + "'");
131+
if (namespacedBatchRead) {
132+
LOG.debug("Will read all configmaps in namespace : " + namespace);
133+
strippedConfigMaps = strippedConfigMapsBatchRead(client, namespace);
134+
}
135+
else {
136+
LOG.debug("Will read individual configmaps in namespace : " + namespace + " with labels : " + labels);
137+
strippedConfigMaps = strippedConfigMapsNonBatchRead(client, namespace, labels);
139138
}
140-
return strippedConfigMaps;
139+
140+
return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, false);
141141
}
142142

143-
private static List<StrippedSourceContainer> strippedSecrets(CoreV1Api coreV1Api, String namespace) {
144-
List<StrippedSourceContainer> strippedSecrets = KubernetesClientSecretsCache.byNamespace(coreV1Api, namespace);
145-
if (strippedSecrets.isEmpty()) {
146-
LOG.debug("No configmaps in namespace '" + namespace + "'");
143+
/**
144+
* <pre>
145+
* 1. read all secrets in the provided namespace
146+
* 2. from the above, filter the ones that we care about (filter by labels)
147+
* 3. see if any of the secrets from (2) has a single yaml/properties file
148+
* 4. gather all the names of the secrets + data they hold
149+
* </pre>
150+
*/
151+
static MultipleSourcesContainer secretsDataByLabels(CoreV1Api client, String namespace, Map<String, String> labels,
152+
Environment environment, boolean namespacedBatchRead) {
153+
154+
List<StrippedSourceContainer> strippedSecrets;
155+
156+
if (namespacedBatchRead) {
157+
LOG.debug("Will read all secrets in namespace : " + namespace);
158+
strippedSecrets = strippedSecretsBatchRead(client, namespace);
147159
}
148-
return strippedSecrets;
160+
else {
161+
LOG.debug("Will read individual secrets in namespace : " + namespace + " with labels : " + labels);
162+
strippedSecrets = strippedSecretsNonBatchRead(client, namespace, labels);
163+
}
164+
165+
return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, false);
149166
}
150167

151168
}

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

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ public class KubernetesClientSecretsPropertySourceLocator extends SecretsPropert
4141

4242
public KubernetesClientSecretsPropertySourceLocator(CoreV1Api coreV1Api,
4343
KubernetesNamespaceProvider kubernetesNamespaceProvider, SecretsConfigProperties secretsConfigProperties) {
44-
super(secretsConfigProperties, new KubernetesClientSecretsCache());
44+
super(secretsConfigProperties, new KubernetesClientSourcesNamespaceBatched());
4545
this.coreV1Api = coreV1Api;
4646
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
4747
}
4848

4949
@Override
50-
protected SecretsPropertySource getPropertySource(ConfigurableEnvironment environment, NormalizedSource source) {
50+
protected SecretsPropertySource getPropertySource(ConfigurableEnvironment environment, NormalizedSource source,
51+
boolean namespacedBatchRead) {
5152

5253
String normalizedNamespace = source.namespace().orElse(null);
5354
String namespace = getApplicationNamespace(normalizedNamespace, source.target(), kubernetesNamespaceProvider);
5455

5556
KubernetesClientConfigContext context = new KubernetesClientConfigContext(coreV1Api, source, namespace,
56-
environment);
57+
environment, true, namespacedBatchRead);
5758

5859
return new KubernetesClientSecretsPropertySource(context);
5960
}

0 commit comments

Comments
 (0)