Skip to content

feat: all event source is resource event source #2367

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 7 commits into from
May 2, 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
15 changes: 9 additions & 6 deletions docs/documentation/v5-0-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ permalink: /docs/v5-0-migration
[`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11)
now contains all the utility methods used for event sources naming that were previously defined in
the `EventSourceInitializer` interface.
3. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources
3. Similarly, the `EventSourceProvider` interface has been remove, replaced by explicit initialization of the associated
event source on `DependentResource` via the `
Optional<? extends EventSource<R, P>> eventSource(EventSourceContext<P> eventSourceContext)` method.
4. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources
implementation have been updated to allow you to specify a name when instantiating them. If you don't provide a name
for your `EventSource` implementation (for example, by using its default, no-arg constructor), one will be
automatically generated. This simplifies the API to define event source to
Expand All @@ -27,7 +30,7 @@ permalink: /docs/v5-0-migration
them automatically might result in duplicated event sources being registered as JOSDK relies on the name to identify
event sources and concurrent, dynamic registration might lead to identical event sources having different generated
names, thus leading JOSDK to consider them as different and hence, register them multiple times.
4. Updates through `UpdateControl` now
5. Updates through `UpdateControl` now
use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add
the finalizer and for all
the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can
Expand All @@ -46,11 +49,11 @@ permalink: /docs/v5-0-migration
the status sub-resource is not instructed to be updated. This is not true for SSA, observed generation is updated
only when patch status is instructed by `UpdateControl`.

5. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed
6. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed
via the accordingly renamed `managedWorkflowAndDependentResourceContext` method.
6. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should
7. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should
work without it by default. To optimize and handle special cases see the relevant section
in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type).
7. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed,
8. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed,
use `Operator.stop(Duration)` instead.
8. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead
9. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.javaoperatorsdk.operator.health.EventSourceHealthIndicator;
import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator;
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;

/**
* RuntimeInfo in general is available when operator is fully started. You can use "isStarted" to
Expand Down Expand Up @@ -64,9 +65,7 @@ public Map<String, Map<String, EventSourceHealthIndicator>> unhealthyEventSource

/**
* @return Aggregated Map with controller related event sources that wraps an informer. Thus,
* either a
* {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource}
* or an
* either a {@link ControllerEventSource} or an
* {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}.
*/
public Map<String, Map<String, InformerWrappingEventSourceHealthIndicator>> unhealthyInformerWrappingEventSourceHealthIndicator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;

/** An interface from which to retrieve configuration information. */
public interface ConfigurationService {
Expand Down Expand Up @@ -212,8 +213,7 @@ default Optional<LeaderElectionConfiguration> getLeaderElectionConfiguration() {
* <p>
* if true, operator stops if there are some issues with informers
* {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource} or
* {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource}
* on startup. Other event sources may also respect this flag.
* {@link ControllerEventSource} on startup. Other event sources may also respect this flag.
* </p>
* <p>
* if false, the startup will ignore recoverable errors, caused for example by RBAC issues, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public <T> Set<T> getSecondaryResources(Class<T> expectedType) {

@Override
public IndexedResourceCache<P> getPrimaryCache() {
return controller.getEventSourceManager().getControllerResourceEventSource();
return controller.getEventSourceManager().getControllerEventSource();
}

@Override
Expand All @@ -55,7 +55,7 @@ public boolean isNextReconciliationImminent() {

@Override
public <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
return controller.getEventSourceManager().getResourceEventSourcesFor(expectedType).stream()
return controller.getEventSourceManager().getEventSourcesFor(expectedType).stream()
.map(es -> es.getSecondaryResources(primaryResource))
.flatMap(Set::stream);
}
Expand All @@ -64,7 +64,7 @@ public <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
public <T> Optional<T> getSecondaryResource(Class<T> expectedType, String eventSourceName) {
return controller
.getEventSourceManager()
.getResourceEventSourceFor(expectedType, eventSourceName)
.getEventSourceFor(expectedType, eventSourceName)
.getSecondaryResource(primaryResource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;

/**
* An interface to implement and provide dependent resource support.
Expand All @@ -32,8 +32,8 @@ public interface DependentResource<R, P extends HasMetadata> {
Class<R> resourceType();

/**
* Dependent resources are designed to by default provide event sources. There are cases where
* they might not:
* Dependent resources are designed to provide event sources by default. There are, however, cases
* where they might not:
* <ul>
* <li>If an event source is shared between multiple dependent resources. In this case only one or
* none of the dependent resources sharing the event source should provide one, if any.</li>
Expand All @@ -42,9 +42,10 @@ public interface DependentResource<R, P extends HasMetadata> {
* </ul>
*
* @param eventSourceContext context of event source initialization
* @return an optional event source
* @return an optional event source initialized from the specified context
* @since 5.0.0
*/
default Optional<? extends ResourceEventSource<R, P>> eventSource(
default Optional<? extends EventSource<R, P>> eventSource(
EventSourceContext<P> eventSourceContext) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.javaoperatorsdk.operator.processing.event.EventSourceManager;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;

@SuppressWarnings("rawtypes")
public class ControllerHealthInfo {
Expand Down Expand Up @@ -36,8 +37,7 @@ public Map<String, InformerWrappingEventSourceHealthIndicator> informerEventSour

/**
* @return Map with event sources that wraps an informer. Thus, either a
* {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource}
* or an
* {@link ControllerEventSource} or an
* {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}.
*/
public Map<String, InformerWrappingEventSourceHealthIndicator> unhealthyInformerEventSourceHealthIndicators() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import io.javaoperatorsdk.operator.processing.event.EventProcessor;
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE;

Expand Down Expand Up @@ -103,7 +103,7 @@ public Controller(Reconciler<P> reconciler,
eventSourceManager.postProcessDefaultEventSourcesAfterProcessorInitializer();
controllerHealthInfo = new ControllerHealthInfo(eventSourceManager);
eventSourceContext = new EventSourceContext<>(
eventSourceManager.getControllerResourceEventSource(), configuration, kubernetesClient);
eventSourceManager.getControllerEventSource(), configuration, kubernetesClient);
initAndRegisterEventSources(eventSourceContext);
configurationService.getMetrics().controllerRegistered(this);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public void initAndRegisterEventSources(EventSourceContext<P> context) {
final var size = dependentResourcesByName.size();
if (size > 0) {
dependentResourcesByName.forEach(dependentResource -> {
Optional<ResourceEventSource> eventSource = dependentResource.eventSource(context);
Optional<EventSource> eventSource = dependentResource.eventSource(context);
eventSource.ifPresent(eventSourceManager::registerEventSource);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller;
import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;

@Ignore
public abstract class AbstractEventSourceHolderDependentResource<R, P extends HasMetadata, T extends ResourceEventSource<R, P>>
public abstract class AbstractEventSourceHolderDependentResource<R, P extends HasMetadata, T extends EventSource<R, P>>
extends AbstractDependentResource<R, P> implements EventSourceReferencer<P> {

private T eventSource;
Expand Down Expand Up @@ -67,7 +67,7 @@ public synchronized Optional<T> eventSource(EventSourceContext<P> context) {
public void resolveEventSource(EventSourceRetriever<P> eventSourceRetriever) {
if (eventSourceNameToUse != null && eventSource == null) {
final var source =
eventSourceRetriever.getResourceEventSourceFor(resourceType(), eventSourceNameToUse);
eventSourceRetriever.getEventSourceFor(resourceType(), eventSourceNameToUse);
if (source == null) {
throw new EventSourceNotFoundException(eventSourceNameToUse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller;
import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;

public abstract class AbstractExternalDependentResource<R, P extends HasMetadata, T extends ResourceEventSource<R, P>>
public abstract class AbstractExternalDependentResource<R, P extends HasMetadata, T extends EventSource<R, P>>
extends AbstractEventSourceHolderDependentResource<R, P, T> {

private final boolean isDependentResourceWithExplicitState =
Expand All @@ -34,7 +34,7 @@ public void resolveEventSource(EventSourceRetriever<P> eventSourceRetriever) {
final var eventSourceName = (String) dependentResourceWithExplicitState
.eventSourceName().orElse(null);
externalStateEventSource = (InformerEventSource<?, P>) eventSourceRetriever
.getResourceEventSourceFor(dependentResourceWithExplicitState.stateResourceClass(),
.getEventSourceFor(dependentResourceWithExplicitState.stateResourceClass(),
eventSourceName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public EventProcessor(EventSourceManager<P> eventSourceManager,
this(
eventSourceManager.getController().getConfiguration(),
new ReconciliationDispatcher<>(eventSourceManager.getController()), eventSourceManager,
configurationService.getMetrics(), eventSourceManager.getControllerResourceEventSource());
configurationService.getMetrics(), eventSourceManager.getControllerEventSource());
}

@SuppressWarnings("rawtypes")
Expand All @@ -64,7 +64,7 @@ public EventProcessor(EventSourceManager<P> eventSourceManager,
this(
controllerConfiguration,
reconciliationDispatcher, eventSourceManager, metrics,
eventSourceManager.getControllerResourceEventSource());
eventSourceManager.getControllerEventSource());
}

@SuppressWarnings({"rawtypes", "unchecked"})
Expand Down
Loading
Loading