use of io.kubernetes.client.extended.controller.reconciler.Reconciler in project java by kubernetes-client.
the class ControllerExample method main.
public static void main(String[] args) throws IOException {
CoreV1Api coreV1Api = new CoreV1Api();
ApiClient apiClient = coreV1Api.getApiClient();
OkHttpClient httpClient = apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build();
apiClient.setHttpClient(httpClient);
// instantiating an informer-factory, and there should be only one informer-factory
// globally.
SharedInformerFactory informerFactory = new SharedInformerFactory();
// registering node-informer into the informer-factory.
SharedIndexInformer<V1Node> nodeInformer = informerFactory.sharedIndexInformerFor((CallGeneratorParams params) -> {
return coreV1Api.listNodeCall(null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
}, V1Node.class, V1NodeList.class);
informerFactory.startAllRegisteredInformers();
EventBroadcaster eventBroadcaster = new LegacyEventBroadcaster(coreV1Api);
// nodeReconciler prints node information on events
NodePrintingReconciler nodeReconciler = new NodePrintingReconciler(nodeInformer, eventBroadcaster.newRecorder(new V1EventSource().host("localhost").component("node-printer")));
// Use builder library to construct a default controller.
Controller controller = ControllerBuilder.defaultBuilder(informerFactory).watch((workQueue) -> ControllerBuilder.controllerWatchBuilder(V1Node.class, workQueue).withWorkQueueKeyFunc((V1Node node) -> new Request(node.getMetadata().getName())).withOnAddFilter((V1Node createdNode) -> createdNode.getMetadata().getName().startsWith(// optional, set onAdd filter
"docker-")).withOnUpdateFilter((V1Node oldNode, V1Node newNode) -> newNode.getMetadata().getName().startsWith(// optional, set onUpdate filter
"docker-")).withOnDeleteFilter((V1Node deletedNode, Boolean stateUnknown) -> deletedNode.getMetadata().getName().startsWith(// optional, set onDelete filter
"docker-")).build()).withReconciler(// required, set the actual reconciler
nodeReconciler).withName(// optional, set name for controller
"node-printing-controller").withWorkerCount(// optional, set worker thread count
4).withReadyFunc(// optional, only starts controller when the
nodeInformer::hasSynced).build();
// Use builder library to manage one or multiple controllers.
ControllerManager controllerManager = ControllerBuilder.controllerManagerBuilder(informerFactory).addController(controller).build();
LeaderElectingController leaderElectingController = new LeaderElectingController(new LeaderElector(new LeaderElectionConfig(new EndpointsLock("kube-system", "leader-election", "foo"), Duration.ofMillis(10000), Duration.ofMillis(8000), Duration.ofMillis(5000))), controllerManager);
leaderElectingController.run();
}
Aggregations