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();
}
}
Aggregations