Skip to content

Commit 09f7d93

Browse files
committed
merge latest
Signed-off-by: wind57 <[email protected]>
2 parents 8f30930 + cb46a90 commit 09f7d93

File tree

63 files changed

+2128
-905
lines changed

Some content is hidden

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

63 files changed

+2128
-905
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/LabeledConfigMapContextToSourceDataProviderNamespacedBatchReadTests.java

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

5455
/**
5556
* @author wind57
@@ -326,10 +327,10 @@ void testTwoConfigmapsWithPrefix() {
326327
String secondKey = keys.next();
327328

328329
if (firstKey.contains("first")) {
329-
Assertions.assertThat(firstKey).isEqualTo("another-blue-configmap.blue-configmap.first");
330+
Assertions.assertThat(firstKey).isEqualTo("blue-configmap.first");
330331
}
331332

332-
Assertions.assertThat(secondKey).isEqualTo("another-blue-configmap.blue-configmap.second");
333+
Assertions.assertThat(secondKey).isEqualTo("another-blue-configmap.second");
333334
Assertions.assertThat(properties.get(firstKey)).isEqualTo("blue");
334335
Assertions.assertThat(properties.get(secondKey)).isEqualTo("blue");
335336
}
@@ -452,11 +453,10 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
452453
KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get();
453454
SourceData sourceData = data.apply(context);
454455

455-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
456-
Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.one")).isEqualTo("1");
457-
Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.two")).isEqualTo("2");
458-
Assertions.assertThat(sourceData.sourceName())
459-
.isEqualTo("configmap.color-configmap.color-configmap-k8s.default");
456+
assertThat(sourceData.sourceData().size()).isEqualTo(2);
457+
assertThat(sourceData.sourceData().get("color-configmap.one")).isEqualTo("1");
458+
assertThat(sourceData.sourceData().get("color-configmap-k8s.two")).isEqualTo("2");
459+
assertThat(sourceData.sourceName()).isEqualTo("configmap.color-configmap.color-configmap-k8s.default");
460460

461461
}
462462

@@ -530,25 +530,13 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() {
530530
KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get();
531531
SourceData sourceData = data.apply(context);
532532

533-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4);
534-
Assertions
535-
.assertThat(sourceData.sourceData()
536-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"))
537-
.isEqualTo("1");
538-
Assertions
539-
.assertThat(sourceData.sourceData()
540-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"))
541-
.isEqualTo("2");
542-
Assertions
543-
.assertThat(sourceData.sourceData()
544-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"))
545-
.isEqualTo("4");
546-
Assertions
547-
.assertThat(sourceData.sourceData()
548-
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"))
549-
.isEqualTo("5");
533+
assertThat(sourceData.sourceData().size()).isEqualTo(4);
534+
assertThat(sourceData.sourceData().get("color-configmap.one")).isEqualTo("1");
535+
assertThat(sourceData.sourceData().get("shape-configmap.two")).isEqualTo("2");
536+
assertThat(sourceData.sourceData().get("color-configmap-k8s.four")).isEqualTo("4");
537+
assertThat(sourceData.sourceData().get("shape-configmap-k8s.five")).isEqualTo("5");
550538

551-
Assertions.assertThat(sourceData.sourceName())
539+
assertThat(sourceData.sourceName())
552540
.isEqualTo("configmap.color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.default");
553541

554542
}

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

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

5657
/**
5758
* @author wind57
@@ -299,10 +300,10 @@ void testTwoSecretsWithPrefix() {
299300
String secondKey = keys.next();
300301

301302
if (firstKey.contains("first")) {
302-
Assertions.assertThat(firstKey).isEqualTo("another-blue-secret.blue-secret.first");
303+
Assertions.assertThat(firstKey).isEqualTo("blue-secret.first");
303304
}
304305

305-
Assertions.assertThat(secondKey).isEqualTo("another-blue-secret.blue-secret.second");
306+
Assertions.assertThat(secondKey).isEqualTo("another-blue-secret.second");
306307
Assertions.assertThat(properties.get(firstKey)).isEqualTo("blue");
307308
Assertions.assertThat(properties.get(secondKey)).isEqualTo("blue");
308309
}
@@ -389,8 +390,8 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
389390
SourceData sourceData = data.apply(context);
390391

391392
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
392-
Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.one")).isEqualTo("1");
393-
Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.two")).isEqualTo("2");
393+
Assertions.assertThat(sourceData.sourceData().get("color-secret.one")).isEqualTo("1");
394+
Assertions.assertThat(sourceData.sourceData().get("color-secret-k8s.two")).isEqualTo("2");
394395
Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.color-secret-k8s.default");
395396

396397
}
@@ -465,21 +466,13 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() {
465466
KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get();
466467
SourceData sourceData = data.apply(context);
467468

468-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4);
469-
Assertions
470-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.one"))
471-
.isEqualTo("1");
472-
Assertions
473-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.two"))
474-
.isEqualTo("2");
475-
Assertions
476-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.four"))
477-
.isEqualTo("4");
478-
Assertions
479-
.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.five"))
480-
.isEqualTo("5");
481-
482-
Assertions.assertThat(sourceData.sourceName())
469+
assertThat(sourceData.sourceData().size()).isEqualTo(4);
470+
assertThat(sourceData.sourceData().get("color-secret.one")).isEqualTo("1");
471+
assertThat(sourceData.sourceData().get("shape-secret.two")).isEqualTo("2");
472+
assertThat(sourceData.sourceData().get("color-secret-k8s.four")).isEqualTo("4");
473+
assertThat(sourceData.sourceData().get("shape-secret-k8s.five")).isEqualTo("5");
474+
475+
assertThat(sourceData.sourceName())
483476
.isEqualTo("secret.color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.default");
484477

485478
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ void matchIncludeSingleProfile() {
175175
CoreV1Api api = new CoreV1Api();
176176

177177
NormalizedSource source = new NamedConfigMapNormalizedSource(RED_CONFIG_MAP_NAME, NAMESPACE, true,
178-
ConfigUtils.Prefix.DEFAULT, true, true);
178+
ConfigUtils.Prefix.DEFAULT, true);
179179
MockEnvironment environment = new MockEnvironment();
180-
environment.setActiveProfiles("with-profile");
180+
environment.addActiveProfile("with-profile");
181181
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment,
182182
false, NAMESPACED_BATCH_READ);
183183

184184
KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get();
185185
SourceData sourceData = data.apply(context);
186186

187-
Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-profile.default.with-profile");
188-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1);
189-
Assertions.assertThat(sourceData.sourceData().get("taste")).isEqualTo("mango");
187+
Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-profile.default");
188+
Assertions.assertThat(sourceData.sourceData())
189+
.containsExactlyInAnyOrderEntriesOf(Map.of("color", "really-red", "taste", "mango"));
190190

191191
}
192192

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ void matchIncludeSingleProfile() {
243243
SourceData sourceData = data.apply(context);
244244

245245
Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.red-with-profile.default.with-profile");
246-
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1);
246+
Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
247247
Assertions.assertThat(sourceData.sourceData().get("taste")).isEqualTo("mango");
248+
Assertions.assertThat(sourceData.sourceData().get("color")).isEqualTo("really-red");
248249

249250
}
250251

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)