Skip to content

Fix generics #634

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5431289
chore(deps): bump micrometer-core from 1.7.4 to 1.7.5 (#606)
dependabot[bot] Oct 15, 2021
30dcf72
fix: re-schedule generics (#614)
csviri Oct 20, 2021
f9ee9b2
chore(deps): bump spring-boot.version from 2.5.5 to 2.5.6 (#617)
dependabot[bot] Oct 22, 2021
fb15a1e
chore(deps): bump awaitility from 4.1.0 to 4.1.1
dependabot[bot] Oct 26, 2021
f188473
fix: prevent double registration of same CR with different controllers
metacosm Oct 26, 2021
b437fef
Informer based CustomResourceEventSource and caching (#581)
csviri Oct 12, 2021
6a3503a
chore: update version to 2.0.0-SNAPSHOT
metacosm Oct 12, 2021
f4b6b7f
Reschedule delete (#600)
csviri Oct 13, 2021
1c9f257
Refined Interface of `EventSource` and `EventSourceManager` (#597)
csviri Oct 13, 2021
cb62f6c
Removing events from context (#596)
csviri Oct 13, 2021
7fc1c64
fix: cache handling on update (#604)
csviri Oct 20, 2021
60660ed
feat: Only one scheduled event (re-schedul / retry) at one time (#609)
csviri Oct 20, 2021
bea733d
feat: Cloner interface for Custom Resource instead of ObjectMapper (#…
csviri Oct 20, 2021
1a3558b
fix: EventSourceManager and ResourceController interface enhancements…
csviri Oct 26, 2021
8199a05
feat!: adapt monitoring code to new implementation
metacosm Oct 21, 2021
a5c481b
feat: removing Event using DefaultEvent instead, renamed DefaultEvent…
csviri Oct 27, 2021
d244948
refactor!: replace Closeable by explicit Stoppable interface
metacosm Oct 27, 2021
d857aca
refactor: fix generics
metacosm Oct 27, 2021
77b6556
chore: clean-up
metacosm Oct 27, 2021
ec53e03
fix: potential performance issue
metacosm Oct 27, 2021
fba211e
chore: clean-up
metacosm Oct 27, 2021
81412a6
fix: more generics fixes
metacosm Oct 27, 2021
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
Prev Previous commit
Next Next commit
refactor: fix generics
  • Loading branch information
metacosm committed Oct 28, 2021
commit d857aca21d2179b3dc6c6be3b190ca8bba2188d9
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.javaoperatorsdk.operator.api.Controller;
import io.javaoperatorsdk.operator.api.ResourceController;

@SuppressWarnings("rawtypes")
public class ControllerUtils {

private static final String FINALIZER_NAME_SUFFIX = "/finalizer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void close() {
* @param <R> the {@code CustomResource} type associated with the controller
* @throws OperatorException if a problem occurred during the registration process
*/
public <R extends CustomResource> void register(ResourceController<R> controller)
public <R extends CustomResource<?, ?>> void register(ResourceController<R> controller)
throws OperatorException {
register(controller, null);
}
Expand All @@ -132,7 +132,7 @@ public <R extends CustomResource> void register(ResourceController<R> controller
* @param <R> the {@code CustomResource} type associated with the controller
* @throws OperatorException if a problem occurred during the registration process
*/
public <R extends CustomResource> void register(
public <R extends CustomResource<?, ?>> void register(
ResourceController<R> controller, ControllerConfiguration<R> configuration)
throws OperatorException {
final var existing = configurationService.getConfigurationFor(controller);
Expand All @@ -148,7 +148,7 @@ public <R extends CustomResource> void register(
configuration = existing;
}
final var configuredController =
new ConfiguredController(controller, configuration, kubernetesClient);
new ConfiguredController<>(controller, configuration, kubernetesClient);
controllers.add(configuredController);

final var watchedNS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

public abstract class BaseControl<T extends BaseControl> {
public abstract class BaseControl<T extends BaseControl<T>> {

private Long scheduleDelay = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.Optional;

import io.fabric8.kubernetes.client.CustomResource;

public interface Context<T extends CustomResource> {
public interface Context {

Optional<RetryInfo> getRetryInfo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.Optional;

import io.fabric8.kubernetes.client.CustomResource;

public class DefaultContext<T extends CustomResource> implements Context<T> {
public class DefaultContext implements Context {

private final RetryInfo retryInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public boolean isRemoveFinalizer() {

@Override
public DeleteControl rescheduleAfter(long delay) {
if (removeFinalizer == true) {
if (removeFinalizer) {
throw new IllegalStateException("Cannot reschedule deleteResource if removing finalizer");
}
return super.rescheduleAfter(delay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.fabric8.kubernetes.client.CustomResource;

public interface ResourceController<R extends CustomResource> {
public interface ResourceController<R extends CustomResource<?, ?>> {

/**
* Note that this method is used in combination of finalizers. If automatic finalizer handling is
Expand All @@ -28,7 +28,7 @@ public interface ResourceController<R extends CustomResource> {
* finalizer to indicate that the resource should not be deleted after all, in which case
* the controller should restore the resource's state appropriately.
*/
default DeleteControl deleteResource(R resource, Context<R> context) {
default DeleteControl deleteResource(R resource, Context context) {
return DeleteControl.defaultDelete();
}

Expand All @@ -46,6 +46,6 @@ default DeleteControl deleteResource(R resource, Context<R> context) {
* be skipped. <b>However we will always call an update if there is no finalizer on object
* and it's not marked for deletion.</b>
*/
UpdateControl<R> createOrUpdateResource(R resource, Context<R> context);
UpdateControl<R> createOrUpdateResource(R resource, Context context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.fabric8.kubernetes.client.CustomResource;

@SuppressWarnings("rawtypes")
public class UpdateControl<T extends CustomResource> extends BaseControl<UpdateControl<T>> {

private final T customResource;
Expand Down Expand Up @@ -34,12 +35,12 @@ public static <T extends CustomResource> UpdateControl<T> updateStatusSubResourc
* @param customResource - custom resource to use in both API calls
* @return UpdateControl instance
*/
public static <T extends CustomResource> UpdateControl<T> updateCustomResourceAndStatus(
public static <T extends CustomResource<?, ?>> UpdateControl<T> updateCustomResourceAndStatus(
T customResource) {
return new UpdateControl<>(customResource, true, true);
}

public static <T extends CustomResource> UpdateControl<T> noUpdate() {
public static <T extends CustomResource<?, ?>> UpdateControl<T> noUpdate() {
return new UpdateControl<>(null, false, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.javaoperatorsdk.operator.ControllerUtils;
import io.javaoperatorsdk.operator.api.ResourceController;

@SuppressWarnings("rawtypes")
public class AbstractConfigurationService implements ConfigurationService {
private final Map<String, ControllerConfiguration> configurations = new ConcurrentHashMap<>();
private final Version version;
Expand All @@ -17,15 +18,15 @@ public AbstractConfigurationService(Version version) {
this.version = version;
}

protected <R extends CustomResource> void register(ControllerConfiguration<R> config) {
protected <R extends CustomResource<?, ?>> void register(ControllerConfiguration<R> config) {
put(config, true);
}

protected <R extends CustomResource> void replace(ControllerConfiguration<R> config) {
protected <R extends CustomResource<?, ?>> void replace(ControllerConfiguration<R> config) {
put(config, false);
}

private <R extends CustomResource> void put(
private <R extends CustomResource<?, ?>> void put(
ControllerConfiguration<R> config, boolean failIfExisting) {
final var name = config.getName();
if (failIfExisting) {
Expand All @@ -38,8 +39,8 @@ private <R extends CustomResource> void put(
config.setConfigurationService(this);
}

protected void throwExceptionOnNameCollision(
String newControllerClassName, ControllerConfiguration existing) {
protected <R extends CustomResource<?, ?>> void throwExceptionOnNameCollision(
String newControllerClassName, ControllerConfiguration<R> existing) {
throw new IllegalArgumentException(
"Controller name '"
+ existing.getName()
Expand All @@ -50,7 +51,7 @@ protected void throwExceptionOnNameCollision(
}

@Override
public <R extends CustomResource> ControllerConfiguration<R> getConfigurationFor(
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
ResourceController<R> controller) {
final var key = keyFor(controller);
final var configuration = configurations.get(key);
Expand All @@ -72,7 +73,7 @@ private String getControllersNameMessage() {
+ ".";
}

protected String keyFor(ResourceController controller) {
protected <R extends CustomResource<?, ?>> String keyFor(ResourceController<R> controller) {
return ControllerUtils.getNameFor(controller);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ConfigurationService {
* @return the {@link ControllerConfiguration} associated with the specified controller or {@code
* null} if no configuration exists for the controller
*/
<R extends CustomResource> ControllerConfiguration<R> getConfigurationFor(
<R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
ResourceController<R> controller);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ConfigurationServiceOverrider withMetrics(Metrics metrics) {
public ConfigurationService build() {
return new ConfigurationService() {
@Override
public <R extends CustomResource> ControllerConfiguration<R> getConfigurationFor(
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
ResourceController<R> controller) {
return original.getConfigurationFor(controller);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilters;

public interface ControllerConfiguration<R extends CustomResource> {
public interface ControllerConfiguration<R extends CustomResource<?, ?>> {

default String getName() {
return ControllerUtils.getDefaultResourceControllerName(getAssociatedControllerClassName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;

public class ConfiguredController<R extends CustomResource<?, ?>> implements ResourceController<R>,
Stoppable, EventSourceInitializer {
Stoppable, EventSourceInitializer<R> {
private final ResourceController<R> controller;
private final ControllerConfiguration<R> configuration;
private final KubernetesClient kubernetesClient;
private DefaultEventSourceManager eventSourceManager;
private DefaultEventSourceManager<R> eventSourceManager;

public ConfiguredController(ResourceController<R> controller,
ControllerConfiguration<R> configuration,
Expand All @@ -33,7 +33,7 @@ public ConfiguredController(ResourceController<R> controller,
}

@Override
public DeleteControl deleteResource(R resource, Context<R> context) {
public DeleteControl deleteResource(R resource, Context context) {
return configuration.getConfigurationService().getMetrics().timeControllerExecution(
new ControllerExecution<>() {
@Override
Expand All @@ -59,7 +59,7 @@ public DeleteControl execute() {
}

@Override
public UpdateControl<R> createOrUpdateResource(R resource, Context<R> context) {
public UpdateControl<R> createOrUpdateResource(R resource, Context context) {
return configuration.getConfigurationService().getMetrics().timeControllerExecution(
new ControllerExecution<>() {
@Override
Expand Down Expand Up @@ -92,7 +92,7 @@ public UpdateControl<R> execute() {
}

@Override
public void prepareEventSources(EventSourceManager eventSourceManager) {
public void prepareEventSources(EventSourceManager<R> eventSourceManager) {
throw new UnsupportedOperationException("This method should never be called directly");
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public void start() throws OperatorException {
try {
eventSourceManager = new DefaultEventSourceManager<>(this);
if (controller instanceof EventSourceInitializer) {
((EventSourceInitializer) controller).prepareEventSources(eventSourceManager);
((EventSourceInitializer<R>) controller).prepareEventSources(eventSourceManager);
}
} catch (MissingCRDException e) {
throwMissingCRDException(crdName, specVersion, controllerName);
Expand Down Expand Up @@ -208,7 +208,7 @@ private boolean failOnMissingCurrentNS() {
return false;
}

public EventSourceManager getEventSourceManager() {
public EventSourceManager<R> getEventSourceManager() {
return eventSourceManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ private PostExecutionControl<R> handleDispatch(ExecutionScope<R> executionScope)
return PostExecutionControl.defaultDispatch();
}

Context<R> context =
new DefaultContext<>(executionScope.getRetryInfo());
Context context =
new DefaultContext(executionScope.getRetryInfo());
if (markedForDeletion) {
return handleDelete(resource, context);
} else {
Expand All @@ -92,7 +92,7 @@ private boolean shouldNotDispatchToDelete(R resource) {
}

private PostExecutionControl<R> handleCreateOrUpdate(
ExecutionScope<R> executionScope, R resource, Context<R> context) {
ExecutionScope<R> executionScope, R resource, Context context) {
if (configuration().useFinalizer() && !resource.hasFinalizer(configuration().getFinalizer())) {
/*
* We always add the finalizer if missing and the controller is configured to use a finalizer.
Expand Down Expand Up @@ -147,7 +147,7 @@ private void updatePostExecutionControlWithReschedule(
baseControl.getScheduleDelay().ifPresent(postExecutionControl::withReSchedule);
}

private PostExecutionControl<R> handleDelete(R resource, Context<R> context) {
private PostExecutionControl<R> handleDelete(R resource, Context context) {
log.debug(
"Executing delete for resource: {} with version: {}",
getName(resource),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @param <T> the type of custom resources handled by this filter
*/
@FunctionalInterface
public interface CustomResourceEventFilter<T extends CustomResource> {
public interface CustomResourceEventFilter<T extends CustomResource<?, ?>> {

/**
* Determines whether the change between the old version of the resource and the new one needs to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
public final class CustomResourceEventFilters {

private static final CustomResourceEventFilter<CustomResource> USE_FINALIZER =
private static final CustomResourceEventFilter<CustomResource<?, ?>> USE_FINALIZER =
(configuration, oldResource, newResource) -> {
if (configuration.useFinalizer()) {
final var finalizer = configuration.getFinalizer();
Expand All @@ -20,18 +20,18 @@ public final class CustomResourceEventFilters {
}
};

private static final CustomResourceEventFilter<CustomResource> GENERATION_AWARE =
private static final CustomResourceEventFilter<CustomResource<?, ?>> GENERATION_AWARE =
(configuration, oldResource, newResource) -> oldResource == null
|| !configuration.isGenerationAware()
|| oldResource.getMetadata().getGeneration() < newResource.getMetadata().getGeneration();

private static final CustomResourceEventFilter<CustomResource> PASSTHROUGH =
private static final CustomResourceEventFilter<CustomResource<?, ?>> PASSTHROUGH =
(configuration, oldResource, newResource) -> true;

private static final CustomResourceEventFilter<CustomResource> NONE =
private static final CustomResourceEventFilter<CustomResource<?, ?>> NONE =
(configuration, oldResource, newResource) -> false;

private static final CustomResourceEventFilter<CustomResource> MARKED_FOR_DELETION =
private static final CustomResourceEventFilter<CustomResource<?, ?>> MARKED_FOR_DELETION =
(configuration, oldResource, newResource) -> newResource.isMarkedForDeletion();

private CustomResourceEventFilters() {}
Expand All @@ -43,7 +43,7 @@ private CustomResourceEventFilters() {}
* @return a filter that accepts all events
*/
@SuppressWarnings("unchecked")
public static <T extends CustomResource> CustomResourceEventFilter<T> passthrough() {
public static <T extends CustomResource<?, ?>> CustomResourceEventFilter<T> passthrough() {
return (CustomResourceEventFilter<T>) PASSTHROUGH;
}

Expand All @@ -54,7 +54,7 @@ public static <T extends CustomResource> CustomResourceEventFilter<T> passthroug
* @return a filter that reject all events
*/
@SuppressWarnings("unchecked")
public static <T extends CustomResource> CustomResourceEventFilter<T> none() {
public static <T extends CustomResource<?, ?>> CustomResourceEventFilter<T> none() {
return (CustomResourceEventFilter<T>) NONE;
}

Expand All @@ -66,7 +66,7 @@ public static <T extends CustomResource> CustomResourceEventFilter<T> none() {
* @return a filter accepting changes based on generation information
*/
@SuppressWarnings("unchecked")
public static <T extends CustomResource> CustomResourceEventFilter<T> generationAware() {
public static <T extends CustomResource<?, ?>> CustomResourceEventFilter<T> generationAware() {
return (CustomResourceEventFilter<T>) GENERATION_AWARE;
}

Expand All @@ -79,7 +79,7 @@ public static <T extends CustomResource> CustomResourceEventFilter<T> generation
* applied
*/
@SuppressWarnings("unchecked")
public static <T extends CustomResource> CustomResourceEventFilter<T> finalizerNeededAndApplied() {
public static <T extends CustomResource<?, ?>> CustomResourceEventFilter<T> finalizerNeededAndApplied() {
return (CustomResourceEventFilter<T>) USE_FINALIZER;
}

Expand All @@ -90,7 +90,7 @@ public static <T extends CustomResource> CustomResourceEventFilter<T> finalizerN
* @return a filter accepting changes based on whether the Custom Resource is marked for deletion.
*/
@SuppressWarnings("unchecked")
public static <T extends CustomResource> CustomResourceEventFilter<T> markedForDeletion() {
public static <T extends CustomResource<?, ?>> CustomResourceEventFilter<T> markedForDeletion() {
return (CustomResourceEventFilter<T>) MARKED_FOR_DELETION;
}

Expand Down
Loading