13
13
package io .kubernetes .client .examples ;
14
14
15
15
import io .kubernetes .client .extended .controller .Controller ;
16
+ import io .kubernetes .client .extended .controller .builder .ControllerBuilder ;
17
+ import io .kubernetes .client .extended .controller .builder .DefaultControllerBuilder ;
16
18
import io .kubernetes .client .extended .controller .reconciler .Reconciler ;
17
19
import io .kubernetes .client .extended .controller .reconciler .Request ;
18
20
import io .kubernetes .client .extended .controller .reconciler .Result ;
28
30
import io .kubernetes .client .spring .extended .controller .annotation .GroupVersionResource ;
29
31
import io .kubernetes .client .spring .extended .controller .annotation .KubernetesInformer ;
30
32
import io .kubernetes .client .spring .extended .controller .annotation .KubernetesInformers ;
31
- import io .kubernetes .client .spring .extended .controller .annotation .KubernetesReconciler ;
32
33
import 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 ;
36
35
import org .springframework .beans .factory .annotation .Autowired ;
37
- import org .springframework .beans .factory .annotation .Qualifier ;
38
36
import org .springframework .beans .factory .annotation .Value ;
39
37
import org .springframework .boot .CommandLineRunner ;
40
38
import org .springframework .boot .SpringApplication ;
@@ -55,8 +53,7 @@ public static class AppConfig {
55
53
56
54
@ Bean
57
55
public CommandLineRunner commandLineRunner (
58
- SharedInformerFactory sharedInformerFactory ,
59
- @ Qualifier ("node-printing-controller" ) Controller nodePrintingController ) {
56
+ SharedInformerFactory sharedInformerFactory , Controller nodePrintingController ) {
60
57
return args -> {
61
58
System .out .println ("starting informers.." );
62
59
sharedInformerFactory .startAllRegisteredInformers ();
@@ -66,12 +63,19 @@ public CommandLineRunner commandLineRunner(
66
63
};
67
64
}
68
65
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 ();
75
79
}
76
80
}
77
81
@@ -96,19 +100,6 @@ public KubernetesControllerFactory kubernetesReconcilerConfigurer(
96
100
@ Component
97
101
public static class MySharedInformerFactory extends SharedInformerFactory {}
98
102
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
- }))
112
103
@ Component
113
104
public static class NodePrintingReconciler implements Reconciler {
114
105
0 commit comments