17
17
import io .javaoperatorsdk .operator .OperatorException ;
18
18
import io .javaoperatorsdk .operator .ReconcilerUtils ;
19
19
import io .javaoperatorsdk .operator .api .config .dependent .DependentResourceSpec ;
20
- import io .javaoperatorsdk .operator .api .reconciler .Constants ;
20
+ import io .javaoperatorsdk .operator .api .reconciler .* ;
21
21
import io .javaoperatorsdk .operator .api .reconciler .ControllerConfiguration ;
22
- import io .javaoperatorsdk .operator .api .reconciler .Reconciler ;
23
22
import io .javaoperatorsdk .operator .api .reconciler .dependent .Dependent ;
24
23
import io .javaoperatorsdk .operator .api .reconciler .dependent .DependentResource ;
25
24
import io .javaoperatorsdk .operator .processing .dependent .kubernetes .KubernetesDependent ;
@@ -54,9 +53,8 @@ public AnnotationControllerConfiguration(Reconciler<P> reconciler) {
54
53
this .reconciler = reconciler ;
55
54
this .annotation = reconciler .getClass ().getAnnotation (ControllerConfiguration .class );
56
55
if (annotation == null ) {
57
- throw new OperatorException (
58
- "Missing mandatory @" + ControllerConfiguration .class .getSimpleName () +
59
- " annotation for reconciler: " + reconciler );
56
+ throw new OperatorException ("Missing mandatory @" + CONTROLLER_CONFIG_ANNOTATION +
57
+ " annotation for reconciler: " + reconciler );
60
58
}
61
59
}
62
60
@@ -247,9 +245,9 @@ public List<DependentResourceSpec> getDependentResources() {
247
245
final var context = "DependentResource of type '" + dependentType .getName () + "'" ;
248
246
spec = new DependentResourceSpec (dependentType , config , name ,
249
247
Set .of (dependent .dependsOn ()),
250
- instantiateConditionIfNotDefault (dependent .readyPostcondition (), context ),
251
- instantiateConditionIfNotDefault (dependent .reconcilePrecondition (), context ),
252
- instantiateConditionIfNotDefault (dependent .deletePostcondition (), context ));
248
+ instantiateIfNotDefault (dependent .readyPostcondition (), Condition . class , context ),
249
+ instantiateIfNotDefault (dependent .reconcilePrecondition (), Condition . class , context ),
250
+ instantiateIfNotDefault (dependent .deletePostcondition (), Condition . class , context ));
253
251
specsMap .put (name , spec );
254
252
}
255
253
@@ -258,10 +256,10 @@ public List<DependentResourceSpec> getDependentResources() {
258
256
return specs ;
259
257
}
260
258
261
- protected Condition <?, ?> instantiateConditionIfNotDefault (Class <? extends Condition > condition ,
259
+ protected < T > T instantiateIfNotDefault (Class <? extends T > toInstantiate , Class < T > defaultClass ,
262
260
String context ) {
263
- if (condition != Condition . class ) {
264
- return instantiateAndConfigureIfNeeded (condition , Condition . class , context );
261
+ if (! defaultClass . equals ( toInstantiate ) ) {
262
+ return instantiateAndConfigureIfNeeded (toInstantiate , defaultClass , context );
265
263
}
266
264
return null ;
267
265
}
@@ -287,6 +285,7 @@ private Object createKubernetesResourceConfig(Class<? extends DependentResource>
287
285
OnUpdateFilter <? extends HasMetadata > onUpdateFilter = null ;
288
286
OnDeleteFilter <? extends HasMetadata > onDeleteFilter = null ;
289
287
GenericFilter <? extends HasMetadata > genericFilter = null ;
288
+ ResourceDiscriminator <?, ? extends HasMetadata > resourceDiscriminator = null ;
290
289
if (kubeDependent != null ) {
291
290
if (!Arrays .equals (KubernetesDependent .DEFAULT_NAMESPACES ,
292
291
kubeDependent .namespaces ())) {
@@ -297,7 +296,6 @@ private Object createKubernetesResourceConfig(Class<? extends DependentResource>
297
296
final var fromAnnotation = kubeDependent .labelSelector ();
298
297
labelSelector = Constants .NO_VALUE_SET .equals (fromAnnotation ) ? null : fromAnnotation ;
299
298
300
-
301
299
final var context =
302
300
KUBE_DEPENDENT_NAME + " annotation on " + dependentType .getName () + " DependentResource" ;
303
301
onAddFilter = createFilter (kubeDependent .onAddFilter (), OnAddFilter .class , context )
@@ -311,10 +309,15 @@ private Object createKubernetesResourceConfig(Class<? extends DependentResource>
311
309
genericFilter =
312
310
createFilter (kubeDependent .genericFilter (), GenericFilter .class , context )
313
311
.orElse (null );
312
+
313
+ resourceDiscriminator =
314
+ instantiateIfNotDefault (kubeDependent .resourceDiscriminator (),
315
+ ResourceDiscriminator .class , context );
314
316
}
315
317
316
318
config =
317
- new KubernetesDependentResourceConfig (namespaces , labelSelector , configuredNS , onAddFilter ,
319
+ new KubernetesDependentResourceConfig (namespaces , labelSelector , configuredNS ,
320
+ resourceDiscriminator , onAddFilter ,
318
321
onUpdateFilter , onDeleteFilter , genericFilter );
319
322
320
323
return config ;
0 commit comments