Skip to content

Commit b47f91d

Browse files
authored
Fix 1592 empty source on error (#1792)
1 parent abc0a89 commit b47f91d

22 files changed

+3098
-46
lines changed

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

Lines changed: 378 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,54 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
5454

5555
private static final String LIST_API = "/api/v1/namespaces/default/secrets";
5656

57-
private static final String LIST_BODY = "{\n" + "\t\"kind\": \"SecretList\",\n" + "\t\"apiVersion\": \"v1\",\n"
58-
+ "\t\"metadata\": {\n" + "\t\t\"selfLink\": \"/api/v1/secrets\",\n"
59-
+ "\t\t\"resourceVersion\": \"163035\"\n" + "\t},\n" + "\t\"items\": [{\n" + "\t\t\t\"metadata\": {\n"
60-
+ "\t\t\t\t\"name\": \"db-secret\",\n" + "\t\t\t\t\"namespace\": \"default\",\n"
61-
+ "\t\t\t\t\"selfLink\": \"/api/v1/namespaces/default/secrets/db-secret\",\n"
62-
+ "\t\t\t\t\"uid\": \"59ba8e6a-a2d4-416c-b016-22597c193f23\",\n"
63-
+ "\t\t\t\t\"resourceVersion\": \"1462\",\n" + "\t\t\t\t\"creationTimestamp\": \"2020-10-28T14:45:02Z\",\n"
64-
+ "\t\t\t\t\"labels\": {\n" + "\t\t\t\t\t\"spring.cloud.kubernetes.secret\": \"true\"\n" + "\t\t\t\t}\n"
65-
+ "\t\t\t},\n" + "\t\t\t\"data\": {\n" + "\t\t\t\t\"password\": \"cDQ1NXcwcmQ=\",\n"
66-
+ "\t\t\t\t\"username\": \"dXNlcg==\"\n" + "\t\t\t},\n" + "\t\t\t\"type\": \"Opaque\"\n" + "\t\t},\n"
67-
+ "\t\t{\n" + "\t\t\t\"metadata\": {\n" + "\t\t\t\t\"name\": \"rabbit-password\",\n"
68-
+ "\t\t\t\t\"namespace\": \"default\",\n"
69-
+ "\t\t\t\t\"selfLink\": \"/api/v1/namespaces/default/secrets/rabbit-password\",\n"
70-
+ "\t\t\t\t\"uid\": \"bc211cb4-e7ff-4556-b26e-c54911301740\",\n"
71-
+ "\t\t\t\t\"resourceVersion\": \"162708\",\n"
72-
+ "\t\t\t\t\"creationTimestamp\": \"2020-10-29T19:47:36Z\",\n" + "\t\t\t\t\"labels\": {\n"
73-
+ "\t\t\t\t\t\"spring.cloud.kubernetes.secret\": \"true\"\n" + "\t\t\t\t},\n"
74-
+ "\t\t\t\t\"annotations\": {\n"
75-
+ "\t\t\t\t\t\"kubectl.kubernetes.io/last-applied-configuration\": \"{\\\"apiVersion\\\":\\\"v1\\\",\\\"data\\\":{\\\"spring.rabbitmq.password\\\":\\\"password\\\"},\\\"kind\\\":\\\"Secret\\\",\\\"metadata\\\":{\\\"annotations\\\":{},\\\"labels\\\":{\\\"spring.cloud.kubernetes.secret\\\":\\\"true\\\"},\\\"name\\\":\\\"rabbit-password\\\",\\\"namespace\\\":\\\"default\\\"},\\\"type\\\":\\\"Opaque\\\"}\\n\"\n"
76-
+ "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"data\": {\n"
77-
+ "\t\t\t\t\"spring.rabbitmq.password\": \"cGFzc3dvcmQ=\"\n" + "\t\t\t},\n" + "\t\t\t\"type\": \"Opaque\"\n"
78-
+ "\t\t}\n" + "\t]\n" + "}";
57+
private static final String LIST_BODY = """
58+
{
59+
\t"kind": "SecretList",
60+
\t"apiVersion": "v1",
61+
\t"metadata": {
62+
\t\t"selfLink": "/api/v1/secrets",
63+
\t\t"resourceVersion": "163035"
64+
\t},
65+
\t"items": [{
66+
\t\t\t"metadata": {
67+
\t\t\t\t"name": "db-secret",
68+
\t\t\t\t"namespace": "default",
69+
\t\t\t\t"selfLink": "/api/v1/namespaces/default/secrets/db-secret",
70+
\t\t\t\t"uid": "59ba8e6a-a2d4-416c-b016-22597c193f23",
71+
\t\t\t\t"resourceVersion": "1462",
72+
\t\t\t\t"creationTimestamp": "2020-10-28T14:45:02Z",
73+
\t\t\t\t"labels": {
74+
\t\t\t\t\t"spring.cloud.kubernetes.secret": "true"
75+
\t\t\t\t}
76+
\t\t\t},
77+
\t\t\t"data": {
78+
\t\t\t\t"password": "cDQ1NXcwcmQ=",
79+
\t\t\t\t"username": "dXNlcg=="
80+
\t\t\t},
81+
\t\t\t"type": "Opaque"
82+
\t\t},
83+
\t\t{
84+
\t\t\t"metadata": {
85+
\t\t\t\t"name": "rabbit-password",
86+
\t\t\t\t"namespace": "default",
87+
\t\t\t\t"selfLink": "/api/v1/namespaces/default/secrets/rabbit-password",
88+
\t\t\t\t"uid": "bc211cb4-e7ff-4556-b26e-c54911301740",
89+
\t\t\t\t"resourceVersion": "162708",
90+
\t\t\t\t"creationTimestamp": "2020-10-29T19:47:36Z",
91+
\t\t\t\t"labels": {
92+
\t\t\t\t\t"spring.cloud.kubernetes.secret": "true"
93+
\t\t\t\t},
94+
\t\t\t\t"annotations": {
95+
\t\t\t\t\t"kubectl.kubernetes.io/last-applied-configuration": "{\\"apiVersion\\":\\"v1\\",\\"data\\":{\\"spring.rabbitmq.password\\":\\"password\\"},\\"kind\\":\\"Secret\\",\\"metadata\\":{\\"annotations\\":{},\\"labels\\":{\\"spring.cloud.kubernetes.secret\\":\\"true\\"},\\"name\\":\\"rabbit-password\\",\\"namespace\\":\\"default\\"},\\"type\\":\\"Opaque\\"}\\n"
96+
\t\t\t\t}
97+
\t\t\t},
98+
\t\t\t"data": {
99+
\t\t\t\t"spring.rabbitmq.password": "cGFzc3dvcmQ="
100+
\t\t\t},
101+
\t\t\t"type": "Opaque"
102+
\t\t}
103+
\t]
104+
}""";
79105

80106
private static WireMockServer wireMockServer;
81107

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

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,54 @@ class KubernetesClientSecretsPropertySourceTests {
8080

8181
private static final String LIST_API_WITH_LABEL = "/api/v1/namespaces/default/secrets";
8282

83-
private static final String LIST_BODY = "{\n" + "\t\"kind\": \"SecretList\",\n" + "\t\"apiVersion\": \"v1\",\n"
84-
+ "\t\"metadata\": {\n" + "\t\t\"selfLink\": \"/api/v1/secrets\",\n"
85-
+ "\t\t\"resourceVersion\": \"163035\"\n" + "\t},\n" + "\t\"items\": [{\n" + "\t\t\t\"metadata\": {\n"
86-
+ "\t\t\t\t\"name\": \"db-secret\",\n" + "\t\t\t\t\"namespace\": \"default\",\n"
87-
+ "\t\t\t\t\"selfLink\": \"/api/v1/namespaces/default/secrets/db-secret\",\n"
88-
+ "\t\t\t\t\"uid\": \"59ba8e6a-a2d4-416c-b016-22597c193f23\",\n"
89-
+ "\t\t\t\t\"resourceVersion\": \"1462\",\n" + "\t\t\t\t\"creationTimestamp\": \"2020-10-28T14:45:02Z\",\n"
90-
+ "\t\t\t\t\"labels\": {\n" + "\t\t\t\t\t\"spring.cloud.kubernetes.secret\": \"true\"\n" + "\t\t\t\t}\n"
91-
+ "\t\t\t},\n" + "\t\t\t\"data\": {\n" + "\t\t\t\t\"password\": \"cDQ1NXcwcmQ=\",\n"
92-
+ "\t\t\t\t\"username\": \"dXNlcg==\"\n" + "\t\t\t},\n" + "\t\t\t\"type\": \"Opaque\"\n" + "\t\t},\n"
93-
+ "\t\t{\n" + "\t\t\t\"metadata\": {\n" + "\t\t\t\t\"name\": \"rabbit-password\",\n"
94-
+ "\t\t\t\t\"namespace\": \"default\",\n"
95-
+ "\t\t\t\t\"selfLink\": \"/api/v1/namespaces/default/secrets/rabbit-password\",\n"
96-
+ "\t\t\t\t\"uid\": \"bc211cb4-e7ff-4556-b26e-c54911301740\",\n"
97-
+ "\t\t\t\t\"resourceVersion\": \"162708\",\n"
98-
+ "\t\t\t\t\"creationTimestamp\": \"2020-10-29T19:47:36Z\",\n" + "\t\t\t\t\"labels\": {\n"
99-
+ "\t\t\t\t\t\"spring.cloud.kubernetes.secret\": \"true\"\n" + "\t\t\t\t},\n"
100-
+ "\t\t\t\t\"annotations\": {\n"
101-
+ "\t\t\t\t\t\"kubectl.kubernetes.io/last-applied-configuration\": \"{\\\"apiVersion\\\":\\\"v1\\\",\\\"data\\\":{\\\"spring.rabbitmq.password\\\":\\\"password\\\"},\\\"kind\\\":\\\"Secret\\\",\\\"metadata\\\":{\\\"annotations\\\":{},\\\"labels\\\":{\\\"spring.cloud.kubernetes.secret\\\":\\\"true\\\"},\\\"name\\\":\\\"rabbit-password\\\",\\\"namespace\\\":\\\"default\\\"},\\\"type\\\":\\\"Opaque\\\"}\\n\"\n"
102-
+ "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"data\": {\n"
103-
+ "\t\t\t\t\"spring.rabbitmq.password\": \"cGFzc3dvcmQ=\"\n" + "\t\t\t},\n" + "\t\t\t\"type\": \"Opaque\"\n"
104-
+ "\t\t}\n" + "\t]\n" + "}";
83+
private static final String LIST_BODY = """
84+
{
85+
\t"kind": "SecretList",
86+
\t"apiVersion": "v1",
87+
\t"metadata": {
88+
\t\t"selfLink": "/api/v1/secrets",
89+
\t\t"resourceVersion": "163035"
90+
\t},
91+
\t"items": [{
92+
\t\t\t"metadata": {
93+
\t\t\t\t"name": "db-secret",
94+
\t\t\t\t"namespace": "default",
95+
\t\t\t\t"selfLink": "/api/v1/namespaces/default/secrets/db-secret",
96+
\t\t\t\t"uid": "59ba8e6a-a2d4-416c-b016-22597c193f23",
97+
\t\t\t\t"resourceVersion": "1462",
98+
\t\t\t\t"creationTimestamp": "2020-10-28T14:45:02Z",
99+
\t\t\t\t"labels": {
100+
\t\t\t\t\t"spring.cloud.kubernetes.secret": "true"
101+
\t\t\t\t}
102+
\t\t\t},
103+
\t\t\t"data": {
104+
\t\t\t\t"password": "cDQ1NXcwcmQ=",
105+
\t\t\t\t"username": "dXNlcg=="
106+
\t\t\t},
107+
\t\t\t"type": "Opaque"
108+
\t\t},
109+
\t\t{
110+
\t\t\t"metadata": {
111+
\t\t\t\t"name": "rabbit-password",
112+
\t\t\t\t"namespace": "default",
113+
\t\t\t\t"selfLink": "/api/v1/namespaces/default/secrets/rabbit-password",
114+
\t\t\t\t"uid": "bc211cb4-e7ff-4556-b26e-c54911301740",
115+
\t\t\t\t"resourceVersion": "162708",
116+
\t\t\t\t"creationTimestamp": "2020-10-29T19:47:36Z",
117+
\t\t\t\t"labels": {
118+
\t\t\t\t\t"spring.cloud.kubernetes.secret": "true"
119+
\t\t\t\t},
120+
\t\t\t\t"annotations": {
121+
\t\t\t\t\t"kubectl.kubernetes.io/last-applied-configuration": "{\\"apiVersion\\":\\"v1\\",\\"data\\":{\\"spring.rabbitmq.password\\":\\"password\\"},\\"kind\\":\\"Secret\\",\\"metadata\\":{\\"annotations\\":{},\\"labels\\":{\\"spring.cloud.kubernetes.secret\\":\\"true\\"},\\"name\\":\\"rabbit-password\\",\\"namespace\\":\\"default\\"},\\"type\\":\\"Opaque\\"}\\n"
122+
\t\t\t\t}
123+
\t\t\t},
124+
\t\t\t"data": {
125+
\t\t\t\t"spring.rabbitmq.password": "cGFzc3dvcmQ="
126+
\t\t\t},
127+
\t\t\t"type": "Opaque"
128+
\t\t}
129+
\t]
130+
}""";
105131

106132
private static WireMockServer wireMockServer;
107133

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.client.config;
18+
19+
import io.kubernetes.client.common.KubernetesObject;
20+
import io.kubernetes.client.openapi.apis.CoreV1Api;
21+
22+
import org.springframework.cloud.kubernetes.client.config.reload.KubernetesClientEventBasedConfigMapChangeDetector;
23+
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
24+
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
25+
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
26+
import org.springframework.core.env.ConfigurableEnvironment;
27+
28+
/**
29+
* @author wind57
30+
*/
31+
public class VisibleKubernetesClientEventBasedConfigMapChangeDetector
32+
extends KubernetesClientEventBasedConfigMapChangeDetector {
33+
34+
public VisibleKubernetesClientEventBasedConfigMapChangeDetector(CoreV1Api coreV1Api,
35+
ConfigurableEnvironment environment, ConfigReloadProperties properties,
36+
ConfigurationUpdateStrategy strategy, KubernetesClientConfigMapPropertySourceLocator propertySourceLocator,
37+
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
38+
super(coreV1Api, environment, properties, strategy, propertySourceLocator, kubernetesNamespaceProvider);
39+
}
40+
41+
public void onEvent(KubernetesObject kubernetesObject) {
42+
super.onEvent(kubernetesObject);
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.client.config;
18+
19+
import io.kubernetes.client.common.KubernetesObject;
20+
import io.kubernetes.client.openapi.apis.CoreV1Api;
21+
22+
import org.springframework.cloud.kubernetes.client.config.reload.KubernetesClientEventBasedSecretsChangeDetector;
23+
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
24+
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
25+
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
26+
import org.springframework.core.env.ConfigurableEnvironment;
27+
28+
/**
29+
* @author wind57
30+
*/
31+
public class VisibleKubernetesClientEventBasedSecretsChangeDetector
32+
extends KubernetesClientEventBasedSecretsChangeDetector {
33+
34+
public VisibleKubernetesClientEventBasedSecretsChangeDetector(CoreV1Api coreV1Api,
35+
ConfigurableEnvironment environment, ConfigReloadProperties properties,
36+
ConfigurationUpdateStrategy strategy, KubernetesClientSecretsPropertySourceLocator propertySourceLocator,
37+
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
38+
super(coreV1Api, environment, properties, strategy, propertySourceLocator, kubernetesNamespaceProvider);
39+
}
40+
41+
@Override
42+
public void onEvent(KubernetesObject kubernetesObject) {
43+
super.onEvent(kubernetesObject);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)