Skip to content

Commit 0197ea7

Browse files
authored
Merge pull request #970 from yue9944882/generic-kubernetes-api-example
Generic kubernetes client example
2 parents 034a292 + 2783088 commit 0197ea7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ We prepared a few examples for common use-cases which are shown below:
104104
Leader election utilities to help implement HA controllers.
105105
- ([9.0.0+](https://github.com/kubernetes-client/java/tree/client-java-parent-9.0.0)) [SpringIntegrationControllerExample](https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java):
106106
Building a kubernetes controller based on spring framework's bean injection.
107+
- ([9.0.0+](https://github.com/kubernetes-client/java/tree/client-java-parent-9.0.0)) [GenericKubernetesClientExample](https://github.com/kubernetes-client/java/blob/master/extended/src/main/java/io/kubernetes/client/extended/generic/GenericKubernetesApi.java):
108+
Construct a generic client interface for any kubernetes types, including CRDs.
107109

108110

109111
__list all pods__:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.kubernetes.client.examples;
22

33
import com.google.common.annotations.Beta;
4+
import io.kubernetes.client.custom.V1Patch;
45
import io.kubernetes.client.extended.generic.GenericKubernetesApi;
56
import io.kubernetes.client.extended.generic.KubernetesApiResponse;
67
import io.kubernetes.client.openapi.ApiClient;
@@ -17,6 +18,7 @@ public class GenericClientExample {
1718

1819
public static void main(String[] args) throws Exception {
1920

21+
// The following codes demonstrates using generic client to manipulate pods
2022
V1Pod pod =
2123
new V1Pod()
2224
.metadata(new V1ObjectMeta().name("foo").namespace("default"))
@@ -33,6 +35,17 @@ public static void main(String[] args) throws Exception {
3335
}
3436
System.out.println("Created!");
3537

38+
KubernetesApiResponse<V1Pod> patchResponse =
39+
podClient.patch(
40+
"default",
41+
"foo",
42+
V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH,
43+
new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}"));
44+
if (!patchResponse.isSuccess()) {
45+
throw new RuntimeException(patchResponse.getStatus().toString());
46+
}
47+
System.out.println("Patched!");
48+
3649
KubernetesApiResponse<V1Pod> deleteResponse = podClient.delete("default", "foo");
3750
if (!deleteResponse.isSuccess()) {
3851
throw new RuntimeException(deleteResponse.getStatus().toString());

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.kubernetes.client.extended.generic;
22

3-
import com.google.common.annotations.Beta;
43
import com.google.common.base.Strings;
54
import com.google.gson.Gson;
65
import com.google.gson.JsonElement;
@@ -40,7 +39,6 @@
4039
* @param <ApiType> the api type parameter
4140
* @param <ApiListType> the api list type parameter
4241
*/
43-
@Beta
4442
public class GenericKubernetesApi<ApiType, ApiListType> {
4543

4644
// TODO(yue9944882): supports status operations..

0 commit comments

Comments
 (0)