Search in sources :

Example 51 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class WatchExample method main.

public static void main(String[] args) throws IOException, ApiException {
    ApiClient client = Config.defaultClient();
    // infinite timeout
    OkHttpClient httpClient = client.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build();
    client.setHttpClient(httpClient);
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();
    Watch<V1Namespace> watch = Watch.createWatch(client, api.listNamespaceCall(null, null, null, null, null, 5, null, null, null, Boolean.TRUE, null), new TypeToken<Watch.Response<V1Namespace>>() {
    }.getType());
    try {
        for (Watch.Response<V1Namespace> item : watch) {
            System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName());
        }
    } finally {
        watch.close();
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) TypeToken(com.google.gson.reflect.TypeToken) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) Watch(io.kubernetes.client.util.Watch) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api)

Example 52 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class LogsExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api coreApi = new CoreV1Api(client);
    PodLogs logs = new PodLogs();
    V1Pod pod = coreApi.listNamespacedPod("default", "false", null, null, null, null, null, null, null, null, null).getItems().get(0);
    InputStream is = logs.streamNamespacedPodLog(pod);
    Streams.copy(is, System.out);
}
Also used : PodLogs(io.kubernetes.client.PodLogs) InputStream(java.io.InputStream) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api)

Example 53 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class PagerExample method main.

public static void main(String[] args) throws IOException {
    ApiClient client = Config.defaultClient();
    OkHttpClient httpClient = client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
    client.setHttpClient(httpClient);
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();
    int i = 0;
    Pager<V1Namespace, V1NamespaceList> pager = new Pager<V1Namespace, V1NamespaceList>((Pager.PagerParams param) -> {
        try {
            return api.listNamespaceCall(null, null, param.getContinueToken(), null, null, param.getLimit(), null, null, 1, null, null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }, client, 10, V1NamespaceList.class);
    for (V1Namespace namespace : pager) {
        System.out.println(namespace.getMetadata().getName());
    }
    System.out.println("------------------");
}
Also used : V1NamespaceList(io.kubernetes.client.openapi.models.V1NamespaceList) OkHttpClient(okhttp3.OkHttpClient) Pager(io.kubernetes.client.extended.pager.Pager) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) IOException(java.io.IOException)

Example 54 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class ProtoExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    ProtoClient pc = new ProtoClient(client);
    ObjectOrStatus<PodList> list = pc.list(PodList.newBuilder(), "/api/v1/namespaces/default/pods");
    if (list.object.getItemsCount() > 0) {
        Pod p = list.object.getItems(0);
        System.out.println(p);
    }
    Namespace namespace = Namespace.newBuilder().setMetadata(ObjectMeta.newBuilder().setName("test").build()).build();
    ObjectOrStatus<Namespace> ns = pc.create(namespace, "/api/v1/namespaces", "v1", "Namespace");
    System.out.println(ns);
    if (ns.object != null) {
        namespace = ns.object.toBuilder().setSpec(NamespaceSpec.newBuilder().addFinalizers("test").build()).build();
        // This is how you would update an object, but you can't actually
        // update namespaces, so this returns a 405
        ns = pc.update(namespace, "/api/v1/namespaces/test", "v1", "Namespace");
        System.out.println(ns.status);
    }
    ns = pc.delete(Namespace.newBuilder(), "/api/v1/namespaces/test");
    System.out.println(ns);
}
Also used : PodList(io.kubernetes.client.proto.V1.PodList) Pod(io.kubernetes.client.proto.V1.Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) Namespace(io.kubernetes.client.proto.V1.Namespace) ProtoClient(io.kubernetes.client.ProtoClient)

Example 55 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class WebSocketsExample method main.

public static void main(String... args) throws ApiException, IOException {
    final ApiClient client = Config.defaultClient();
    WebSockets.stream(args[0], "GET", client, new WebSockets.SocketListener() {

        private volatile WebSocket socket;

        @Override
        public void open(String protocol, WebSocket socket) {
            this.socket = socket;
        }

        @Override
        public void close() {
        }

        @Override
        public void bytesMessage(InputStream is) {
        }

        @Override
        public void failure(Throwable t) {
            t.printStackTrace();
        }

        @Override
        public void textMessage(Reader in) {
            try {
                BufferedReader reader = new BufferedReader(in);
                for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                    System.out.println(line);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
}
Also used : WebSockets(io.kubernetes.client.util.WebSockets) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) IOException(java.io.IOException) ApiClient(io.kubernetes.client.openapi.ApiClient) WebSocket(okhttp3.WebSocket)

Aggregations

ApiClient (io.kubernetes.client.openapi.ApiClient)61 Test (org.junit.Test)28 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)13 V1Pod (io.kubernetes.client.openapi.models.V1Pod)12 IOException (java.io.IOException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)9 ClientBuilder (io.kubernetes.client.util.ClientBuilder)6 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)5 Before (org.junit.Before)5 ApiException (io.kubernetes.client.openapi.ApiException)4 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)3 V1Job (io.kubernetes.client.openapi.models.V1Job)3 V1JobList (io.kubernetes.client.openapi.models.V1JobList)3 V1Namespace (io.kubernetes.client.openapi.models.V1Namespace)3 OkHttpClient (okhttp3.OkHttpClient)3 NodeMetrics (io.kubernetes.client.custom.NodeMetrics)2 PodMetrics (io.kubernetes.client.custom.PodMetrics)2 V1Patch (io.kubernetes.client.custom.V1Patch)2 LeaderElectionConfig (io.kubernetes.client.extended.leaderelection.LeaderElectionConfig)2 LeaderElector (io.kubernetes.client.extended.leaderelection.LeaderElector)2