Skip to content

Commit d7d09de

Browse files
authored
minor clean-ups (#1157)
1 parent 347a36d commit d7d09de

File tree

5 files changed

+39
-59
lines changed

5 files changed

+39
-59
lines changed

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/skaffold.yaml

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

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ class DiscoveryClientFilterNamespaceIT {
7575

7676
private static final String SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME = "spring-cloud-kubernetes-discoveryclient-it";
7777

78-
private static final String MOCK_DEPLOYMENT_NAME = "servicea-wiremock-deployment";
78+
private static final String MOCK_DEPLOYMENT_NAME = "wiremock-deployment";
7979

80-
private static final String MOCK_CLIENT_APP_NAME = "servicea-wiremock";
80+
private static final String MOCK_CLIENT_APP_NAME = "wiremock";
8181

8282
private static final String MOCK_IMAGE_NAME = "wiremock";
8383

8484
private static final String NAMESPACE = "default";
8585

86-
private static final String NAMESPACE_1 = "namespace1";
86+
private static final String NAMESPACE_LEFT = "left-namespace";
8787

88-
private static final String NAMESPACE_2 = "namespace2";
88+
private static final String NAMESPACE_RIGHT = "right-namespace";
8989

9090
private static CoreV1Api api;
9191

@@ -99,7 +99,6 @@ class DiscoveryClientFilterNamespaceIT {
9999

100100
private static final K3sContainer K3S = Commons.container();
101101

102-
@SuppressWarnings("checkstyle:WhitespaceAround")
103102
@BeforeAll
104103
static void beforeAll() throws Exception {
105104
K3S.start();
@@ -152,8 +151,8 @@ void afterEach() throws ApiException {
152151

153152
@Test
154153
void testDiscoveryClient() throws Exception {
155-
deploySampleAppInNamespace(NAMESPACE_1);
156-
deploySampleAppInNamespace(NAMESPACE_2);
154+
deploySampleAppInNamespace(NAMESPACE_LEFT);
155+
deploySampleAppInNamespace(NAMESPACE_RIGHT);
157156
deployDiscoveryIt();
158157

159158
testLoadBalancer();
@@ -168,18 +167,20 @@ private void cleanup() throws ApiException {
168167
null);
169168
networkingApi.deleteNamespacedIngress("it-ingress", NAMESPACE, null, null, null, null, null, null);
170169

171-
appsApi.deleteCollectionNamespacedDeployment(NAMESPACE_1, null, null, null,
170+
appsApi.deleteCollectionNamespacedDeployment(NAMESPACE_LEFT, null, null, null,
172171
"metadata.name=" + MOCK_DEPLOYMENT_NAME, null, null, null, null, null, null, null, null, null);
173-
appsApi.deleteCollectionNamespacedDeployment(NAMESPACE_2, null, null, null,
172+
appsApi.deleteCollectionNamespacedDeployment(NAMESPACE_RIGHT, null, null, null,
174173
"metadata.name=" + MOCK_DEPLOYMENT_NAME, null, null, null, null, null, null, null, null, null);
175174

176-
api.deleteNamespacedService(MOCK_CLIENT_APP_NAME, NAMESPACE_1, null, null, null, null, null, null);
177-
api.deleteNamespacedService(MOCK_CLIENT_APP_NAME, NAMESPACE_2, null, null, null, null, null, null);
175+
api.deleteNamespacedService(MOCK_CLIENT_APP_NAME, NAMESPACE_LEFT, null, null, null, null, null, null);
176+
api.deleteNamespacedService(MOCK_CLIENT_APP_NAME, NAMESPACE_RIGHT, null, null, null, null, null, null);
178177

179-
networkingApi.deleteNamespacedIngress("servicea-wiremock-ingress", NAMESPACE_1, null, null, null, null, null,
180-
null);
181-
networkingApi.deleteNamespacedIngress("servicea-wiremock-ingress", NAMESPACE_2, null, null, null, null, null,
178+
networkingApi.deleteNamespacedIngress("wiremock-ingress", NAMESPACE_LEFT, null, null, null, null, null,
182179
null);
180+
networkingApi.deleteNamespacedIngress("wiremock-ingress", NAMESPACE_RIGHT, null, null, null, null,
181+
null, null);
182+
183+
authApi.deleteClusterRole("cluster-admin", null, null, null, null, null, null);
183184

184185
}
185186

@@ -193,17 +194,18 @@ private void testLoadBalancer() {
193194
String[] result = serviceClient.method(HttpMethod.GET).retrieve().bodyToMono(String[].class)
194195
.retryWhen(retrySpec()).block();
195196
LOG.info("Services: " + Arrays.toString(result));
196-
assertThat(result).containsAnyOf("servicea-wiremock");
197+
assertThat(result).containsAnyOf("wiremock");
197198

198199
// ServiceInstance
199200
WebClient serviceInstanceClient = builder
200-
.baseUrl("http://localhost:80/discoveryclient-it/service/servicea-wiremock").build();
201+
.baseUrl("http://localhost:80/discoveryclient-it/service/wiremock").build();
201202
List<KubernetesServiceInstance> serviceInstances = serviceInstanceClient.method(HttpMethod.GET).retrieve()
202203
.bodyToMono(new ParameterizedTypeReference<List<KubernetesServiceInstance>>() {
203204
}).retryWhen(retrySpec()).block();
204205

206+
assertThat(serviceInstances).isNotNull();
205207
assertThat(serviceInstances.size()).isEqualTo(1);
206-
assertThat(serviceInstances.get(0).getNamespace()).isEqualTo(NAMESPACE_1);
208+
assertThat(serviceInstances.get(0).getNamespace()).isEqualTo(NAMESPACE_LEFT);
207209

208210
}
209211

@@ -234,12 +236,12 @@ private void deployDiscoveryIt() throws Exception {
234236
}
235237

236238
private static V1Deployment getDiscoveryItDeployment() throws Exception {
237-
V1Deployment deployment = (V1Deployment) k8SUtils
239+
V1Deployment deployment = (V1Deployment) K8SUtils
238240
.readYamlFromClasspath("client/spring-cloud-kubernetes-discoveryclient-it-deployment.yaml");
239241

240-
// add namespaces filter property for namespace1
241-
var env = new V1EnvVarBuilder().withName("JAVA_OPTS")
242-
.withValue("-Dspring.cloud.kubernetes.discovery.namespaces[0]=" + NAMESPACE_1).build();
242+
// add namespaces filter property for left namespace
243+
var env = new V1EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_NAMESPACES_0")
244+
.withValue(NAMESPACE_LEFT).build();
243245
var container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
244246
container.setEnv(List.of(env));
245247

@@ -264,12 +266,12 @@ private static void deployDiscoveryServer() throws Exception {
264266

265267
private static void deploySampleAppInNamespace(final String namespace) throws Exception {
266268

267-
V1Namespace namespace1 = new V1Namespace();
269+
V1Namespace v1Namespace = new V1Namespace();
268270
V1ObjectMeta meta = new V1ObjectMeta();
269271
meta.setName(namespace);
270-
namespace1.setMetadata(meta);
272+
v1Namespace.setMetadata(meta);
271273

272-
api.createNamespace(namespace1, null, null, null);
274+
api.createNamespace(v1Namespace, null, null, null);
273275

274276
V1Deployment deployment = getMockServiceDeployment();
275277
deployment.getMetadata().setNamespace(namespace);
@@ -287,14 +289,14 @@ private static void deploySampleAppInNamespace(final String namespace) throws Ex
287289
}
288290

289291
private static V1Deployment getDiscoveryServerDeployment() throws Exception {
290-
V1Deployment deployment = (V1Deployment) k8SUtils
292+
V1Deployment deployment = (V1Deployment) K8SUtils
291293
.readYamlFromClasspath("server/spring-cloud-kubernetes-discoveryserver-deployment.yaml");
292294
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
293295
+ getPomVersion();
294296
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
295297
// setup all-namespaces property
296-
V1EnvVar env = new V1EnvVarBuilder().withName("JAVA_OPTS")
297-
.withValue("-Dspring.cloud.kubernetes.discovery.all-namespaces=true").build();
298+
V1EnvVar env = new V1EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_ALL_NAMESPACES")
299+
.withValue("TRUE").build();
298300
V1Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
299301
container.setEnv(List.of(env));
300302

@@ -327,7 +329,7 @@ private static V1ClusterRoleBinding getClusterRoleBinding() throws Exception {
327329
}
328330

329331
private static V1Deployment getMockServiceDeployment() throws Exception {
330-
return (V1Deployment) k8SUtils.readYamlFromClasspath("wiremock/discovery-wiremock-deployment.yaml");
332+
return (V1Deployment) K8SUtils.readYamlFromClasspath("wiremock/discovery-wiremock-deployment.yaml");
331333
}
332334

333335
private static V1Service getMockServiceService() throws Exception {

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/resources/wiremock/discovery-wiremock-deployment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: servicea-wiremock-deployment
4+
name: wiremock-deployment
55
spec:
66
selector:
77
matchLabels:
8-
app: servicea-wiremock
8+
app: wiremock
99
template:
1010
metadata:
1111
labels:
12-
app: servicea-wiremock
12+
app: wiremock
1313
spec:
1414
containers:
15-
- name: servicea-wiremock
15+
- name: wiremock
1616
image: wiremock/wiremock:2.32.0
1717
imagePullPolicy: IfNotPresent
1818
readinessProbe:
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: networking.k8s.io/v1
22
kind: Ingress
33
metadata:
4-
name: servicea-wiremock-ingress
4+
name: wiremock-ingress
55
spec:
66
rules:
77
- http:
@@ -10,6 +10,6 @@ spec:
1010
pathType: Prefix
1111
backend:
1212
service:
13-
name: servicea-wiremock
13+
name: wiremock
1414
port:
1515
number: 8080

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/resources/wiremock/discovery-wiremock-service.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
labels:
5-
app: servicea-wiremock
6-
name: servicea-wiremock
5+
app: wiremock
6+
name: wiremock
77
spec:
88
ports:
99
- name: http
1010
port: 8080
1111
targetPort: 8080
1212
selector:
13-
app: servicea-wiremock
13+
app: wiremock
1414
type: ClusterIP

0 commit comments

Comments
 (0)