Skip to content

Commit 50245f7

Browse files
committed
Merge branch '3.0.x'
2 parents 3d5fd98 + a9c072b commit 50245f7

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace;
3030

31+
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.ALWAYS_TRUE;
3132
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpoints;
3233

3334
/**
@@ -41,7 +42,7 @@ final class Fabric8EndpointsCatalogWatch
4142
@Override
4243
public List<EndpointNameAndNamespace> apply(Fabric8CatalogWatchContext context) {
4344
List<Endpoints> endpoints = endpoints(context.properties(), context.kubernetesClient(),
44-
context.namespaceProvider(), "catalog-watcher", null, x -> true);
45+
context.namespaceProvider(), "catalog-watcher", null, ALWAYS_TRUE);
4546

4647
/**
4748
* <pre>

spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ final class Fabric8KubernetesDiscoveryClientUtils {
7070
private static final LogAccessor LOG = new LogAccessor(
7171
LogFactory.getLog(Fabric8KubernetesDiscoveryClientUtils.class));
7272

73+
static final Predicate<Service> ALWAYS_TRUE = x -> true;
74+
7375
private Fabric8KubernetesDiscoveryClientUtils() {
7476

7577
}
@@ -225,7 +227,7 @@ else if (!properties.namespaces().isEmpty()) {
225227
static List<Endpoints> withFilter(List<Endpoints> endpoints, KubernetesDiscoveryProperties properties,
226228
KubernetesClient client, Predicate<Service> filter) {
227229

228-
if (properties.filter() == null || properties.filter().isBlank()) {
230+
if (properties.filter() == null || properties.filter().isBlank() || filter == ALWAYS_TRUE) {
229231
LOG.debug(() -> "filter not present");
230232
return endpoints;
231233
}

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
3535

36+
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.ALWAYS_TRUE;
37+
3638
/**
3739
* @author wind57
3840
*/
@@ -53,7 +55,7 @@ void afterEach() {
5355
@Test
5456
void withFilterEmptyInput() {
5557
List<Endpoints> result = Fabric8KubernetesDiscoveryClientUtils.withFilter(List.of(), PROPERTIES, client,
56-
x -> true);
58+
ALWAYS_TRUE);
5759
Assertions.assertEquals(result.size(), 0);
5860
}
5961

@@ -87,7 +89,7 @@ void withFilterOneEndpointsMatchInService() {
8789
Endpoints endpoints = createEndpoints("a", "namespace-a");
8890
createService("a", "namespace-a");
8991
List<Endpoints> result = Fabric8KubernetesDiscoveryClientUtils.withFilter(List.of(endpoints), PROPERTIES,
90-
client, x -> true);
92+
client, ALWAYS_TRUE);
9193
Assertions.assertEquals(result.size(), 1);
9294
}
9395

@@ -112,6 +114,28 @@ void withFilterTwoEndpointsOneMatchInService() {
112114
Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespace-a");
113115
}
114116

117+
/**
118+
* <pre>
119+
* - Endpoints with name : "a" and namespace "namespace-a", present
120+
* - Endpoints with name : "b" and namespace "namespace-b", present
121+
* - Service with name "a" and namespace "namespace-a" present
122+
* - Predicate that we use is "ALWAYS_TRUE", so no service filter is applied
123+
*
124+
* As such, there is a match, single endpoints as result.
125+
* This test is the same as above with the difference in the predicate.
126+
* It simulates Fabric8EndpointsCatalogWatch::apply
127+
* </pre>
128+
*/
129+
@Test
130+
void withFilterTwoEndpointsOneMatchInServiceAlwaysTruePredicate() {
131+
Endpoints endpointsA = createEndpoints("a", "namespace-a");
132+
Endpoints endpointsB = createEndpoints("b", "namespace-b");
133+
createService("a", "namespace-a");
134+
List<Endpoints> result = Fabric8KubernetesDiscoveryClientUtils.withFilter(List.of(endpointsA, endpointsB),
135+
PROPERTIES, client, ALWAYS_TRUE);
136+
Assertions.assertEquals(result.size(), 2);
137+
}
138+
115139
/**
116140
* <pre>
117141
* - Endpoints with name : "a" and namespace "namespace-a", present
@@ -132,7 +156,7 @@ void withFilterTwoEndpointsAndThreeServices() {
132156
createService("c", "namespace-c");
133157

134158
List<Endpoints> result = Fabric8KubernetesDiscoveryClientUtils.withFilter(List.of(endpointsA, endpointsB),
135-
PROPERTIES, client, x -> true);
159+
PROPERTIES, client, ALWAYS_TRUE);
136160
Assertions.assertEquals(result.size(), 2);
137161
result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList();
138162
Assertions.assertEquals(result.get(0).getMetadata().getName(), "a");

0 commit comments

Comments
 (0)