5
5
import io .javaoperatorsdk .operator .api .Controller ;
6
6
import io .javaoperatorsdk .operator .api .ResourceController ;
7
7
import io .javaoperatorsdk .operator .api .config .ControllerConfiguration ;
8
+ import java .util .Optional ;
8
9
import java .util .Set ;
9
10
10
11
public class AnnotationConfiguration <R extends CustomResource >
11
12
implements ControllerConfiguration <R > {
12
13
13
14
private final ResourceController <R > controller ;
14
- private final Controller annotation ;
15
+ private final Optional < Controller > annotation ;
15
16
16
17
public AnnotationConfiguration (ResourceController <R > controller ) {
17
18
this .controller = controller ;
18
- this .annotation = controller .getClass ().getAnnotation (Controller .class );
19
+ this .annotation = Optional . ofNullable ( controller .getClass ().getAnnotation (Controller .class ) );
19
20
}
20
21
21
22
@ Override
@@ -30,16 +31,13 @@ public String getCRDName() {
30
31
31
32
@ Override
32
33
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 ()));
38
36
}
39
37
40
38
@ Override
41
39
public boolean isGenerationAware () {
42
- return annotation .generationAwareEventProcessing ( );
40
+ return annotation .map ( Controller :: generationAwareEventProcessing ). orElse ( true );
43
41
}
44
42
45
43
@ Override
@@ -49,7 +47,7 @@ public Class<R> getCustomResourceClass() {
49
47
50
48
@ Override
51
49
public Set <String > getNamespaces () {
52
- return Set .of (annotation .namespaces ( ));
50
+ return Set .of (annotation .map ( Controller :: namespaces ). orElse ( new String []{} ));
53
51
}
54
52
55
53
@ Override
0 commit comments