Skip to content

Commit cb46a90

Browse files
committed
merge main
Signed-off-by: wind57 <[email protected]>
2 parents 379846c + abf452a commit cb46a90

File tree

65 files changed

+1851
-935
lines changed

Some content is hidden

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

65 files changed

+1851
-935
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ class LabeledConfigMapContextToSourceDataProvider implements Supplier<Kubernetes
3333
* There could be many sources that are read based on incoming labels, for which we
3434
* will be computing a single Map<String, Object> in the end.
3535
*
36-
* If there is no config maps found for the provided labels, we will return an "empty"
37-
* SourceData. Its name is going to be the concatenated labels mapped to an empty Map.
36+
* If there are no config maps found for the provided labels, we will return an
37+
* "empty" SourceData. Its name is going to be the concatenated labels mapped to an
38+
* empty Map.
3839
*
39-
* If we find config maps(s) for the provided labels, its name is going to be the
40-
* concatenated names mapped to the data they hold as a Map.
4140
*/
4241
@Override
4342
public KubernetesClientContextToSourceData get() {

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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5050
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
5151
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
52+
import static org.assertj.core.api.Assertions.assertThat;
5253

5354
/**
5455
* @author wind57
@@ -318,10 +319,10 @@ void testTwoConfigmapsWithPrefix() {
318319
String secondKey = keys.next();
319320

320321
if (firstKey.contains("first")) {
321-
Assertions.assertThat(firstKey).isEqualTo("another-blue-configmap.blue-configmap.first");
322+
Assertions.assertThat(firstKey).isEqualTo("blue-configmap.first");
322323
}
323324

324-
Assertions.assertThat(secondKey).isEqualTo("another-blue-configmap.blue-configmap.second");
325+
Assertions.assertThat(secondKey).isEqualTo("another-blue-configmap.second");
325326
Assertions.assertThat(properties.get(firstKey)).isEqualTo("blue");
326327
Assertions.assertThat(properties.get(secondKey)).isEqualTo("blue");
327328
}
@@ -443,11 +444,10 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
443444
KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get();
444445
SourceData sourceData = data.apply(context);
445446

446-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
447-
Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.one")).isEqualTo("1");
448-
Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.two")).isEqualTo("2");
449-
Assertions.assertThat(sourceData.sourceName())
450-
.isEqualTo("configmap.color-configmap.color-configmap-k8s.default");
447+
assertThat(sourceData.sourceData().size()).isEqualTo(2);
448+
assertThat(sourceData.sourceData().get("color-configmap.one")).isEqualTo("1");
449+
assertThat(sourceData.sourceData().get("color-configmap-k8s.two")).isEqualTo("2");
450+
assertThat(sourceData.sourceName()).isEqualTo("configmap.color-configmap.color-configmap-k8s.default");
451451

452452
}
453453

@@ -520,25 +520,13 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() {
520520
KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get();
521521
SourceData sourceData = data.apply(context);
522522

523-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4);
524-
Assertions
525-
.assertThat(sourceData.sourceData()
526-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"))
527-
.isEqualTo("1");
528-
Assertions
529-
.assertThat(sourceData.sourceData()
530-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"))
531-
.isEqualTo("2");
532-
Assertions
533-
.assertThat(sourceData.sourceData()
534-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"))
535-
.isEqualTo("4");
536-
Assertions
537-
.assertThat(sourceData.sourceData()
538-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"))
539-
.isEqualTo("5");
523+
assertThat(sourceData.sourceData().size()).isEqualTo(4);
524+
assertThat(sourceData.sourceData().get("color-configmap.one")).isEqualTo("1");
525+
assertThat(sourceData.sourceData().get("shape-configmap.two")).isEqualTo("2");
526+
assertThat(sourceData.sourceData().get("color-configmap-k8s.four")).isEqualTo("4");
527+
assertThat(sourceData.sourceData().get("shape-configmap-k8s.five")).isEqualTo("5");
540528

541-
Assertions.assertThat(sourceData.sourceName())
529+
assertThat(sourceData.sourceName())
542530
.isEqualTo("configmap.color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.default");
543531

544532
}

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5252
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
5353
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
54+
import static org.assertj.core.api.Assertions.assertThat;
5455

5556
/**
5657
* @author wind57
@@ -291,10 +292,10 @@ void testTwoSecretsWithPrefix() {
291292
String secondKey = keys.next();
292293

293294
if (firstKey.contains("first")) {
294-
Assertions.assertThat(firstKey).isEqualTo("another-blue-secret.blue-secret.first");
295+
Assertions.assertThat(firstKey).isEqualTo("blue-secret.first");
295296
}
296297

297-
Assertions.assertThat(secondKey).isEqualTo("another-blue-secret.blue-secret.second");
298+
Assertions.assertThat(secondKey).isEqualTo("another-blue-secret.second");
298299
Assertions.assertThat(properties.get(firstKey)).isEqualTo("blue");
299300
Assertions.assertThat(properties.get(secondKey)).isEqualTo("blue");
300301
}
@@ -380,8 +381,8 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
380381
SourceData sourceData = data.apply(context);
381382

382383
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
383-
Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.one")).isEqualTo("1");
384-
Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.two")).isEqualTo("2");
384+
Assertions.assertThat(sourceData.sourceData().get("color-secret.one")).isEqualTo("1");
385+
Assertions.assertThat(sourceData.sourceData().get("color-secret-k8s.two")).isEqualTo("2");
385386
Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.color-secret-k8s.default");
386387

387388
}
@@ -455,21 +456,13 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() {
455456
KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get();
456457
SourceData sourceData = data.apply(context);
457458

458-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4);
459-
Assertions
460-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.one"))
461-
.isEqualTo("1");
462-
Assertions
463-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.two"))
464-
.isEqualTo("2");
465-
Assertions
466-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.four"))
467-
.isEqualTo("4");
468-
Assertions
469-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.five"))
470-
.isEqualTo("5");
471-
472-
Assertions.assertThat(sourceData.sourceName())
459+
assertThat(sourceData.sourceData().size()).isEqualTo(4);
460+
assertThat(sourceData.sourceData().get("color-secret.one")).isEqualTo("1");
461+
assertThat(sourceData.sourceData().get("shape-secret.two")).isEqualTo("2");
462+
assertThat(sourceData.sourceData().get("color-secret-k8s.four")).isEqualTo("4");
463+
assertThat(sourceData.sourceData().get("shape-secret-k8s.five")).isEqualTo("5");
464+
465+
assertThat(sourceData.sourceName())
473466
.isEqualTo("secret.color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.default");
474467

475468
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,18 @@ void matchIncludeSingleProfile() {
169169
CoreV1Api api = new CoreV1Api();
170170

171171
NormalizedSource source = new NamedConfigMapNormalizedSource(RED_CONFIG_MAP_NAME, NAMESPACE, true,
172-
ConfigUtils.Prefix.DEFAULT, true, true);
172+
ConfigUtils.Prefix.DEFAULT, true);
173173
MockEnvironment environment = new MockEnvironment();
174-
environment.setActiveProfiles("with-profile");
174+
environment.addActiveProfile("with-profile");
175175
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment,
176-
false);
176+
true);
177177

178178
KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get();
179179
SourceData sourceData = data.apply(context);
180180

181-
Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-profile.default.with-profile");
182-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1);
183-
Assertions.assertThat(sourceData.sourceData().get("taste")).isEqualTo("mango");
181+
Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-profile.default");
182+
Assertions.assertThat(sourceData.sourceData())
183+
.containsExactlyInAnyOrderEntriesOf(Map.of("color", "really-red", "taste", "mango"));
184184

185185
}
186186

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,15 @@ void matchIncludeSingleProfile() {
229229
MockEnvironment environment = new MockEnvironment();
230230
environment.addActiveProfile("with-profile");
231231
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment,
232-
false);
232+
true);
233233

234234
KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get();
235235
SourceData sourceData = data.apply(context);
236236

237237
Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.red-with-profile.default.with-profile");
238-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1);
238+
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
239239
Assertions.assertThat(sourceData.sourceData().get("taste")).isEqualTo("mango");
240+
Assertions.assertThat(sourceData.sourceData().get("color")).isEqualTo("really-red");
240241

241242
}
242243

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/LabeledConfigMapWithProfileApp.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
2121
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2222
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.Blue;
2323
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.Green;
24+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenK8s;
25+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenProd;
26+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenPurple;
27+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenPurpleK8s;
2428

2529
/**
2630
* @author wind57
2731
*/
2832
@SpringBootApplication
29-
@EnableConfigurationProperties({ Blue.class, Green.class })
33+
@EnableConfigurationProperties({ Blue.class, Green.class, GreenK8s.class, GreenProd.class, GreenPurple.class,
34+
GreenPurpleK8s.class })
3035
public class LabeledConfigMapWithProfileApp {
3136

3237
public static void main(String[] args) {

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/LabeledConfigMapWithProfileTests.java

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@
1717
package org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile;
1818

1919
import com.github.tomakehurst.wiremock.client.WireMock;
20-
import org.hamcrest.Matchers;
2120
import org.junit.jupiter.api.AfterAll;
2221
import org.junit.jupiter.api.AfterEach;
2322
import org.junit.jupiter.api.Test;
2423

2524
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.Blue;
26+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.Green;
27+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenK8s;
28+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenProd;
29+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenPurple;
30+
import org.springframework.cloud.kubernetes.client.config.applications.labeled_config_map_with_profile.properties.GreenPurpleK8s;
2631
import org.springframework.test.web.reactive.server.WebTestClient;
2732

33+
import static org.assertj.core.api.Assertions.assertThat;
34+
2835
/**
2936
* Stub data is in
3037
* {@link org.springframework.cloud.kubernetes.client.config.bootstrap.stubs.LabeledConfigMapWithProfileConfigurationStub}
@@ -36,6 +43,24 @@ abstract class LabeledConfigMapWithProfileTests {
3643
@Autowired
3744
private WebTestClient webClient;
3845

46+
@Autowired
47+
private Blue blue;
48+
49+
@Autowired
50+
private Green green;
51+
52+
@Autowired
53+
private GreenK8s greenK8s;
54+
55+
@Autowired
56+
private GreenProd greenProd;
57+
58+
@Autowired
59+
private GreenPurple greenPurple;
60+
61+
@Autowired
62+
private GreenPurpleK8s greenPurpleK8s;
63+
3964
@AfterEach
4065
void afterEach() {
4166
WireMock.reset();
@@ -55,30 +80,35 @@ static void afterAll() {
5580
*/
5681
@Test
5782
void testBlue() {
58-
this.webClient.get()
59-
.uri("/labeled-configmap/profile/blue")
60-
.exchange()
61-
.expectStatus()
62-
.isOk()
63-
.expectBody(String.class)
64-
.value(Matchers.equalTo("1"));
83+
assertThat(blue.getOne()).isEqualTo("1");
6584
}
6685

67-
/**
68-
* <pre>
69-
* this one is taken from : "green-configmap.green-configmap-k8s.green-configmap-prod.green-purple-configmap.green-purple-configmap-k8s".
70-
* We find "green-configmap", "green-configmap-k8s", "green-configmap-prod" by labels.
71-
* </pre>
72-
*/
86+
// found by labels
7387
@Test
7488
void testGreen() {
75-
this.webClient.get()
76-
.uri("/labeled-configmap/profile/green")
77-
.exchange()
78-
.expectStatus()
79-
.isOk()
80-
.expectBody(String.class)
81-
.value(Matchers.equalTo("2#6#7#eight-ish"));
89+
assertThat(green.getTwo()).isEqualTo("2");
90+
}
91+
92+
// found because above is found, plus active profile is included
93+
@Test
94+
void testGreenK8s() {
95+
assertThat(greenK8s.getSix()).isEqualTo("6");
96+
}
97+
98+
// found because above is found, plus active profile is included
99+
@Test
100+
void testGreenProd() {
101+
assertThat(greenProd.getSeven()).isEqualTo("7");
102+
}
103+
104+
@Test
105+
void testGreenPurple() {
106+
assertThat(greenPurple.getEight()).isEqualTo("8");
107+
}
108+
109+
@Test
110+
void testGreenPurpleK8s() {
111+
assertThat(greenPurpleK8s.getEight()).isEqualTo("eight-ish");
82112
}
83113

84114
}

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/controller/LabeledConfigMapWithProfileController.java

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

0 commit comments

Comments
 (0)