55import io .javaoperatorsdk .operator .api .Controller ;
66import io .javaoperatorsdk .operator .api .ResourceController ;
77import io .javaoperatorsdk .operator .api .config .ControllerConfiguration ;
8+ import java .util .Optional ;
89import java .util .Set ;
910
1011public class AnnotationConfiguration <R extends CustomResource >
1112 implements ControllerConfiguration <R > {
1213
1314 private final ResourceController <R > controller ;
14- private final Controller annotation ;
15+ private final Optional < Controller > annotation ;
1516
1617 public AnnotationConfiguration (ResourceController <R > controller ) {
1718 this .controller = controller ;
18- this .annotation = controller .getClass ().getAnnotation (Controller .class );
19+ this .annotation = Optional . ofNullable ( controller .getClass ().getAnnotation (Controller .class ) );
1920 }
2021
2122 @ Override
@@ -30,16 +31,13 @@ public String getCRDName() {
3031
3132 @ Override
3233 public String getFinalizer () {
33- final String annotationFinalizerName = annotation .finalizerName ();
34- if (!Controller .NULL .equals (annotationFinalizerName )) {
35- return annotationFinalizerName ;
36- }
37- return ControllerUtils .getDefaultFinalizerName (getCRDName ());
34+ return annotation .map (Controller ::finalizerName ).filter (String ::isBlank )
35+ .orElse (ControllerUtils .getDefaultFinalizerName (getCRDName ()));
3836 }
3937
4038 @ Override
4139 public boolean isGenerationAware () {
42- return annotation .generationAwareEventProcessing ( );
40+ return annotation .map ( Controller :: generationAwareEventProcessing ). orElse ( true );
4341 }
4442
4543 @ Override
@@ -49,7 +47,7 @@ public Class<R> getCustomResourceClass() {
4947
5048 @ Override
5149 public Set <String > getNamespaces () {
52- return Set .of (annotation .namespaces ( ));
50+ return Set .of (annotation .map ( Controller :: namespaces ). orElse ( new String []{} ));
5351 }
5452
5553 @ Override
0 commit comments