use of io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconciler in project java by kubernetes-client.
the class KubernetesControllerFactory method buildController.
private Controller buildController(SharedInformerFactory sharedInformerFactory, Reconciler r) throws BeansException {
KubernetesReconciler kubernetesReconciler = r.getClass().getAnnotation(KubernetesReconciler.class);
String reconcilerName = kubernetesReconciler.value();
KubernetesReconcilerWatches watches = kubernetesReconciler.watches();
DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory);
RateLimitingQueue<Request> workQueue = new DefaultRateLimitingQueue<>();
builder = builder.withWorkQueue(workQueue);
Map<Class, AddFilterAdaptor> addFilters = getAddFilters(watches, r);
Map<Class, UpdateFilterAdaptor> updateFilters = getUpdateFilters(watches, r);
Map<Class, DeleteFilterAdaptor> deleteFilters = getDeleteFilters(watches, r);
List<ReadyFuncAdaptor> readyFuncs = getReadyFuncs(r);
for (KubernetesReconcilerWatch watch : watches.value()) {
try {
Function<? extends KubernetesObject, Request> workQueueKeyFunc;
try {
workQueueKeyFunc = watch.workQueueKeyFunc().getConstructor(WorkQueue.class).newInstance(workQueue);
} catch (NoSuchMethodException e) {
workQueueKeyFunc = watch.workQueueKeyFunc().newInstance();
} catch (InvocationTargetException e) {
throw new BeanCreationException("Failed instantiating controller watch: " + e.getMessage());
}
final Function<? extends KubernetesObject, Request> finalWorkQueueKeyFunc = workQueueKeyFunc;
builder = builder.watch((q) -> {
return ControllerBuilder.controllerWatchBuilder(watch.apiTypeClass(), q).withOnAddFilter(addFilters.get(watch.apiTypeClass())).withOnUpdateFilter(updateFilters.get(watch.apiTypeClass())).withOnDeleteFilter(deleteFilters.get(watch.apiTypeClass())).withWorkQueueKeyFunc(finalWorkQueueKeyFunc).withResyncPeriod(Duration.ofMillis(watch.resyncPeriodMillis())).build();
});
for (Supplier<Boolean> readyFunc : readyFuncs) {
builder = builder.withReadyFunc(readyFunc);
}
} catch (IllegalAccessException | InstantiationException e) {
throw new BeanCreationException("Failed instantiating controller: " + e.getMessage());
}
}
builder = builder.withWorkerCount(kubernetesReconciler.workerCount());
return builder.withReconciler(r).withName(reconcilerName).build();
}
Aggregations