Skip to content

Commit fae4e7f

Browse files
authored
Merge pull request #2024 from wind57/revert_workaround
revert workaround
2 parents 1372bde + d9ecf17 commit fae4e7f

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
*/
5959
abstract class Fabric8EndpointsAndEndpointSlicesTests {
6060

61+
static KubernetesClient mockClient;
62+
6163
static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = Mockito.mock(KubernetesNamespaceProvider.class);
6264

6365
static final ArgumentCaptor<HeartbeatEvent> HEARTBEAT_EVENT_ARGUMENT_CAPTOR = ArgumentCaptor
@@ -68,7 +70,7 @@ abstract class Fabric8EndpointsAndEndpointSlicesTests {
6870
@BeforeAll
6971
static void setUp() {
7072
// Configure the kubernetes master url to point to the mock server
71-
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient().getConfiguration().getMasterUrl());
73+
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
7274
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
7375
System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false");
7476
System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false");
@@ -79,8 +81,8 @@ static void setUp() {
7981
@AfterEach
8082
void afterEach() {
8183
Mockito.reset(APPLICATION_EVENT_PUBLISHER);
82-
mockClient().discovery().v1().endpointSlices().inAnyNamespace().delete();
83-
mockClient().endpoints().inAnyNamespace().delete();
84+
mockClient.discovery().v1().endpointSlices().inAnyNamespace().delete();
85+
mockClient.endpoints().inAnyNamespace().delete();
8486
}
8587

8688
/**
@@ -251,7 +253,7 @@ KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map<String, String
251253
boolean allNamespaces = true;
252254
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces,
253255
true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices, false, null);
254-
KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER);
256+
KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER);
255257

256258
if (endpointSlices) {
257259
watch = Mockito.spy(watch);
@@ -272,7 +274,7 @@ KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String namespa
272274
boolean allNamespaces = false;
273275
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces,
274276
Set.of(namespace), true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices, false, null);
275-
KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER);
277+
KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER);
276278

277279
if (endpointSlices) {
278280
watch = Mockito.spy(watch);
@@ -291,7 +293,7 @@ KubernetesCatalogWatch createWatcherInSpecificNamespacesWithLabels(Set<String> n
291293
// all-namespaces = false
292294
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, namespaces, true, 60,
293295
false, "", Set.of(), labels, "", null, 0, false, false, null);
294-
KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER);
296+
KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER);
295297

296298
if (endpointSlices) {
297299
watch = Mockito.spy(watch);
@@ -316,7 +318,7 @@ void endpoints(String namespace, Map<String, String> labels, String podName) {
316318
.withMetadata(new ObjectMetaBuilder().withLabels(labels).withName("endpoints-" + podName).build())
317319
.withSubsets(List.of(endpointSubset))
318320
.build();
319-
mockClient().endpoints().inNamespace(namespace).resource(endpoints).create();
321+
mockClient.endpoints().inNamespace(namespace).resource(endpoints).create();
320322
}
321323

322324
Endpoints endpointsWithoutSubsets(String namespace, Map<String, String> labels, String podName) {
@@ -330,7 +332,7 @@ Endpoints endpointsWithoutSubsets(String namespace, Map<String, String> labels,
330332
.withMetadata(new ObjectMetaBuilder().withLabels(labels).withName("endpoints-" + podName).build())
331333
.withSubsets(endpointSubsets)
332334
.build();
333-
mockClient().endpoints().inNamespace(namespace).resource(endpoints).create();
335+
mockClient.endpoints().inNamespace(namespace).resource(endpoints).create();
334336
return endpoints;
335337
}
336338

@@ -339,7 +341,7 @@ void service(String namespace, Map<String, String> labels, String podName) {
339341
Service service = new ServiceBuilder()
340342
.withMetadata(new ObjectMetaBuilder().withLabels(labels).withName("endpoints-" + podName).build())
341343
.build();
342-
mockClient().services().inNamespace(namespace).resource(service).create();
344+
mockClient.services().inNamespace(namespace).resource(service).create();
343345
}
344346

345347
static void endpointSlice(String namespace, Map<String, String> labels, String podName) {
@@ -356,7 +358,7 @@ static void endpointSlice(String namespace, Map<String, String> labels, String p
356358
.withEndpoints(endpoint)
357359
.build();
358360

359-
mockClient().discovery().v1().endpointSlices().inNamespace(namespace).resource(slice).create();
361+
mockClient.discovery().v1().endpointSlices().inNamespace(namespace).resource(slice).create();
360362

361363
}
362364

@@ -372,7 +374,7 @@ static EndpointSlice endpointSliceWithoutEndpoints(String namespace, Map<String,
372374
.withEndpoints(endpoints)
373375
.build();
374376

375-
mockClient().discovery().v1().endpointSlices().inNamespace(namespace).resource(slice).create();
377+
mockClient.discovery().v1().endpointSlices().inNamespace(namespace).resource(slice).create();
376378
return slice;
377379

378380
}
@@ -389,11 +391,4 @@ static void invokeAndAssert(KubernetesCatalogWatch watch, List<EndpointNameAndNa
389391
assertThat(event.getValue()).isEqualTo(state);
390392
}
391393

392-
// work-around for : https://github.com/fabric8io/kubernetes-client/issues/4649
393-
private static KubernetesClient mockClient() {
394-
return Fabric8KubernetesCatalogWatchEndpointsTests.endpointsMockClient() != null
395-
? Fabric8KubernetesCatalogWatchEndpointsTests.endpointsMockClient()
396-
: Fabric8KubernetesCatalogWatchEndpointSlicesTests.endpointSlicesMockClient();
397-
}
398-
399394
}

spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,4 @@ void generateStateEndpointsWithoutEndpoints() {
203203
assertThat(catalogWatch.generateState(List.of(sliceNoEndpoints))).isEmpty();
204204
}
205205

206-
// work-around for : https://github.com/fabric8io/kubernetes-client/issues/4649
207-
static KubernetesClient endpointSlicesMockClient() {
208-
return mockClient;
209-
}
210-
211206
}

spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Set;
2222

2323
import io.fabric8.kubernetes.api.model.Endpoints;
24-
import io.fabric8.kubernetes.client.KubernetesClient;
2524
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
2625
import org.junit.jupiter.api.AfterEach;
2726
import org.junit.jupiter.api.Test;
@@ -40,8 +39,6 @@ class Fabric8KubernetesCatalogWatchEndpointsTests extends Fabric8EndpointsAndEnd
4039

4140
private static final Boolean ENDPOINT_SLICES = false;
4241

43-
private static KubernetesClient mockClient;
44-
4542
@AfterEach
4643
void afterEach() {
4744
mockClient.endpoints().inAnyNamespace().delete();
@@ -264,9 +261,4 @@ void generateStateEndpointsWithoutSubsets() {
264261
assertThat(result).isEmpty();
265262
}
266263

267-
// work-around for : https://github.com/fabric8io/kubernetes-client/issues/4649
268-
static KubernetesClient endpointsMockClient() {
269-
return mockClient;
270-
}
271-
272264
}

0 commit comments

Comments
 (0)