1313package io .kubernetes .client .examples ;
1414
1515import io .kubernetes .client .extended .controller .Controller ;
16+ import io .kubernetes .client .extended .controller .builder .ControllerBuilder ;
17+ import io .kubernetes .client .extended .controller .builder .DefaultControllerBuilder ;
1618import io .kubernetes .client .extended .controller .reconciler .Reconciler ;
1719import io .kubernetes .client .extended .controller .reconciler .Request ;
1820import io .kubernetes .client .extended .controller .reconciler .Result ;
2830import io .kubernetes .client .spring .extended .controller .annotation .GroupVersionResource ;
2931import io .kubernetes .client .spring .extended .controller .annotation .KubernetesInformer ;
3032import io .kubernetes .client .spring .extended .controller .annotation .KubernetesInformers ;
31- import io .kubernetes .client .spring .extended .controller .annotation .KubernetesReconciler ;
3233import io .kubernetes .client .spring .extended .controller .annotation .KubernetesReconcilerReadyFunc ;
33- import io .kubernetes .client .spring .extended .controller .annotation .KubernetesReconcilerWatch ;
34- import io .kubernetes .client .spring .extended .controller .annotation .KubernetesReconcilerWatches ;
35- import io .kubernetes .client .spring .extended .controller .factory .KubernetesControllerFactory ;
34+ import java .time .Duration ;
3635import org .springframework .beans .factory .annotation .Autowired ;
37- import org .springframework .beans .factory .annotation .Qualifier ;
3836import org .springframework .beans .factory .annotation .Value ;
3937import org .springframework .boot .CommandLineRunner ;
4038import org .springframework .boot .SpringApplication ;
@@ -55,8 +53,7 @@ public static class AppConfig {
5553
5654 @ Bean
5755 public CommandLineRunner commandLineRunner (
58- SharedInformerFactory sharedInformerFactory ,
59- @ Qualifier ("node-printing-controller" ) Controller nodePrintingController ) {
56+ SharedInformerFactory sharedInformerFactory , Controller nodePrintingController ) {
6057 return args -> {
6158 System .out .println ("starting informers.." );
6259 sharedInformerFactory .startAllRegisteredInformers ();
@@ -66,12 +63,19 @@ public CommandLineRunner commandLineRunner(
6663 };
6764 }
6865
69- // *REQUIRED*
70- // factorybean to crete controller
71- @ Bean ("node-printing-controller" )
72- public KubernetesControllerFactory kubernetesReconcilerConfigurer (
73- SharedInformerFactory sharedInformerFactory , Reconciler reconciler ) {
74- return new KubernetesControllerFactory (sharedInformerFactory , reconciler );
66+ @ Bean
67+ public Controller nodePrintingController (
68+ SharedInformerFactory sharedInformerFactory , NodePrintingReconciler reconciler ) {
69+ DefaultControllerBuilder builder = ControllerBuilder .defaultBuilder (sharedInformerFactory );
70+ builder =
71+ builder .watch (
72+ (q ) -> {
73+ return ControllerBuilder .controllerWatchBuilder (V1Node .class , q )
74+ .withResyncPeriod (Duration .ofMinutes (1 ))
75+ .build ();
76+ });
77+ builder .withWorkerCount (2 );
78+ return builder .withReconciler (reconciler ).withName ("nodePrintingController" ).build ();
7579 }
7680 }
7781
@@ -96,19 +100,6 @@ public KubernetesControllerFactory kubernetesReconcilerConfigurer(
96100 @ Component
97101 public static class MySharedInformerFactory extends SharedInformerFactory {}
98102
99- // As long as a reconciler bean attached `@KubernetesReconciler` detected in the context, we
100- // will
101- // be automatically creating a conresponding controller bean implementing {@link
102- // io.kubernetes.client.extended.controller.Controller}
103- // with the name specified and registering it to the spring bean-factory.
104- @ KubernetesReconciler (
105- watches =
106- @ KubernetesReconcilerWatches ({
107- @ KubernetesReconcilerWatch (
108- apiTypeClass = V1Node .class ,
109- resyncPeriodMillis = 60 * 1000L // fully resync every 1 minute
110- ),
111- }))
112103 @ Component
113104 public static class NodePrintingReconciler implements Reconciler {
114105
0 commit comments