Skip to content

Commit 3a1e3d9

Browse files
authored
Merge pull request #1252 from yue9944882/refactor/generic-api-failure-flow
Refactor: Generic kubernetes api failure flow
2 parents 0fe6a1f + 1f8c247 commit 3a1e3d9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

examples/src/main/java/io/kubernetes/client/examples/GenericClientExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import io.kubernetes.client.custom.V1Patch;
1616
import io.kubernetes.client.openapi.ApiClient;
17+
import io.kubernetes.client.openapi.ApiException;
1718
import io.kubernetes.client.openapi.models.V1Container;
1819
import io.kubernetes.client.openapi.models.V1ObjectMeta;
1920
import io.kubernetes.client.openapi.models.V1Pod;
@@ -45,7 +46,7 @@ public static void main(String[] args) throws Exception {
4546
.onFailure(
4647
errorStatus -> {
4748
System.out.println("Not Created!");
48-
throw new RuntimeException(errorStatus.toString());
49+
throw new ApiException(errorStatus.toString());
4950
})
5051
.getObject();
5152
System.out.println("Created!");
@@ -60,7 +61,7 @@ public static void main(String[] args) throws Exception {
6061
.onFailure(
6162
errorStatus -> {
6263
System.out.println("Not Patched!");
63-
throw new RuntimeException(errorStatus.toString());
64+
throw new ApiException(errorStatus.toString());
6465
})
6566
.getObject();
6667
System.out.println("Patched!");
@@ -71,7 +72,7 @@ public static void main(String[] args) throws Exception {
7172
.onFailure(
7273
errorStatus -> {
7374
System.out.println("Not Deleted!");
74-
throw new RuntimeException(errorStatus.toString());
75+
throw new ApiException(errorStatus.toString());
7576
})
7677
.getObject();
7778
if (deletedPod != null) {

util/src/main/java/io/kubernetes/client/informer/SharedInformerFactory.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.kubernetes.client.util.Watch;
2525
import io.kubernetes.client.util.Watchable;
2626
import io.kubernetes.client.util.generic.GenericKubernetesApi;
27-
import io.kubernetes.client.util.generic.KubernetesApiResponse;
2827
import io.kubernetes.client.util.generic.options.ListOptions;
2928
import java.lang.reflect.Type;
3029
import java.util.HashMap;
@@ -205,18 +204,19 @@ ListerWatcher<ApiType, ApiListType> listerWatcherFor(
205204
}
206205
return new ListerWatcher<ApiType, ApiListType>() {
207206
public ApiListType list(CallGeneratorParams params) throws ApiException {
208-
KubernetesApiResponse<ApiListType> resp =
209-
genericKubernetesApi.list(
207+
return genericKubernetesApi
208+
.list(
210209
new ListOptions() {
211210
{
212211
setResourceVersion(params.resourceVersion);
213212
setTimeoutSeconds(params.timeoutSeconds);
214213
}
215-
});
216-
if (!resp.isSuccess()) {
217-
throw new ApiException(resp.getHttpStatusCode(), resp.getStatus().getMessage());
218-
}
219-
return resp.getObject();
214+
})
215+
.onFailure(
216+
errorStatus -> {
217+
throw new ApiException(errorStatus.toString());
218+
})
219+
.getObject();
220220
}
221221

222222
public Watchable<ApiType> watch(CallGeneratorParams params) throws ApiException {

0 commit comments

Comments
 (0)