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