Skip to content

Commit c8daa58

Browse files
authored
Merge pull request #3930 from cyrilcsr/dev
fix: add missing continue token when build cluster list call
2 parents cbf3f45 + ed4df76 commit c8daa58

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

util/src/main/java/io/kubernetes/client/util/generic/GenericKubernetesApi.java

+1
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ private CallBuilder makeClusterListCallBuilder(final ListOptions listOptions) {
579579
adaptListCall(
580580
customObjectsApi.getApiClient(),
581581
customObjectsApi.listClusterCustomObject( this.apiGroup, this.apiVersion, this.resourcePlural)
582+
._continue(listOptions.getContinue())
582583
.fieldSelector(listOptions.getFieldSelector())
583584
.labelSelector(listOptions.getLabelSelector())
584585
.limit(listOptions.getLimit())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package io.kubernetes.client.util.generic;
2+
3+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
4+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
8+
import io.kubernetes.client.openapi.ApiClient;
9+
import io.kubernetes.client.openapi.JSON;
10+
import io.kubernetes.client.openapi.models.V1Job;
11+
import io.kubernetes.client.openapi.models.V1JobList;
12+
import io.kubernetes.client.openapi.models.V1ListMeta;
13+
import io.kubernetes.client.util.ClientBuilder;
14+
import io.kubernetes.client.util.generic.options.ListOptions;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.api.extension.RegisterExtension;
18+
19+
class GenericKubernetesListApiTest {
20+
@RegisterExtension
21+
static WireMockExtension apiServer =
22+
WireMockExtension.newInstance().options(wireMockConfig().dynamicPort()).build();
23+
24+
private GenericKubernetesApi<V1Job, V1JobList> jobClient;
25+
26+
@BeforeEach
27+
void setup() {
28+
ApiClient apiClient =
29+
new ClientBuilder().setBasePath("http://localhost:" + apiServer.getPort()).build();
30+
jobClient =
31+
new GenericKubernetesApi<>(V1Job.class, V1JobList.class, "batch", "v1", "jobs", apiClient);
32+
}
33+
34+
@Test
35+
void listNamespacedJobWithAllListOptionsSet() {
36+
V1JobList jobList = new V1JobList().kind("PartialObjectMetadataList").metadata(new V1ListMeta());
37+
38+
ListOptions listOptions = new ListOptions()
39+
._continue("continue-token")
40+
.fieldSelector("metadata.name=foo")
41+
.labelSelector("app=web")
42+
.limit(10)
43+
.resourceVersion("12345")
44+
.timeoutSeconds(30)
45+
.isPartialObjectMetadataListRequest(true);
46+
47+
apiServer.stubFor(
48+
get(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
49+
.withHeader(
50+
"Accept",
51+
equalTo("application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json"))
52+
.withQueryParam("continue", equalTo("continue-token"))
53+
.withQueryParam("fieldSelector", equalTo("metadata.name=foo"))
54+
.withQueryParam("labelSelector", equalTo("app=web"))
55+
.withQueryParam("limit", equalTo("10"))
56+
.withQueryParam("resourceVersion", equalTo("12345"))
57+
.withQueryParam("timeoutSeconds", equalTo("30"))
58+
.willReturn(aResponse().withStatus(200).withBody(JSON.serialize(jobList))));
59+
60+
KubernetesApiResponse<V1JobList> response = jobClient.list("default", listOptions);
61+
62+
assertThat(response.isSuccess()).isTrue();
63+
assertThat(response.getObject()).isEqualTo(jobList);
64+
assertThat(response.getStatus()).isNull();
65+
66+
apiServer.verify(
67+
getRequestedFor(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
68+
.withHeader(
69+
"Accept",
70+
equalTo("application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json"))
71+
.withQueryParam("continue", equalTo("continue-token"))
72+
.withQueryParam("fieldSelector", equalTo("metadata.name=foo"))
73+
.withQueryParam("labelSelector", equalTo("app=web"))
74+
.withQueryParam("limit", equalTo("10"))
75+
.withQueryParam("resourceVersion", equalTo("12345"))
76+
.withQueryParam("timeoutSeconds", equalTo("30")));
77+
}
78+
79+
@Test
80+
void listNamespacedJobWithNoListOptionsSet() {
81+
V1JobList jobList = new V1JobList().kind("JobList").metadata(new V1ListMeta());
82+
83+
apiServer.stubFor(
84+
get(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
85+
.willReturn(aResponse().withStatus(200).withBody(JSON.serialize(jobList))));
86+
87+
KubernetesApiResponse<V1JobList> response = jobClient.list("default", new ListOptions());
88+
89+
assertThat(response.isSuccess()).isTrue();
90+
assertThat(response.getObject()).isEqualTo(jobList);
91+
assertThat(response.getStatus()).isNull();
92+
93+
apiServer.verify(
94+
getRequestedFor(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
95+
.withQueryParam("continue", absent())
96+
.withQueryParam("fieldSelector", absent())
97+
.withQueryParam("labelSelector", absent())
98+
.withQueryParam("limit", absent())
99+
.withQueryParam("resourceVersion", absent())
100+
.withQueryParam("timeoutSeconds", absent()));
101+
}
102+
103+
@Test
104+
void listClusterJobWithAllListOptionsSet() {
105+
V1JobList jobList = new V1JobList().kind("PartialObjectMetadataList").metadata(new V1ListMeta());
106+
107+
ListOptions listOptions = new ListOptions()
108+
._continue("continue-token")
109+
.fieldSelector("metadata.name=foo")
110+
.labelSelector("app=web")
111+
.limit(10)
112+
.resourceVersion("12345")
113+
.timeoutSeconds(30)
114+
.isPartialObjectMetadataListRequest(true);
115+
116+
apiServer.stubFor(
117+
get(urlPathEqualTo("/apis/batch/v1/jobs"))
118+
.withHeader(
119+
"Accept",
120+
equalTo("application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json"))
121+
.withQueryParam("continue", equalTo("continue-token"))
122+
.withQueryParam("fieldSelector", equalTo("metadata.name=foo"))
123+
.withQueryParam("labelSelector", equalTo("app=web"))
124+
.withQueryParam("limit", equalTo("10"))
125+
.withQueryParam("resourceVersion", equalTo("12345"))
126+
.withQueryParam("timeoutSeconds", equalTo("30"))
127+
.willReturn(aResponse().withStatus(200).withBody(JSON.serialize(jobList))));
128+
129+
KubernetesApiResponse<V1JobList> response = jobClient.list(listOptions);
130+
131+
assertThat(response.isSuccess()).isTrue();
132+
assertThat(response.getObject()).isEqualTo(jobList);
133+
assertThat(response.getStatus()).isNull();
134+
135+
apiServer.verify(
136+
getRequestedFor(urlPathEqualTo("/apis/batch/v1/jobs"))
137+
.withHeader(
138+
"Accept",
139+
equalTo("application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json"))
140+
.withQueryParam("continue", equalTo("continue-token"))
141+
.withQueryParam("fieldSelector", equalTo("metadata.name=foo"))
142+
.withQueryParam("labelSelector", equalTo("app=web"))
143+
.withQueryParam("limit", equalTo("10"))
144+
.withQueryParam("resourceVersion", equalTo("12345"))
145+
.withQueryParam("timeoutSeconds", equalTo("30")));
146+
}
147+
148+
@Test
149+
void listClusterJobWithNoListOptionsSet() {
150+
V1JobList jobList = new V1JobList().kind("JobList").metadata(new V1ListMeta());
151+
152+
apiServer.stubFor(
153+
get(urlPathEqualTo("/apis/batch/v1/jobs"))
154+
.willReturn(aResponse().withStatus(200).withBody(JSON.serialize(jobList))));
155+
156+
KubernetesApiResponse<V1JobList> response = jobClient.list(new ListOptions());
157+
158+
assertThat(response.isSuccess()).isTrue();
159+
assertThat(response.getObject()).isEqualTo(jobList);
160+
assertThat(response.getStatus()).isNull();
161+
162+
apiServer.verify(
163+
getRequestedFor(urlPathEqualTo("/apis/batch/v1/jobs"))
164+
.withQueryParam("continue", absent())
165+
.withQueryParam("fieldSelector", absent())
166+
.withQueryParam("labelSelector", absent())
167+
.withQueryParam("limit", absent())
168+
.withQueryParam("resourceVersion", absent())
169+
.withQueryParam("timeoutSeconds", absent()));
170+
}
171+
}

0 commit comments

Comments
 (0)