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
+
14
+ import java .util .Arrays ;
15
+
16
+ @ Beta
17
+ public class GenericClientExample {
18
+
19
+ public static void main (String [] args ) throws Exception {
20
+
21
+ V1Pod pod = new V1Pod ()
22
+ .metadata (new V1ObjectMeta ()
23
+ .name ("foo" )
24
+ .namespace ("default" )
25
+ )
26
+ .spec (new V1PodSpec ().containers (Arrays .asList (
27
+ new V1Container ().name ("c" ).image ("test" )
28
+ )));
29
+ ApiClient apiClient = ClientBuilder .standard ().build ();
30
+ GenericKubernetesApi <V1Pod , V1PodList > podClient = new GenericKubernetesApi <>(
31
+ V1Pod .class ,
32
+ V1PodList .class ,
33
+ "" ,
34
+ "v1" ,
35
+ "pods" ,
36
+ apiClient );
37
+
38
+ KubernetesApiResponse <V1Pod > createResponse = podClient .create (pod );
39
+ if (!createResponse .isSuccess ()) {
40
+ throw new RuntimeException (createResponse .getStatus ().toString ());
41
+ }
42
+ System .out .println ("Created!" );
43
+
44
+
45
+ KubernetesApiResponse <V1Pod > deleteResponse = podClient .delete ("default" , "foo" );
46
+ if (!deleteResponse .isSuccess ()) {
47
+ throw new RuntimeException (deleteResponse .getStatus ().toString ());
48
+ }
49
+ if (deleteResponse .getObject () != null ) {
50
+ System .out .println ("Received after-deletion status of the requested object, will be deleting in background!" );
51
+ }
52
+ System .out .println ("Deleted!" );
53
+ }
54
+
55
+ }
0 commit comments