Search in sources :

Example 1 with DeleteCollectionNamespacedPod

use of com.marcnuri.yakc.api.core.v1.CoreV1Api.DeleteCollectionNamespacedPod in project yakc by manusa.

the class PodLogs method main.

public static void main(String[] args) {
    final boolean follow = Stream.of(args).anyMatch(s -> s.matches("-*?follow"));
    try (KubernetesClient kc = new KubernetesClient()) {
        final CoreV1Api api = kc.create(CoreV1Api.class);
        createPod(api);
        final KubernetesCall<String> podLogCall = api.readNamespacedPodLog(POD_NAME, NAMESPACE, new ReadNamespacedPodLog().follow(follow).pretty("true").timestamps(true));
        if (follow) {
            final ExecutorService readLogService = Executors.newSingleThreadExecutor();
            final Future<Void> logReader = readLogService.submit(new LogReader(podLogCall));
            System.out.println("Log reading started in a parallel thread, following logs for a couple of seconds");
            Thread.sleep(10500L);
            logReader.cancel(true);
            readLogService.shutdownNow();
            System.out.println("Log thread finished");
        } else {
            System.out.println(podLogCall.get());
        }
        System.out.println("Cleaning up");
        api.deleteCollectionNamespacedPod(NAMESPACE, new DeleteCollectionNamespacedPod().gracePeriodSeconds(0).labelSelector(String.format("app=%s", POD_NAME))).get();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : KubernetesClient(com.marcnuri.yakc.KubernetesClient) DeleteCollectionNamespacedPod(com.marcnuri.yakc.api.core.v1.CoreV1Api.DeleteCollectionNamespacedPod) ExecutorService(java.util.concurrent.ExecutorService) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ReadNamespacedPodLog(com.marcnuri.yakc.api.core.v1.CoreV1Api.ReadNamespacedPodLog) IOException(java.io.IOException) NotFoundException(com.marcnuri.yakc.api.NotFoundException)

Aggregations

KubernetesClient (com.marcnuri.yakc.KubernetesClient)1 NotFoundException (com.marcnuri.yakc.api.NotFoundException)1 CoreV1Api (com.marcnuri.yakc.api.core.v1.CoreV1Api)1 DeleteCollectionNamespacedPod (com.marcnuri.yakc.api.core.v1.CoreV1Api.DeleteCollectionNamespacedPod)1 ReadNamespacedPodLog (com.marcnuri.yakc.api.core.v1.CoreV1Api.ReadNamespacedPodLog)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1