Search in sources :

Example 1 with CoreV1Api

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();
    });
}
Also used : CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api)

Example 2 with CoreV1Api

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();
    }
}
Also used : ApiextensionsV1Api(com.marcnuri.yakc.api.apiextensions.v1.ApiextensionsV1Api) KubernetesClient(com.marcnuri.yakc.KubernetesClient) IOException(java.io.IOException) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api)

Example 3 with CoreV1Api

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

Example 4 with CoreV1Api

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();
    });
}
Also used : ListNamespacedSecret(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedSecret) ListSecretForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListSecretForAllNamespaces) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api)

Example 5 with CoreV1Api

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();
    });
}
Also used : ListNamespacedService(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedService) ListServiceForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListServiceForAllNamespaces) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api)

Aggregations

CoreV1Api (com.marcnuri.yakc.api.core.v1.CoreV1Api)6 KubernetesClient (com.marcnuri.yakc.KubernetesClient)3 IOException (java.io.IOException)3 NotFoundException (com.marcnuri.yakc.api.NotFoundException)2 ApiextensionsV1Api (com.marcnuri.yakc.api.apiextensions.v1.ApiextensionsV1Api)1 DeleteCollectionNamespacedPod (com.marcnuri.yakc.api.core.v1.CoreV1Api.DeleteCollectionNamespacedPod)1 ListNamespacedSecret (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedSecret)1 ListNamespacedService (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedService)1 ListSecretForAllNamespaces (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListSecretForAllNamespaces)1 ListServiceForAllNamespaces (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListServiceForAllNamespaces)1 ReadNamespacedPodLog (com.marcnuri.yakc.api.core.v1.CoreV1Api.ReadNamespacedPodLog)1 Pod (com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod)1 Disposable (io.reactivex.disposables.Disposable)1 ExecutorService (java.util.concurrent.ExecutorService)1