Skip to content

Commit

Permalink
Merge pull request #970 from yue9944882/generic-kubernetes-api-example
Browse files Browse the repository at this point in the history
Generic kubernetes client example
  • Loading branch information
k8s-ci-robot authored Jun 4, 2020
2 parents 034a292 + 2783088 commit 0197ea7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ We prepared a few examples for common use-cases which are shown below:
Leader election utilities to help implement HA controllers.
- ([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):
Building a kubernetes controller based on spring framework's bean injection.
- ([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):
Construct a generic client interface for any kubernetes types, including CRDs.


__list all pods__:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kubernetes.client.examples;

import com.google.common.annotations.Beta;
import io.kubernetes.client.custom.V1Patch;
import io.kubernetes.client.extended.generic.GenericKubernetesApi;
import io.kubernetes.client.extended.generic.KubernetesApiResponse;
import io.kubernetes.client.openapi.ApiClient;
Expand All @@ -17,6 +18,7 @@ public class GenericClientExample {

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

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

KubernetesApiResponse<V1Pod> patchResponse =
podClient.patch(
"default",
"foo",
V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH,
new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}"));
if (!patchResponse.isSuccess()) {
throw new RuntimeException(patchResponse.getStatus().toString());
}
System.out.println("Patched!");

KubernetesApiResponse<V1Pod> deleteResponse = podClient.delete("default", "foo");
if (!deleteResponse.isSuccess()) {
throw new RuntimeException(deleteResponse.getStatus().toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.kubernetes.client.extended.generic;

import com.google.common.annotations.Beta;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -40,7 +39,6 @@
* @param <ApiType> the api type parameter
* @param <ApiListType> the api list type parameter
*/
@Beta
public class GenericKubernetesApi<ApiType, ApiListType> {

// TODO(yue9944882): supports status operations..
Expand Down

0 comments on commit 0197ea7

Please sign in to comment.