Skip to content

Commit fef9e61

Browse files
authored
Merge pull request #1900 from cmaune/patch-1
fix: use ',' as delimiter for key-value pairs in labelSelector. Fixes #1899
2 parents dc8862d + 7382b53 commit fef9e61

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesCatalogWatchContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static List<EndpointNameAndNamespace> state(Stream<V1ObjectReference> references
4848
}
4949

5050
static String labelSelector(Map<String, String> labels) {
51-
return labels.entrySet().stream().map(en -> en.getKey() + "=" + en.getValue()).collect(Collectors.joining("&"));
51+
return labels.entrySet().stream().map(en -> en.getKey() + "=" + en.getValue()).collect(Collectors.joining(","));
5252
}
5353

5454
}

spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesCatalogWatchContextTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.kubernetes.client.discovery.catalog;
1818

19+
import java.util.LinkedHashMap;
1920
import java.util.Map;
2021

2122
import org.junit.jupiter.api.Assertions;
@@ -40,10 +41,11 @@ void singleLabel() {
4041

4142
@Test
4243
void multipleLabelsLabel() {
43-
String result = KubernetesCatalogWatchContext.labelSelector(Map.of("a", "b", "c", "d"));
44-
Assertions.assertTrue(result.contains("c=d"));
45-
Assertions.assertTrue(result.contains("&"));
46-
Assertions.assertTrue(result.contains("a=b"));
44+
Map<String, String> labels = new LinkedHashMap<>();
45+
labels.put("a", "b");
46+
labels.put("c", "d");
47+
String result = KubernetesCatalogWatchContext.labelSelector(labels);
48+
Assertions.assertEquals("a=b,c=d", result);
4749
}
4850

4951
}

spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesCatalogWatchEndpointSlicesTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void testInAllNamespacesWithSingleLabel() {
9696
@Test
9797
@Override
9898
void testInAllNamespacesWithDoubleLabel() {
99-
stubFor(get("/apis/discovery.k8s.io/v1/endpointslices?labelSelector=a%3Db%26c%3Dd")
99+
stubFor(get("/apis/discovery.k8s.io/v1/endpointslices?labelSelector=a%3Db%2Cc%3Dd")
100100
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpointSlices("a", "default")))));
101101
// otherwise the stub might fail
102102
LinkedHashMap<String, String> map = new LinkedHashMap<>();
@@ -137,9 +137,9 @@ void testInSpecificNamespacesWithSingleLabel() {
137137
@Test
138138
@Override
139139
void testInSpecificNamespacesWithDoubleLabel() {
140-
stubFor(get("/apis/discovery.k8s.io/v1/namespaces/one/endpointslices?labelSelector=a%3Db%26c%3Dd")
140+
stubFor(get("/apis/discovery.k8s.io/v1/namespaces/one/endpointslices?labelSelector=a%3Db%2Cc%3Dd")
141141
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpointSlices("aa", "a")))));
142-
stubFor(get("/apis/discovery.k8s.io/v1/namespaces/two/endpointslices?labelSelector=a%3Db%26c%3Dd")
142+
stubFor(get("/apis/discovery.k8s.io/v1/namespaces/two/endpointslices?labelSelector=a%3Db%2Cc%3Dd")
143143
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpointSlices("bb", "b")))));
144144

145145
// otherwise the stub might fail
@@ -179,7 +179,7 @@ void testInOneNamespaceWithSingleLabel() {
179179
@Test
180180
@Override
181181
void testInOneNamespaceWithDoubleLabel() {
182-
stubFor(get("/apis/discovery.k8s.io/v1/namespaces/b/endpointslices?labelSelector=key%3Dvalue%26key1%3Dvalue1")
182+
stubFor(get("/apis/discovery.k8s.io/v1/namespaces/b/endpointslices?labelSelector=key%3Dvalue%2Ckey1%3Dvalue1")
183183
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpointSlices("a", "b")))));
184184
// otherwise the stub might fail
185185
LinkedHashMap<String, String> map = new LinkedHashMap<>();

spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesCatalogWatchEndpointsTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void testInAllNamespacesWithSingleLabel() {
9696
@Test
9797
@Override
9898
void testInAllNamespacesWithDoubleLabel() {
99-
stubFor(get("/api/v1/endpoints?labelSelector=a%3Db%26c%3Dd")
99+
stubFor(get("/api/v1/endpoints?labelSelector=a%3Db%2Cc%3Dd")
100100
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpoints("a", "default")))));
101101
// otherwise the stub might fail
102102
LinkedHashMap<String, String> map = new LinkedHashMap<>();
@@ -137,9 +137,9 @@ void testInSpecificNamespacesWithSingleLabel() {
137137
@Test
138138
@Override
139139
void testInSpecificNamespacesWithDoubleLabel() {
140-
stubFor(get("/api/v1/namespaces/one/endpoints?labelSelector=a%3Db%26c%3Dd")
140+
stubFor(get("/api/v1/namespaces/one/endpoints?labelSelector=a%3Db%2Cc%3Dd")
141141
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpoints("aa", "a")))));
142-
stubFor(get("/api/v1/namespaces/two/endpoints?labelSelector=a%3Db%26c%3Dd")
142+
stubFor(get("/api/v1/namespaces/two/endpoints?labelSelector=a%3Db%2Cc%3Dd")
143143
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpoints("bb", "b")))));
144144

145145
// otherwise the stub might fail
@@ -179,7 +179,7 @@ void testInOneNamespaceWithSingleLabel() {
179179
@Test
180180
@Override
181181
void testInOneNamespaceWithDoubleLabel() {
182-
stubFor(get("/api/v1/namespaces/b/endpoints?labelSelector=key%3Dvalue%26key1%3Dvalue1")
182+
stubFor(get("/api/v1/namespaces/b/endpoints?labelSelector=key%3Dvalue%2Ckey1%3Dvalue1")
183183
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(endpoints("a", "b")))));
184184
// otherwise the stub might fail
185185
LinkedHashMap<String, String> map = new LinkedHashMap<>();

0 commit comments

Comments
 (0)