|
| 1 | +package io.kubernetes.client.examples; |
| 2 | + |
| 3 | +import com.google.common.annotations.Beta; |
| 4 | +import io.kubernetes.client.extended.generic.GenericKubernetesApi; |
| 5 | +import io.kubernetes.client.extended.generic.KubernetesApiResponse; |
| 6 | +import io.kubernetes.client.openapi.ApiClient; |
| 7 | +import io.kubernetes.client.openapi.models.V1Container; |
| 8 | +import io.kubernetes.client.openapi.models.V1ObjectMeta; |
| 9 | +import io.kubernetes.client.openapi.models.V1Pod; |
| 10 | +import io.kubernetes.client.openapi.models.V1PodList; |
| 11 | +import io.kubernetes.client.openapi.models.V1PodSpec; |
| 12 | +import io.kubernetes.client.util.ClientBuilder; |
| 13 | +import java.util.Arrays; |
| 14 | + |
| 15 | +@Beta |
| 16 | +public class GenericClientExample { |
| 17 | + |
| 18 | + public static void main(String[] args) throws Exception { |
| 19 | + |
| 20 | + V1Pod pod = |
| 21 | + new V1Pod() |
| 22 | + .metadata(new V1ObjectMeta().name("foo").namespace("default")) |
| 23 | + .spec( |
| 24 | + new V1PodSpec() |
| 25 | + .containers(Arrays.asList(new V1Container().name("c").image("test")))); |
| 26 | + ApiClient apiClient = ClientBuilder.standard().build(); |
| 27 | + GenericKubernetesApi<V1Pod, V1PodList> podClient = |
| 28 | + new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); |
| 29 | + |
| 30 | + KubernetesApiResponse<V1Pod> createResponse = podClient.create(pod); |
| 31 | + if (!createResponse.isSuccess()) { |
| 32 | + throw new RuntimeException(createResponse.getStatus().toString()); |
| 33 | + } |
| 34 | + System.out.println("Created!"); |
| 35 | + |
| 36 | + KubernetesApiResponse<V1Pod> deleteResponse = podClient.delete("default", "foo"); |
| 37 | + if (!deleteResponse.isSuccess()) { |
| 38 | + throw new RuntimeException(deleteResponse.getStatus().toString()); |
| 39 | + } |
| 40 | + if (deleteResponse.getObject() != null) { |
| 41 | + System.out.println( |
| 42 | + "Received after-deletion status of the requested object, will be deleting in background!"); |
| 43 | + } |
| 44 | + System.out.println("Deleted!"); |
| 45 | + } |
| 46 | +} |
0 commit comments