Skip to content

Commit 6183985

Browse files
committed
refactor: extract more generic instantiateIfNotDefault method
1 parent d7e8a90 commit 6183985

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AnnotationControllerConfiguration.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ public List<DependentResourceSpec> getDependentResources() {
245245
final var context = "DependentResource of type '" + dependentType.getName() + "'";
246246
spec = new DependentResourceSpec(dependentType, config, name,
247247
Set.of(dependent.dependsOn()),
248-
instantiateConditionIfNotDefault(dependent.readyPostcondition(), context),
249-
instantiateConditionIfNotDefault(dependent.reconcilePrecondition(), context),
250-
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));
251251
specsMap.put(name, spec);
252252
}
253253

@@ -256,10 +256,10 @@ public List<DependentResourceSpec> getDependentResources() {
256256
return specs;
257257
}
258258

259-
protected Condition<?, ?> instantiateConditionIfNotDefault(Class<? extends Condition> condition,
259+
protected <T> T instantiateIfNotDefault(Class<? extends T> toInstantiate, Class<T> defaultClass,
260260
String context) {
261-
if (condition != Condition.class) {
262-
return instantiateAndConfigureIfNeeded(condition, Condition.class, context);
261+
if (!defaultClass.equals(toInstantiate)) {
262+
return instantiateAndConfigureIfNeeded(toInstantiate, defaultClass, context);
263263
}
264264
return null;
265265
}
@@ -311,7 +311,7 @@ private Object createKubernetesResourceConfig(Class<? extends DependentResource>
311311
.orElse(null);
312312

313313
resourceDiscriminator =
314-
instantiateDiscriminatorIfNotVoid(kubeDependent.resourceDiscriminator());
314+
instantiateIfNotDefault(kubeDependent.resourceDiscriminator(), ResourceDiscriminator.class, context);
315315
}
316316

317317
config =
@@ -321,17 +321,7 @@ private Object createKubernetesResourceConfig(Class<? extends DependentResource>
321321

322322
return config;
323323
}
324-
325-
@SuppressWarnings({"unchecked"})
326-
private ResourceDiscriminator<?, ? extends HasMetadata> instantiateDiscriminatorIfNotVoid(
327-
Class<? extends ResourceDiscriminator> discriminator) {
328-
if (discriminator != ResourceDiscriminator.class) {
329-
return instantiateAndConfigureIfNeeded(discriminator, ResourceDiscriminator.class,
330-
CONTROLLER_CONFIG_ANNOTATION);
331-
}
332-
return null;
333-
}
334-
324+
335325
public static <T> T valueOrDefault(
336326
ControllerConfiguration controllerConfiguration,
337327
Function<ControllerConfiguration, T> mapper,

0 commit comments

Comments
 (0)