@@ -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 {
0 commit comments