Skip to content

refactor: getDependentResources return type is more generic #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters;

@SuppressWarnings("rawtypes")
public class AnnotationControllerConfiguration<R extends HasMetadata>
implements io.javaoperatorsdk.operator.api.config.ControllerConfiguration<R> {

protected final Reconciler<R> reconciler;
private final ControllerConfiguration annotation;
private ConfigurationService service;
private List<DependentResourceSpec> specs;
private List<DependentResourceSpec<?, ?>> specs;

public AnnotationControllerConfiguration(Reconciler<R> reconciler) {
this.reconciler = reconciler;
Expand Down Expand Up @@ -147,14 +146,15 @@ public static <T> T valueOrDefault(

@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public List<DependentResourceSpec> getDependentResources() {
public List<DependentResourceSpec<?, ?>> getDependentResources() {
if (specs == null) {
final var dependents =
valueOrDefault(annotation, ControllerConfiguration::dependents, new Dependent[] {});
if (dependents.length == 0) {
return Collections.emptyList();
}

Object config = null;
specs = new ArrayList<>(dependents.length);
for (Dependent dependent : dependents) {
final Class<? extends DependentResource> dependentType = dependent.type();
Expand All @@ -172,13 +172,10 @@ public List<DependentResourceSpec> getDependentResources() {
kubeDependent,
KubernetesDependent::addOwnerReference,
KubernetesDependent.ADD_OWNER_REFERENCE_DEFAULT);
KubernetesDependentResourceConfig config =
new KubernetesDependentResourceConfig(
addOwnerReference, namespaces, labelSelector, getConfigurationService());
specs.add(new DependentResourceSpec(dependentType, config));
} else {
specs.add(new DependentResourceSpec(dependentType));
config = new KubernetesDependentResourceConfig(
addOwnerReference, namespaces, labelSelector, getConfigurationService());
}
specs.add(new DependentResourceSpec(dependentType, config));
}
}
return specs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters;

@SuppressWarnings("rawtypes")
public interface ControllerConfiguration<R extends HasMetadata> extends ResourceConfiguration<R> {

default String getName() {
Expand Down Expand Up @@ -52,7 +51,7 @@ default ResourceEventFilter<R> getEventFilter() {
return ResourceEventFilters.passthrough();
}

default List<DependentResourceSpec> getDependentResources() {
default List<DependentResourceSpec<?, ?>> getDependentResources() {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ControllerConfigurationOverrider<R extends HasMetadata> {
private ResourceEventFilter<R> customResourcePredicate;
private final ControllerConfiguration<R> original;
private Duration reconciliationMaxInterval;
private final List<DependentResourceSpec> dependentResourceSpecs;
private final List<DependentResourceSpec<?, ?>> dependentResourceSpecs;

private ControllerConfigurationOverrider(ControllerConfiguration<R> original) {
finalizer = original.getFinalizer();
Expand Down Expand Up @@ -115,7 +115,7 @@ public void addNewDependentResourceConfig(DependentResourceSpec dependentResourc
dependentResourceSpecs.add(dependentResourceSpec);
}

private Optional<DependentResourceSpec> findConfigForDependentResourceClass(
private Optional<DependentResourceSpec<?, ?>> findConfigForDependentResourceClass(
Class<? extends DependentResource> dependentResourceClass) {
return dependentResourceSpecs.stream()
.filter(dc -> dc.getDependentResourceClass().equals(dependentResourceClass))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DefaultControllerConfiguration<R extends HasMetadata>
private final boolean generationAware;
private final RetryConfiguration retryConfiguration;
private final ResourceEventFilter<R> resourceEventFilter;
private final List<DependentResourceSpec> dependents;
private final List<DependentResourceSpec<?, ?>> dependents;
private final Duration reconciliationMaxInterval;

// NOSONAR constructor is meant to provide all information
Expand All @@ -38,7 +38,7 @@ public DefaultControllerConfiguration(
Class<R> resourceClass,
Duration reconciliationMaxInterval,
ConfigurationService service,
List<DependentResourceSpec> dependents) {
List<DependentResourceSpec<?, ?>> dependents) {
super(labelSelector, resourceClass, namespaces);
this.associatedControllerClassName = associatedControllerClassName;
this.name = name;
Expand Down Expand Up @@ -102,7 +102,7 @@ public ResourceEventFilter<R> getEventFilter() {
}

@Override
public List<DependentResourceSpec> getDependentResources() {
public List<DependentResourceSpec<?, ?>> getDependentResources() {
return dependents;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public class DependentResourceSpec<T extends DependentResource<?, ?>, C> {

private final C dependentResourceConfig;

public DependentResourceSpec(Class<T> dependentResourceClass) {
this(dependentResourceClass, null);
}

public DependentResourceSpec(Class<T> dependentResourceClass, C dependentResourceConfig) {
this.dependentResourceClass = dependentResourceClass;
this.dependentResourceConfig = dependentResourceConfig;
Expand Down