12
12
import io .javaoperatorsdk .operator .processing .event .DefaultEventSourceManager ;
13
13
import io .javaoperatorsdk .operator .processing .event .internal .CustomResourceEventSource ;
14
14
import io .javaoperatorsdk .operator .processing .retry .GenericRetry ;
15
- import io .javaoperatorsdk .operator .processing .retry .Retry ;
16
15
import java .util .Arrays ;
17
16
import org .slf4j .Logger ;
18
17
import org .slf4j .LoggerFactory ;
@@ -49,53 +48,43 @@ public <R extends CustomResource> void register(
49
48
if (configuration == null ) {
50
49
configuration = existing ;
51
50
}
52
- final var retry = GenericRetry .fromConfiguration (configuration .getRetryConfiguration ());
53
- final var targetNamespaces = configuration .getNamespaces ().toArray (new String []{});
54
- registerController (controller , configuration .watchAllNamespaces (), retry , targetNamespaces );
55
- }
56
- }
57
51
58
- @ SuppressWarnings ("rawtypes" )
59
- private <R extends CustomResource > void registerController (
60
- ResourceController <R > controller ,
61
- boolean watchAllNamespaces ,
62
- Retry retry ,
63
- String ... targetNamespaces )
64
- throws OperatorException {
65
- final var configuration = configurationService .getConfigurationFor (controller );
66
- Class <R > resClass = configuration .getCustomResourceClass ();
67
- String finalizer = configuration .getFinalizer ();
68
- MixedOperation client = k8sClient .customResources (resClass );
69
- EventDispatcher dispatcher = new EventDispatcher (controller , finalizer ,
70
- new EventDispatcher .CustomResourceFacade (client ));
52
+ final var retry = GenericRetry .fromConfiguration (configuration .getRetryConfiguration ());
53
+ final var targetNamespaces = configuration .getNamespaces ().toArray (new String [] {});
54
+ Class <R > resClass = configuration .getCustomResourceClass ();
55
+ String finalizer = configuration .getFinalizer ();
56
+ MixedOperation client = k8sClient .customResources (resClass );
57
+ EventDispatcher dispatcher =
58
+ new EventDispatcher (
59
+ controller , finalizer , new EventDispatcher .CustomResourceFacade (client ));
71
60
72
- CustomResourceCache customResourceCache = new CustomResourceCache ();
73
- DefaultEventHandler defaultEventHandler =
74
- new DefaultEventHandler (customResourceCache , dispatcher , configuration .getName (), retry );
75
- DefaultEventSourceManager eventSourceManager =
76
- new DefaultEventSourceManager (defaultEventHandler , retry != null );
77
- defaultEventHandler .setEventSourceManager (eventSourceManager );
78
- dispatcher .setEventSourceManager (eventSourceManager );
61
+ CustomResourceCache customResourceCache = new CustomResourceCache ();
62
+ DefaultEventHandler defaultEventHandler =
63
+ new DefaultEventHandler (customResourceCache , dispatcher , configuration .getName (), retry );
64
+ DefaultEventSourceManager eventSourceManager =
65
+ new DefaultEventSourceManager (defaultEventHandler , retry != null );
66
+ defaultEventHandler .setEventSourceManager (eventSourceManager );
67
+ dispatcher .setEventSourceManager (eventSourceManager );
79
68
80
- controller .init (eventSourceManager );
81
- CustomResourceEventSource customResourceEventSource =
82
- createCustomResourceEventSource (
83
- client ,
84
- customResourceCache ,
85
- watchAllNamespaces ,
86
- targetNamespaces ,
87
- defaultEventHandler ,
88
- configuration .isGenerationAware (),
89
- finalizer );
90
- eventSourceManager .registerCustomResourceEventSource (customResourceEventSource );
69
+ controller .init (eventSourceManager );
70
+ final boolean watchAllNamespaces = configuration .watchAllNamespaces ();
71
+ CustomResourceEventSource customResourceEventSource =
72
+ createCustomResourceEventSource (
73
+ client ,
74
+ customResourceCache ,
75
+ watchAllNamespaces ,
76
+ targetNamespaces ,
77
+ defaultEventHandler ,
78
+ configuration .isGenerationAware (),
79
+ finalizer );
80
+ eventSourceManager .registerCustomResourceEventSource (customResourceEventSource );
91
81
92
- log .info (
93
- "Registered Controller: '{}' for CRD: '{}' for namespaces: {}" ,
94
- controller .getClass ().getSimpleName (),
95
- resClass ,
96
- targetNamespaces .length == 0
97
- ? "[all/client namespace]"
98
- : Arrays .toString (targetNamespaces ));
82
+ log .info (
83
+ "Registered Controller: '{}' for CRD: '{}' for namespaces: {}" ,
84
+ controller .getClass ().getSimpleName (),
85
+ resClass ,
86
+ watchAllNamespaces ? "[all namespaces]" : Arrays .toString (targetNamespaces ));
87
+ }
99
88
}
100
89
101
90
private CustomResourceEventSource createCustomResourceEventSource (
@@ -109,7 +98,7 @@ private CustomResourceEventSource createCustomResourceEventSource(
109
98
CustomResourceEventSource customResourceEventSource =
110
99
watchAllNamespaces
111
100
? CustomResourceEventSource .customResourceEventSourceForAllNamespaces (
112
- customResourceCache , client , generationAware , finalizer )
101
+ customResourceCache , client , generationAware , finalizer )
113
102
: CustomResourceEventSource .customResourceEventSourceForTargetNamespaces (
114
103
customResourceCache , client , targetNamespaces , generationAware , finalizer );
115
104
0 commit comments