Skip to content

Commit 0f78b73

Browse files
authored
bugfix KubernetesApiResponse cannot be cast to class KubernetesObject (#1631)
* bugfix KubernetesApiResponse cannot be cast to class KubernetesObject * fix source code format * update catch ApiException
1 parent 2633bcd commit 0f78b73

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlPatch.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.kubernetes.client.common.KubernetesObject;
1616
import io.kubernetes.client.custom.V1Patch;
1717
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
18+
import io.kubernetes.client.openapi.ApiException;
1819
import io.kubernetes.client.util.ModelMapper;
1920
import io.kubernetes.client.util.generic.GenericKubernetesApi;
2021

@@ -44,10 +45,22 @@ public ApiType execute() throws KubectlException {
4445
refreshDiscovery();
4546

4647
GenericKubernetesApi genericKubernetesApi = getGenericApi();
47-
if (ModelMapper.isNamespaced(apiTypeClass)) {
48-
return (ApiType) genericKubernetesApi.patch(namespace, name, patchType, patchContent);
49-
} else {
50-
return (ApiType) genericKubernetesApi.patch(name, patchType, patchContent);
48+
try {
49+
if (ModelMapper.isNamespaced(apiTypeClass)) {
50+
return (ApiType)
51+
genericKubernetesApi
52+
.patch(namespace, name, patchType, patchContent)
53+
.throwsApiException()
54+
.getObject();
55+
} else {
56+
return (ApiType)
57+
genericKubernetesApi
58+
.patch(name, patchType, patchContent)
59+
.throwsApiException()
60+
.getObject();
61+
}
62+
} catch (ApiException e) {
63+
throw new KubectlException(e);
5164
}
5265
}
5366
}

0 commit comments

Comments
 (0)