1212import io .javaoperatorsdk .operator .processing .event .DefaultEventSourceManager ;
1313import io .javaoperatorsdk .operator .processing .event .internal .CustomResourceEventSource ;
1414import io .javaoperatorsdk .operator .processing .retry .GenericRetry ;
15- import io .javaoperatorsdk .operator .processing .retry .Retry ;
1615import java .util .Arrays ;
1716import org .slf4j .Logger ;
1817import org .slf4j .LoggerFactory ;
@@ -49,53 +48,43 @@ public <R extends CustomResource> void register(
4948 if (configuration == null ) {
5049 configuration = existing ;
5150 }
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- }
5751
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 ));
7160
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 );
7968
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 );
9181
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+ }
9988 }
10089
10190 private CustomResourceEventSource createCustomResourceEventSource (
@@ -109,7 +98,7 @@ private CustomResourceEventSource createCustomResourceEventSource(
10998 CustomResourceEventSource customResourceEventSource =
11099 watchAllNamespaces
111100 ? CustomResourceEventSource .customResourceEventSourceForAllNamespaces (
112- customResourceCache , client , generationAware , finalizer )
101+ customResourceCache , client , generationAware , finalizer )
113102 : CustomResourceEventSource .customResourceEventSourceForTargetNamespaces (
114103 customResourceCache , client , targetNamespaces , generationAware , finalizer );
115104
0 commit comments