@@ -99,6 +99,67 @@ We prepared a few examples for common use-cases which are shown below:
99
99
- [ PagerExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/PagerExample.java ) :
100
100
Support Pagination (only for the list request) to ease server-side loads/network congestion.
101
101
102
+
103
+ __ list all pods__ :
104
+
105
+ ```
106
+ import io.kubernetes.client.ApiClient;
107
+ import io.kubernetes.client.ApiException;
108
+ import io.kubernetes.client.Configuration;
109
+ import io.kubernetes.client.apis.CoreV1Api;
110
+ import io.kubernetes.client.models.V1Pod;
111
+ import io.kubernetes.client.models.V1PodList;
112
+ import io.kubernetes.client.util.Config;
113
+
114
+ import java.io.IOException;
115
+
116
+ public class Example {
117
+ public static void main(String[] args) throws IOException, ApiException{
118
+ ApiClient client = Config.defaultClient();
119
+ Configuration.setDefaultApiClient(client);
120
+
121
+ CoreV1Api api = new CoreV1Api();
122
+ V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
123
+ for (V1Pod item : list.getItems()) {
124
+ System.out.println(item.getMetadata().getName());
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+ __ watch on namespace object__ :
131
+
132
+ ```
133
+ import com.google.gson.reflect.TypeToken;
134
+ import io.kubernetes.client.ApiClient;
135
+ import io.kubernetes.client.ApiException;
136
+ import io.kubernetes.client.Configuration;
137
+ import io.kubernetes.client.apis.CoreV1Api;
138
+ import io.kubernetes.client.models.V1Namespace;
139
+ import io.kubernetes.client.util.Config;
140
+ import io.kubernetes.client.util.Watch;
141
+
142
+ import java.io.IOException;
143
+
144
+ public class WatchExample {
145
+ public static void main(String[] args) throws IOException, ApiException{
146
+ ApiClient client = Config.defaultClient();
147
+ Configuration.setDefaultApiClient(client);
148
+
149
+ CoreV1Api api = new CoreV1Api();
150
+
151
+ Watch<V1Namespace> watch = Watch.createWatch(
152
+ client,
153
+ api.listNamespaceCall(null, null, null, null, null, 5, null, null, Boolean.TRUE, null, null),
154
+ new TypeToken<Watch.Response<V1Namespace>>(){}.getType());
155
+
156
+ for (Watch.Response<V1Namespace> item : watch) {
157
+ System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName());
158
+ }
159
+ }
160
+ }
161
+ ```
162
+
102
163
More examples can be found in [ examples] ( examples/ ) folder. To run examples, run this command:
103
164
104
165
``` shell
0 commit comments