Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ public Flux<String> getServices() {
.subscribeOn(Schedulers.boundedElastic());
}

@Override
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we use the same properties for the reactive and blocking reactive clients + our reactive clients are based on the blocking ones, we can re-use the order here

public int getOrder() {
return kubernetesDiscoveryClient.getOrder();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,20 @@ void testPodMetadata() {
server.shutdown();
}

@Test
void testOrder() {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of("a", "b"),
true, 60L, false, "", Set.of(), Map.of(), "", null, 57, false, true);

Lister<V1Service> serviceLister = setupServiceLister(SERVICE_1, SERVICE_2);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister(ENDPOINTS_1);

KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient(
SHARED_INFORMER_FACTORY, serviceLister, endpointsLister, null, null, properties);

assertThat(discoveryClient.getOrder()).isEqualTo(57);
}

private Lister<V1Service> setupServiceLister(V1Service... services) {
Cache<V1Service> serviceCache = new Cache<>();
Lister<V1Service> serviceLister = new Lister<>(serviceCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void afterEach() {
void testDiscoveryGetServicesAllNamespaceShouldWork() {
Lister<V1Service> serviceLister = setupServiceLister(NAMESPACE_ALL, TEST_SERVICE_1, TEST_SERVICE_2,
TEST_SERVICE_3);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister("");
Lister<V1Endpoints> endpointsLister = setupEndpointsLister();

KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, true,
Set.of(), true, 60, false, null, Set.of(), Map.of(), null, null, 0, false);
Expand All @@ -105,7 +105,7 @@ void testDiscoveryGetServicesAllNamespaceShouldWork() {
@Test
void testDiscoveryGetServicesOneNamespaceShouldWork() {
Lister<V1Service> serviceLister = setupServiceLister(NAMESPACE_1, TEST_SERVICE_1, TEST_SERVICE_2);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister("");
Lister<V1Endpoints> endpointsLister = setupEndpointsLister();

KubernetesInformerReactiveDiscoveryClient discoveryClient = new KubernetesInformerReactiveDiscoveryClient(
new KubernetesInformerDiscoveryClient(sharedInformerFactory, serviceLister, endpointsLister, null, null,
Expand All @@ -121,7 +121,7 @@ void testDiscoveryGetServicesOneNamespaceShouldWork() {
@Test
void testDiscoveryGetInstanceAllNamespaceShouldWork() {
Lister<V1Service> serviceLister = setupServiceLister(NAMESPACE_ALL, TEST_SERVICE_1, TEST_SERVICE_2);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister(NAMESPACE_1, TEST_ENDPOINTS_1);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister(TEST_ENDPOINTS_1);

KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, true,
Set.of(), true, 60, false, null, Set.of(), Map.of(), null,
Expand All @@ -143,7 +143,7 @@ void testDiscoveryGetInstanceAllNamespaceShouldWork() {
@Test
void testDiscoveryGetInstanceOneNamespaceShouldWork() {
Lister<V1Service> serviceLister = setupServiceLister(NAMESPACE_1, TEST_SERVICE_1, TEST_SERVICE_2);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister(NAMESPACE_1, TEST_ENDPOINTS_1);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister(TEST_ENDPOINTS_1);

KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, false,
Set.of(), true, 60, false, null, Set.of(), Map.of(), null,
Expand Down Expand Up @@ -173,7 +173,7 @@ void testDiscoveryGetInstanceOneNamespaceShouldWork() {
*/
@Test
void testAllNamespacesTwoServicesPresent() {
Lister<V1Endpoints> endpointsLister = setupEndpointsLister("");
Lister<V1Endpoints> endpointsLister = setupEndpointsLister();

boolean allNamespaces = true;
V1Service serviceA = new V1Service().metadata(new V1ObjectMeta().name("service-a").namespace("namespace-a"));
Expand Down Expand Up @@ -207,7 +207,7 @@ void testAllNamespacesTwoServicesPresent() {
*/
@Test
void testSingleNamespaceTwoServicesPresent() {
Lister<V1Endpoints> endpointsLister = setupEndpointsLister("");
Lister<V1Endpoints> endpointsLister = setupEndpointsLister();

boolean allNamespaces = false;
V1Service serviceA = new V1Service().metadata(new V1ObjectMeta().name("service-a").namespace("namespace-a"));
Expand Down Expand Up @@ -330,6 +330,20 @@ void testAllSingleTwoEndpointsPresent() {
Assertions.assertThat(byIp).contains("1.1.1.1");
}

@Test
void testOrder() {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of("a", "b"),
true, 60L, false, "", Set.of(), Map.of(), "", null, 57, false, true);

Lister<V1Service> serviceLister = setupServiceLister(NAMESPACE_ALL, TEST_SERVICE_1, TEST_SERVICE_2);
Lister<V1Endpoints> endpointsLister = setupEndpointsLister(TEST_ENDPOINTS_1);

KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient(sharedInformerFactory,
serviceLister, endpointsLister, null, null, properties);

Assertions.assertThat(discoveryClient.getOrder()).isEqualTo(57);
}

private Lister<V1Service> setupServiceLister(String namespace, V1Service... services) {
Lister<V1Service> serviceLister = new Lister<>(serviceCache, namespace);
for (V1Service svc : services) {
Expand All @@ -338,7 +352,7 @@ private Lister<V1Service> setupServiceLister(String namespace, V1Service... serv
return serviceLister;
}

private Lister<V1Endpoints> setupEndpointsLister(String namespace, V1Endpoints... endpoints) {
private Lister<V1Endpoints> setupEndpointsLister(V1Endpoints... endpoints) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor simplification that is un-related to the issue itself

Lister<V1Endpoints> endpointsLister = new Lister<>(endpointsCache);
for (V1Endpoints ep : endpoints) {
endpointsCache.add(ep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public Flux<String> getServices() {
.subscribeOn(Schedulers.boundedElastic());
}

@Override
public int getOrder() {
return kubernetesDiscoveryClient.getOrder();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ void testPodMetadata() {
.containsExactlyInAnyOrderEntriesOf(Map.of("c", "d"));
}

@Test
void testOrder() {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60L,
false, "", Set.of(), Map.of(), "", null, 57, false);

KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null);

Assertions.assertThat(discoveryClient.getOrder()).isEqualTo(57);
}

private void createEndpoints(String namespace, String name, Map<String, String> labels) {
client.endpoints()
.inNamespace(namespace)
Expand Down
Loading