Skip to content
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

improve: generics for prepare event source #2407

Merged
merged 1 commit into from
Jun 19, 2024
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 @@ -70,7 +70,7 @@ protected void createConfigMap(P resource, Context<P> context) {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, P>> prepareEventSources(
EventSourceContext<P> context) {

var boundedItemStore =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
public class EventSourceUtils {

@SuppressWarnings("unchecked")
public static <R extends HasMetadata> List<EventSource> dependentEventSources(
EventSourceContext<R> eventSourceContext, DependentResource... dependentResources) {
public static <P extends HasMetadata> List<EventSource<?, P>> dependentEventSources(
EventSourceContext<P> eventSourceContext, DependentResource... dependentResources) {
return Arrays.stream(dependentResources)
.flatMap(dr -> dr.eventSource(eventSourceContext).stream()).toList();
}

@SuppressWarnings("unchecked")
public static <K extends HasMetadata> List<EventSource> eventSourcesFromWorkflow(
EventSourceContext<K> context,
Workflow<K> workflow) {
public static <P extends HasMetadata> List<EventSource<?, P>> eventSourcesFromWorkflow(
EventSourceContext<P> context,
Workflow<P> workflow) {
return workflow.getDependentResourcesWithoutActivationCondition().stream()
.flatMap(dr -> dr.eventSource(context).stream()).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface Reconciler<P extends HasMetadata> {
* sources
* @return a list of event sources
*/
default List<EventSource> prepareEventSources(EventSourceContext<P> context) {
default List<EventSource<?, P>> prepareEventSources(EventSourceContext<P> context) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, BulkDependentTestCustomResource>> prepareEventSources(
EventSourceContext<BulkDependentTestCustomResource> context) {
return List.of(dependent.initEventSource(context));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ChangeNamespaceTestReconciler
new ConcurrentHashMap<>();

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, ChangeNamespaceTestCustomResource>> prepareEventSources(
EventSourceContext<ChangeNamespaceTestCustomResource> context) {

InformerEventSource<ConfigMap, ChangeNamespaceTestCustomResource> configMapES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private ConfigMap desired(ClusterScopedCustomResource resource) {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, ClusterScopedCustomResource>> prepareEventSources(
EventSourceContext<ClusterScopedCustomResource> context) {
var ies = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context)
.withSecondaryToPrimaryMapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public UpdateControl<ComplexDependentCustomResource> reconcile(
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, ComplexDependentCustomResource>> prepareEventSources(
EventSourceContext<ComplexDependentCustomResource> context) {
InformerEventSource<Service, ComplexDependentCustomResource> serviceEventSource =
new InformerEventSource<>(SERVICE_EVENT_SOURCE_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, CreateUpdateEventFilterTestCustomResource>> prepareEventSources(
EventSourceContext<CreateUpdateEventFilterTestCustomResource> context) {
InformerConfiguration<ConfigMap> informerConfiguration =
InformerConfiguration.from(ConfigMap.class, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public UpdateControl<DependentReInitializationCustomResource> reconcile(
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, DependentReInitializationCustomResource>> prepareEventSources(
EventSourceContext<DependentReInitializationCustomResource> context) {
return EventSourceUtils.dependentEventSources(context,
configMapDependentResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, DependnetSSACustomResource>> prepareEventSources(
EventSourceContext<DependnetSSACustomResource> context) {
return EventSourceUtils.dependentEventSources(context,
ssaConfigMapDependent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, ExternalStateCustomResource>> prepareEventSources(
EventSourceContext<ExternalStateCustomResource> context) {
var configMapEventSource = new InformerEventSource<>(
InformerConfiguration.from(ConfigMap.class, context).build(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, ExternalStateCustomResource>> prepareEventSources(
EventSourceContext<ExternalStateCustomResource> context) {

configMapEventSource = new InformerEventSource<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, ExternalStateBulkDependentCustomResource>> prepareEventSources(
EventSourceContext<ExternalStateBulkDependentCustomResource> context) {
var configMapEventSource = new InformerEventSource<>(
InformerConfiguration.from(ConfigMap.class, context).build(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, FilterTestCustomResource>> prepareEventSources(
EventSourceContext<FilterTestCustomResource> context) {

InformerEventSource<ConfigMap, FilterTestCustomResource> configMapES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public UpdateControl<GenericKubernetesDependentStandaloneCustomResource> reconci
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, GenericKubernetesDependentStandaloneCustomResource>> prepareEventSources(
EventSourceContext<GenericKubernetesDependentStandaloneCustomResource> context) {
return List.of(dependent.eventSource(context).orElseThrow());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ GenericKubernetesResource desiredConfigMap(


@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, GenericKubernetesResourceHandlingCustomResource>> prepareEventSources(
EventSourceContext<GenericKubernetesResourceHandlingCustomResource> context) {

var informerEventSource = new InformerEventSource<>(InformerConfiguration.from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class InformerEventSourceTestCustomReconciler
private final AtomicInteger numberOfExecutions = new AtomicInteger(0);

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, InformerEventSourceTestCustomResource>> prepareEventSources(
EventSourceContext<InformerEventSourceTestCustomResource> context) {

InformerConfiguration<ConfigMap> config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DependentGarbageCollectionTestReconciler() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, DependentGarbageCollectionTestCustomResource>> prepareEventSources(
EventSourceContext<DependentGarbageCollectionTestCustomResource> context) {
return EventSourceUtils.dependentEventSources(context, configMapDependent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public UpdateControl<MultipleDependentResourceCustomResource> reconcile(
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, MultipleDependentResourceCustomResource>> prepareEventSources(
EventSourceContext<MultipleDependentResourceCustomResource> context) {
InformerEventSource<ConfigMap, MultipleDependentResourceCustomResource> eventSource =
new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, MultipleDependentResourceCustomResourceWithDiscriminator>> prepareEventSources(
EventSourceContext<MultipleDependentResourceCustomResourceWithDiscriminator> context) {
InformerEventSource<ConfigMap, MultipleDependentResourceCustomResourceWithDiscriminator> eventSource =
new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, MultipleManagedDependentNoDiscriminatorCustomResource>> prepareEventSources(
EventSourceContext<MultipleManagedDependentNoDiscriminatorCustomResource> context) {
InformerEventSource<ConfigMap, MultipleManagedDependentNoDiscriminatorCustomResource> ies =
new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, MultipleManagedDependentResourceCustomResource>> prepareEventSources(
EventSourceContext<MultipleManagedDependentResourceCustomResource> context) {
InformerEventSource<ConfigMap, MultipleManagedDependentResourceCustomResource> ies =
new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, MultipleManagedExternalDependentResourceCustomResource>> prepareEventSources(
EventSourceContext<MultipleManagedExternalDependentResourceCustomResource> context) {

final PollingEventSource.GenericResourceFetcher<ExternalResource> fetcher = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int getNumberOfExecutions() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, MultipleSecondaryEventSourceCustomResource>> prepareEventSources(
EventSourceContext<MultipleSecondaryEventSourceCustomResource> context) {

var config = InformerConfiguration.from(ConfigMap.class, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public UpdateControl<PerResourceEventSourceCustomResource> reconcile(
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, PerResourceEventSourceCustomResource>> prepareEventSources(
EventSourceContext<PerResourceEventSourceCustomResource> context) {
PerResourcePollingEventSource<String, PerResourceEventSourceCustomResource> eventSource =
new PerResourcePollingEventSource<>(String.class, context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PrimaryIndexerTestReconciler
extends AbstractPrimaryIndexerTestReconciler {

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, PrimaryIndexerTestCustomResource>> prepareEventSources(
EventSourceContext<PrimaryIndexerTestCustomResource> context) {

context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public UpdateControl<Job> reconcile(
}

@Override
public List<EventSource> prepareEventSources(EventSourceContext<Job> context) {
public List<EventSource<?, Job>> prepareEventSources(EventSourceContext<Job> context) {
context.getPrimaryCache().addIndexer(JOB_CLUSTER_INDEX, (job -> List
.of(indexKey(job.getSpec().getClusterName(), job.getMetadata().getNamespace()))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int getNumberOfExecutions() {
* demand for it.
**/
@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, PrimaryToSecondaryDependentCustomResource>> prepareEventSources(
EventSourceContext<PrimaryToSecondaryDependentCustomResource> context) {
// there is no owner reference in the config map, but we still want to trigger reconciliation if
// the config map changes. So first we add an index which custom resource references the config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public StandaloneDependentTestReconciler() {
}

@Override
public List<EventSource> prepareEventSources(
public List<EventSource<?, StandaloneDependentTestCustomResource>> prepareEventSources(
EventSourceContext<StandaloneDependentTestCustomResource> context) {
return EventSourceUtils.dependentEventSources(context,
deploymentDependent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public WebappReconciler(KubernetesClient kubernetesClient) {
}

@Override
public List<EventSource> prepareEventSources(EventSourceContext<Webapp> context) {
public List<EventSource<?, Webapp>> prepareEventSources(EventSourceContext<Webapp> context) {
/*
* To create an event to a related WebApp resource and trigger the reconciliation we need to
* find which WebApp this Tomcat custom resource is related to. To find the related
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) {
}

@Override
public List<EventSource> prepareEventSources(EventSourceContext<WebPage> context) {
public List<EventSource<?, WebPage>> prepareEventSources(EventSourceContext<WebPage> context) {
return EventSourceUtils.dependentEventSources(context, configMapDR,
deploymentDR, serviceDR,
ingressDR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public WebPageReconciler() {
}

@Override
public List<EventSource> prepareEventSources(EventSourceContext<WebPage> context) {
public List<EventSource<?, WebPage>> prepareEventSources(EventSourceContext<WebPage> context) {
var configMapEventSource =
new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context)
.withLabelSelector(SELECTOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public WebPageStandaloneDependentsReconciler() {
}

@Override
public List<EventSource> prepareEventSources(EventSourceContext<WebPage> context) {
public List<EventSource<?, WebPage>> prepareEventSources(EventSourceContext<WebPage> context) {
// initializes the dependents' event sources from the given context
return EventSourceUtils.eventSourcesFromWorkflow(context, workflow);
}
Expand Down
Loading