5858 */
5959abstract 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}
0 commit comments