use of com.marcnuri.yakc.api.core.v1.CoreV1Api.ReadNamespacedPodLog 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();
}
}
use of com.marcnuri.yakc.api.core.v1.CoreV1Api.ReadNamespacedPodLog in project yakc by manusa.
the class PodIT method readNamespacedPodLog.
@Test
@DisplayName("readNamespacedPodLog, should wait for pod to start and retrieve logs")
void readNamespacedPodLog() throws IOException {
// Given
awaitPodReady();
// When
final String podLog = KC.create(CoreV1Api.class).readNamespacedPodLog(podName, NAMESPACE, new ReadNamespacedPodLog().timestamps(true)).get();
// Then
assertThat(podLog).contains("Busybox for IT started");
}
Aggregations