use of com.marcnuri.yakc.api.core.v1.CoreV1Api in project yakc by manusa.
the class NamespaceService method watch.
@Override
public Observable<WatchEvent<Namespace>> watch() throws IOException {
final CoreV1Api core = kubernetesClient.create(CoreV1Api.class);
final String configNamespace = kubernetesClient.getConfiguration().getNamespace();
return tryWithFallback(() -> {
core.listNamespace(new CoreV1Api.ListNamespace().limit(1)).get();
return core.listNamespace().watch();
}, () -> {
if (configNamespace != null) {
core.listNamespace(new CoreV1Api.ListNamespace().limit(1).fieldSelector("metadata.name=" + configNamespace)).get();
return core.listNamespace(new CoreV1Api.ListNamespace().fieldSelector("metadata.name=" + configNamespace)).watch();
}
return Observable.empty();
}, () -> {
if (configNamespace != null) {
return justWithNoComplete(new WatchEvent<>(WatchEvent.Type.ADDED, core.readNamespace(configNamespace).get()));
}
return Observable.empty();
});
}
use of com.marcnuri.yakc.api.core.v1.CoreV1Api in project yakc by manusa.
the class CrdQuickstart method main.
public static void main(String[] args) {
System.out.println("Complete Custom Resource Definition (CRD) example:\n" + " - Creates a namespace\n" + " - Deletes CRD if exists\n" + " - Creates CRD\n" + " - Creates custom resource - TV Show\n" + " - List entries for custom resource - TV Show\n" + " - Patch entry for custom resource - TV Show\n" + " - List patched entries for custom resource - TV Show\n" + "Starting...\n");
try (KubernetesClient kc = new KubernetesClient()) {
final CoreV1Api core = kc.create(CoreV1Api.class);
final ApiextensionsV1Api extensions = kc.create(ApiextensionsV1Api.class);
final ShowsV1Api shows = kc.create(ShowsV1Api.class);
createNamespace(core);
deleteCrdIfExists(extensions);
createCrd(extensions);
createShows(shows);
listShows(shows);
patchShow(shows);
listShows(shows);
deleteCrd(extensions);
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of com.marcnuri.yakc.api.core.v1.CoreV1Api 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 in project yakc by manusa.
the class SecretService method watch.
@Override
public Observable<WatchEvent<Secret>> watch() throws IOException {
final CoreV1Api api = kubernetesClient.create(CoreV1Api.class);
return tryWithFallback(() -> {
api.listSecretForAllNamespaces(new ListSecretForAllNamespaces().limit(1)).get();
return api.listSecretForAllNamespaces().watch();
}, () -> {
final String ns = kubernetesClient.getConfiguration().getNamespace();
api.listNamespacedSecret(ns, new ListNamespacedSecret().limit(1)).get();
return api.listNamespacedSecret(ns).watch();
});
}
use of com.marcnuri.yakc.api.core.v1.CoreV1Api in project yakc by manusa.
the class ServiceService method watch.
@Override
public Observable<WatchEvent<Service>> watch() throws IOException {
final CoreV1Api api = kubernetesClient.create(CoreV1Api.class);
return tryWithFallback(() -> {
api.listServiceForAllNamespaces(new ListServiceForAllNamespaces().limit(1)).get();
return api.listServiceForAllNamespaces().watch();
}, () -> {
final String ns = kubernetesClient.getConfiguration().getNamespace();
api.listNamespacedService(ns, new ListNamespacedService().limit(1)).get();
return api.listNamespacedService(ns).watch();
});
}
Aggregations