Search in sources :

Example 1 with CakeController

use of it.fvaleri.integ.controller.CakeController in project integ-examples by fvaleri.

the class CakeOperator method main.

public static void main(String[] args) {
    try (KubernetesClient client = new DefaultKubernetesClient()) {
        String namespace = client.getNamespace();
        if (namespace == null) {
            LOG.warn("No namespace found via config, assuming default");
            namespace = "default";
        }
        LOG.info("Using namespace {}", namespace);
        OperationContext namespaced = new OperationContext().withNamespace(namespace);
        // an infomer creates a watcher for a specific resource type and caches related events
        // you can subscribe to these events by registering a resource event handler
        SharedInformerFactory informerFactory = client.informers();
        SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, namespaced, RESYNC_PERIOD_MS);
        SharedIndexInformer<Cake> cakeSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(Cake.class, namespaced, RESYNC_PERIOD_MS);
        LOG.debug("Informer factories initialized");
        MixedOperation<Cake, CakeList, Resource<Cake>> cakeClient = client.customResources(Cake.class, CakeList.class);
        CakeController cakeController = new CakeController(client, cakeClient, podSharedIndexInformer, cakeSharedIndexInformer, namespace);
        LOG.debug("Controller initialized");
        cakeController.create();
        informerFactory.startAllRegisteredInformers();
        informerFactory.addSharedInformerEventListener(e -> LOG.error("Exception occurred", e));
        cakeController.run();
    } catch (KubernetesClientException e) {
        LOG.error("Kubernetes client exception: {}", e.getMessage());
    }
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.base.OperationContext) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) CakeList(it.fvaleri.integ.model.v1alpha1.CakeList) Pod(io.fabric8.kubernetes.api.model.Pod) Cake(it.fvaleri.integ.model.v1alpha1.Cake) Resource(io.fabric8.kubernetes.client.dsl.Resource) CakeController(it.fvaleri.integ.controller.CakeController) SharedInformerFactory(io.fabric8.kubernetes.client.informers.SharedInformerFactory) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

Pod (io.fabric8.kubernetes.api.model.Pod)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 OperationContext (io.fabric8.kubernetes.client.dsl.base.OperationContext)1 SharedInformerFactory (io.fabric8.kubernetes.client.informers.SharedInformerFactory)1 CakeController (it.fvaleri.integ.controller.CakeController)1 Cake (it.fvaleri.integ.model.v1alpha1.Cake)1 CakeList (it.fvaleri.integ.model.v1alpha1.CakeList)1