Skip to content

Commit d247f2c

Browse files
committed
fix-1715 : started work
Signed-off-by: wind57 <[email protected]>
1 parent ae10e54 commit d247f2c

File tree

27 files changed

+142
-213
lines changed

27 files changed

+142
-213
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,34 @@ public static Set<String> namespaces(KubernetesNamespaceProvider provider, Confi
6565
* <pre>
6666
* 1. read all secrets in the provided namespace
6767
* 2. from the above, filter the ones that we care about (filter by labels)
68-
* 3. with secret names from (2), find out if there are any profile based secrets (if profiles is not empty)
69-
* 4. concat (2) and (3) and these are the secrets we are interested in
70-
* 5. see if any of the secrets from (4) has a single yaml/properties file
71-
* 6. gather all the names of the secrets (from 4) + data they hold
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
7270
* </pre>
7371
*/
7472
static MultipleSourcesContainer secretsDataByLabels(CoreV1Api coreV1Api, String namespace,
75-
Map<String, String> labels, Environment environment, Set<String> profiles) {
73+
Map<String, String> labels, Environment environment) {
7674
List<StrippedSourceContainer> strippedSecrets = strippedSecrets(coreV1Api, namespace);
7775
if (strippedSecrets.isEmpty()) {
7876
return MultipleSourcesContainer.empty();
7977
}
80-
return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, profiles, DECODE);
78+
return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, DECODE);
8179
}
8280

8381
/**
8482
* <pre>
8583
* 1. read all config maps in the provided namespace
8684
* 2. from the above, filter the ones that we care about (filter by labels)
87-
* 3. with config maps names from (2), find out if there are any profile based ones (if profiles is not empty)
88-
* 4. concat (2) and (3) and these are the config maps we are interested in
89-
* 5. see if any from (4) has a single yaml/properties file
90-
* 6. gather all the names of the config maps (from 4) + data they hold
85+
* 3. see if any from (2) has a single yaml/properties file
86+
* 4. gather all the names of the config maps + data they hold
9187
* </pre>
9288
*/
9389
static MultipleSourcesContainer configMapsDataByLabels(CoreV1Api coreV1Api, String namespace,
94-
Map<String, String> labels, Environment environment, Set<String> profiles) {
90+
Map<String, String> labels, Environment environment) {
9591
List<StrippedSourceContainer> strippedConfigMaps = strippedConfigMaps(coreV1Api, namespace);
9692
if (strippedConfigMaps.isEmpty()) {
9793
return MultipleSourcesContainer.empty();
9894
}
99-
return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, profiles, DECODE);
95+
return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, DECODE);
10096
}
10197

10298
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public KubernetesClientContextToSourceData get() {
4848

4949
return new LabeledSourceData() {
5050
@Override
51-
public MultipleSourcesContainer dataSupplier(Map<String, String> labels, Set<String> profiles) {
51+
public MultipleSourcesContainer dataSupplier(Map<String, String> labels) {
5252
return KubernetesClientConfigUtils.configMapsDataByLabels(context.client(), context.namespace(),
53-
labels, context.environment(), profiles);
53+
labels, context.environment());
5454
}
5555

5656
}.compute(source.labels(), source.prefix(), source.target(), source.profileSpecificSources(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public KubernetesClientContextToSourceData get() {
5555

5656
return new LabeledSourceData() {
5757
@Override
58-
public MultipleSourcesContainer dataSupplier(Map<String, String> labels, Set<String> profiles) {
58+
public MultipleSourcesContainer dataSupplier(Map<String, String> labels) {
5959
return KubernetesClientConfigUtils.secretsDataByLabels(context.client(), context.namespace(),
60-
labels, context.environment(), profiles);
60+
labels, context.environment());
6161
}
6262

6363
}.compute(source.labels(), source.prefix(), source.target(), source.profileSpecificSources(),

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySourceTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.junit.jupiter.api.BeforeAll;
3636
import org.junit.jupiter.api.Test;
3737

38+
import org.springframework.cloud.kubernetes.commons.config.ConfigUtils;
3839
import org.springframework.cloud.kubernetes.commons.config.LabeledSecretNormalizedSource;
3940
import org.springframework.cloud.kubernetes.commons.config.NamedSecretNormalizedSource;
4041
import org.springframework.cloud.kubernetes.commons.config.NormalizedSource;
@@ -193,7 +194,7 @@ void secretLabelsTest() {
193194
Map<String, String> labels = new HashMap<>();
194195
labels.put("spring.cloud.kubernetes.secret", "true");
195196

196-
NormalizedSource source = new LabeledSecretNormalizedSource("default", labels, false, false);
197+
NormalizedSource source = new LabeledSecretNormalizedSource("default", labels, false, ConfigUtils.Prefix.DEFAULT);
197198
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, "default",
198199
new MockEnvironment());
199200

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,8 @@ void searchWithLabelsOneConfigMapFound() {
409409

410410
/**
411411
* two configmaps are deployed: "color-configmap" with label: "{color:blue}" and
412-
* "color-configmap-k8s" with label: "{color:red}". We search by "{color:blue}" and
413-
* find one configmap. Since profiles are enabled, we will also be reading
414-
* "color-configmap-k8s", even if its labels do not match provided ones.
412+
* "color-configmap-k8s" with label: "{color:blue}". We search by "{color:blue}" and
413+
* find them both.
415414
*/
416415
@Test
417416
void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
@@ -426,7 +425,7 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
426425

427426
V1ConfigMap two = new V1ConfigMapBuilder()
428427
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s")
429-
.withLabels(RED_LABEL)
428+
.withLabels(BLUE_LABEL)
430429
.withNamespace(NAMESPACE)
431430
.build())
432431
.addToData("two", "2")
@@ -491,7 +490,7 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() {
491490

492491
V1ConfigMap colorConfigmapK8s = new V1ConfigMapBuilder()
493492
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s")
494-
.withLabels(RED_LABEL)
493+
.withLabels(BLUE_LABEL)
495494
.withNamespace(NAMESPACE)
496495
.build())
497496
.addToData("four", "4")

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void noMatch() {
108108

109109
// blue does not match red
110110
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE,
111-
Collections.singletonMap("color", "blue"), false, false);
111+
Collections.singletonMap("color", "blue"), false, ConfigUtils.Prefix.DEFAULT);
112112
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
113113
new MockEnvironment());
114114

@@ -136,7 +136,8 @@ void singleSecretMatchAgainstLabels() {
136136
stubCall(secretList);
137137
CoreV1Api api = new CoreV1Api();
138138

139-
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, LABELS, false, false);
139+
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, LABELS,
140+
false, ConfigUtils.Prefix.DEFAULT);
140141
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
141142
new MockEnvironment());
142143

@@ -168,7 +169,8 @@ void twoSecretsMatchAgainstLabels() {
168169
stubCall(secretList);
169170
CoreV1Api api = new CoreV1Api();
170171

171-
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, RED_LABEL, false, false);
172+
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, RED_LABEL,
173+
false, ConfigUtils.Prefix.DEFAULT);
172174
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
173175
new MockEnvironment());
174176

@@ -193,7 +195,8 @@ void namespaceMatch() {
193195
stubCall(secretList);
194196
CoreV1Api api = new CoreV1Api();
195197

196-
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE + "nope", LABELS, false, false);
198+
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE + "nope",
199+
LABELS, false, ConfigUtils.Prefix.DEFAULT);
197200
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
198201
new MockEnvironment());
199202

@@ -226,8 +229,8 @@ void testWithPrefix() {
226229
CoreV1Api api = new CoreV1Api();
227230

228231
ConfigUtils.Prefix prefix = ConfigUtils.findPrefix("me", false, false, null);
229-
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, prefix,
230-
false);
232+
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"),
233+
false, prefix);
231234
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
232235
new MockEnvironment());
233236

@@ -272,7 +275,7 @@ void testTwoSecretsWithPrefix() {
272275
CoreV1Api api = new CoreV1Api();
273276

274277
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false,
275-
ConfigUtils.Prefix.DELAYED, false);
278+
ConfigUtils.Prefix.DELAYED);
276279
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
277280
new MockEnvironment());
278281

@@ -304,7 +307,7 @@ void testTwoSecretsWithPrefix() {
304307
/**
305308
* two secrets are deployed: secret "color-secret" with label: "{color:blue}" and
306309
* "shape-secret" with label: "{shape:round}". We search by "{color:blue}" and find
307-
* one secret. profile based sources are enabled, but it has no effect.
310+
* one secret.
308311
*/
309312
@Test
310313
void searchWithLabelsOneSecretFound() {
@@ -331,7 +334,7 @@ void searchWithLabelsOneSecretFound() {
331334
CoreV1Api api = new CoreV1Api();
332335

333336
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false,
334-
ConfigUtils.Prefix.DEFAULT, true);
337+
ConfigUtils.Prefix.DEFAULT);
335338
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
336339
new MockEnvironment());
337340

@@ -347,8 +350,7 @@ void searchWithLabelsOneSecretFound() {
347350
/**
348351
* two secrets are deployed: secret "color-secret" with label: "{color:blue}" and
349352
* "color-secret-k8s" with label: "{color:red}". We search by "{color:blue}" and find
350-
* one secret. Since profiles are enabled, we will also be reading "color-secret-k8s",
351-
* even if its labels do not match provided ones.
353+
* both.
352354
*/
353355
@Test
354356
void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
@@ -362,7 +364,7 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
362364
.build();
363365

364366
V1Secret shapeSecret = new V1SecretBuilder()
365-
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
367+
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
366368
.withNamespace(NAMESPACE)
367369
.withName("color-secret-k8s")
368370
.build())
@@ -377,7 +379,7 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
377379
environment.setActiveProfiles("k8s");
378380

379381
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false,
380-
ConfigUtils.Prefix.DELAYED, true);
382+
ConfigUtils.Prefix.DELAYED);
381383
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment);
382384

383385
KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get();
@@ -427,15 +429,15 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() {
427429
.build();
428430

429431
V1Secret colorSecretK8s = new V1SecretBuilder()
430-
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
432+
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
431433
.withNamespace(NAMESPACE)
432434
.withName("color-secret-k8s")
433435
.build())
434436
.addToData("four", "4".getBytes())
435437
.build();
436438

437439
V1Secret shapeSecretK8s = new V1SecretBuilder()
438-
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("shape", "triangle"))
440+
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
439441
.withNamespace(NAMESPACE)
440442
.withName("shape-secret-k8s")
441443
.build())
@@ -454,7 +456,7 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() {
454456
environment.setActiveProfiles("k8s");
455457

456458
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false,
457-
ConfigUtils.Prefix.DELAYED, true);
459+
ConfigUtils.Prefix.DELAYED);
458460
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment);
459461

460462
KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get();
@@ -490,7 +492,7 @@ void testYaml() {
490492
CoreV1Api api = new CoreV1Api();
491493

492494
NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false,
493-
ConfigUtils.Prefix.DEFAULT, true);
495+
ConfigUtils.Prefix.DEFAULT);
494496
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE,
495497
new MockEnvironment());
496498

@@ -535,7 +537,7 @@ void cache(CapturedOutput output) {
535537
CoreV1Api api = new CoreV1Api();
536538

537539
NormalizedSource redSource = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "red"), false,
538-
ConfigUtils.Prefix.DEFAULT, false);
540+
ConfigUtils.Prefix.DEFAULT);
539541
KubernetesClientConfigContext redContext = new KubernetesClientConfigContext(api, redSource, NAMESPACE,
540542
new MockEnvironment());
541543
KubernetesClientContextToSourceData redData = new LabeledSecretContextToSourceDataProvider().get();
@@ -547,7 +549,7 @@ void cache(CapturedOutput output) {
547549
Assertions.assertThat(output.getOut()).contains("Loaded all secrets in namespace '" + NAMESPACE + "'");
548550

549551
NormalizedSource greenSource = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "green"), false,
550-
ConfigUtils.Prefix.DEFAULT, false);
552+
ConfigUtils.Prefix.DEFAULT);
551553
KubernetesClientConfigContext greenContext = new KubernetesClientConfigContext(api, greenSource, NAMESPACE,
552554
new MockEnvironment());
553555
KubernetesClientContextToSourceData greenData = new LabeledSecretContextToSourceDataProvider().get();

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_secret_with_profile/LabeledSecretWithProfileTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ static void afterAll() {
8181

8282
/**
8383
* <pre>
84-
* this one is taken from : "blue.one". We find "color-secret" by labels, and
85-
* "color-secrets-k8s" exists, but "includeProfileSpecificSources=false", thus not taken.
86-
* Since "explicitPrefix=blue", we take "blue.one"
84+
* this one is taken from : "blue.one". We find "color-secret" by labels.
8785
* </pre>
8886
*/
8987
@Test

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledConfigMapWithProfileConfigurationStub.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ public ApiClient apiClient(WireMockServer wireMockServer) {
7474
* - configmap with name "green-configmap-k8s", with labels : "{color: green-k8s}"
7575
* - configmap with name "green-configmap-prod", with labels : "{color: green-prod}"
7676
*
77-
* # a test that proves order: first read non-profile based configmaps, thus profile based
78-
* # configmaps override non-profile ones.
7977
* - configmap with name "green-purple-configmap", labels "{color: green, shape: round}", data: "{eight: 8}"
80-
* - configmap with name "green-purple-configmap-k8s", labels "{color: black}", data: "{eight: eight-ish}"
78+
* - configmap with name "green-purple-configmap-k8s", labels "{color: green}", data: "{eight: eight-ish}"
8179
* </pre>
8280
*/
8381
public static void stubData() {
@@ -112,7 +110,7 @@ public static void stubData() {
112110
V1ConfigMap greenConfigMapK8s = new V1ConfigMapBuilder()
113111
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-k8s")
114112
.withNamespace("spring-k8s")
115-
.withLabels(Map.of("color", "green-k8s"))
113+
.withLabels(Map.of("color", "green"))
116114
.build())
117115
.addToData(Collections.singletonMap("six", "6"))
118116
.build();
@@ -121,7 +119,7 @@ public static void stubData() {
121119
V1ConfigMap greenConfigMapProd = new V1ConfigMapBuilder()
122120
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-prod")
123121
.withNamespace("spring-k8s")
124-
.withLabels(Map.of("color", "green-prod"))
122+
.withLabels(Map.of("color", "green"))
125123
.build())
126124
.addToData(Collections.singletonMap("seven", "7"))
127125
.build();
@@ -157,7 +155,7 @@ public static void stubData() {
157155
V1ConfigMap greenPurpleConfigMapK8s = new V1ConfigMapBuilder()
158156
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-configmap-k8s")
159157
.withNamespace("spring-k8s")
160-
.withLabels(Map.of("color", "black"))
158+
.withLabels(Map.of("color", "green"))
161159
.build())
162160
.addToData(Collections.singletonMap("eight", "eight-ish"))
163161
.build();

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledSecretWithProfileConfigurationStub.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ public ApiClient apiClient(WireMockServer wireMockServer) {
7575
* - secret with name "green-secret-k8s", with labels : "{color: green-k8s}"
7676
* - secret with name "green-secret-prod", with labels : "{color: green-prod}"
7777
*
78-
* # a test that proves order: first read non-profile based secrets, thus profile based
79-
* # secrets override non-profile ones.
8078
* - secret with name "green-purple-secret", labels "{color: green, shape: round}", data: "{eight: 8}"
81-
* - secret with name "green-purple-secret-k8s", labels "{color: black}", data: "{eight: eight-ish}"
79+
* - secret with name "green-purple-secret-k8s", labels "{color: green}", data: "{eight: eight-ish}"
8280
* </pre>
8381
*/
8482
public static void stubData() {
@@ -113,7 +111,7 @@ public static void stubData() {
113111
V1Secret greenSecretK8s = new V1SecretBuilder()
114112
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret-k8s")
115113
.withNamespace("spring-k8s")
116-
.withLabels(Map.of("color", "green-k8s"))
114+
.withLabels(Map.of("color", "green"))
117115
.build())
118116
.addToData(Collections.singletonMap("six", "6".getBytes(StandardCharsets.UTF_8)))
119117
.build();
@@ -122,7 +120,7 @@ public static void stubData() {
122120
V1Secret shapeSecretProd = new V1SecretBuilder()
123121
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret-prod")
124122
.withNamespace("spring-k8s")
125-
.withLabels(Map.of("color", "green-prod"))
123+
.withLabels(Map.of("color", "green"))
126124
.build())
127125
.addToData(Collections.singletonMap("seven", "7".getBytes(StandardCharsets.UTF_8)))
128126
.build();
@@ -158,7 +156,7 @@ public static void stubData() {
158156
V1Secret greenPurpleSecretK8s = new V1SecretBuilder()
159157
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-secret-k8s")
160158
.withNamespace("spring-k8s")
161-
.withLabels(Map.of("color", "black"))
159+
.withLabels(Map.of("color", "green"))
162160
.build())
163161
.addToData(Collections.singletonMap("eight", "eight-ish".getBytes(StandardCharsets.UTF_8)))
164162
.build();

0 commit comments

Comments
 (0)