8000 refactor: fix generics and minor clean-ups (#636) · Sgitario/java-operator-sdk@7fec740 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fec740

Browse files
authored
refactor: fix generics and minor clean-ups (operator-framework#636)
1 parent cbfd993 commit 7fec740

File tree

44 files changed

+174
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+174
-176
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.javaoperatorsdk.operator.api.Controller;
66
import io.javaoperatorsdk.operator.api.ResourceController;
77

8+
@SuppressWarnings("rawtypes")
89
public class ControllerUtils {
910

1011
private static final String FINALIZER_NAME_SUFFIX = "/finalizer";

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void close() {
114114
* @param <R> the {@code CustomResource} type associated with the controller
115115
* @throws OperatorException if a problem occurred during the registration process
116116
*/
117-
public <R extends CustomResource> void register(ResourceController<R> controller)
117+
public <R extends CustomResource<?, ?>> void register(ResourceController<R> controller)
118118
throws OperatorException {
119119
register(controller, null);
120120
}
@@ -132,7 +132,7 @@ public <R extends CustomResource> void register(ResourceController<R> controller
132132
* @param <R> the {@code CustomResource} type associated with the controller
133133
* @throws OperatorException if a problem occurred during the registration process
134134
*/
135-
public <R extends CustomResource> void register(
135+
public <R extends CustomResource<?, ?>> void register(
136136
ResourceController<R> controller, ControllerConfiguration<R> configuration)
137137
throws OperatorException {
138138
final var existing = configurationService.getConfigurationFor(controller);
@@ -148,7 +148,7 @@ public <R extends CustomResource> void register(
148148
configuration = existing;
149149
}
150150
final var configuredController =
151-
new ConfiguredController(controller, configuration, kubernetesClient);
151+
new ConfiguredController<>(controller, configuration, kubernetesClient);
152152
controllers.add(configuredController);
153153

154154
final var watchedNS =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Optional;
44
import java.util.concurrent.TimeUnit;
55

6-
public abstract class BaseControl<T extends BaseControl> {
6+
public abstract class BaseControl<T extends BaseControl<T>> {
77

88
private Long scheduleDelay = null;
99

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import java.util.Optional;
44

5-
import io.fabric8.kubernetes.client.CustomResource;
6-
7-
public interface Context<T extends CustomResource> {
5+
public interface Context {
86

97
Optional<RetryInfo> getRetryInfo();
108

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import java.util.Optional;
44

5-
import io.fabric8.kubernetes.client.CustomResource;
6-
7-
public class DefaultContext<T extends CustomResource> implements Context<T> {
5+
public class DefaultContext implements Context {
86

97
private final RetryInfo retryInfo;
108

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public boolean isRemoveFinalizer() {
2222

2323
@Override
2424
public DeleteControl rescheduleAfter(long delay) {
25-
if (removeFinalizer == true) {
25+
if (removeFinalizer) {
2626
throw new IllegalStateException("Cannot reschedule deleteResource if removing finalizer");
2727
}
2828
return super.rescheduleAfter(delay);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io.fabric8.kubernetes.client.CustomResource;
44

5-
public interface ResourceController<R extends CustomResource> {
5+
public interface ResourceController<R extends CustomResource<?, ?>> {
66

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

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

5151
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.fabric8.kubernetes.client.CustomResource;
44

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

78
private final T customResource;
@@ -30,16 +31,16 @@ public static <T extends CustomResource> UpdateControl<T> updateStatusSubResourc
3031
/**
3132
* As a results of this there will be two call to K8S API. First the custom resource will be
3233
* updates then the status sub-resource.
33-
*
34+
*
3435
* @param customResource - custom resource to use in both API calls
3536
* @return UpdateControl instance
3637
*/
37-
public static <T extends CustomResource> UpdateControl<T> updateCustomResourceAndStatus(
38+
public static <T extends CustomResource<?, ?>> UpdateControl<T> updateCustomResourceAndStatus(
3839
T customResource) {
3940
return new UpdateControl<>(customResource, true, true);
4041
}
4142

42-
public static <T extends CustomResource> UpdateControl<T> noUpdate() {
43+
public static <T extends CustomResource<?, ?>> UpdateControl<T> noUpdate() {
4344
return new UpdateControl<>(null, false, false);
4445
}
4546

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.javaoperatorsdk.operator.ControllerUtils;
1010
import io.javaoperatorsdk.operator.api.ResourceController;
1111

12+
@SuppressWarnings("rawtypes")
1213
public class AbstractConfigurationService implements ConfigurationService {
1314
private final Map<String, ControllerConfiguration> configurations = new ConcurrentHashMap<>();
1415
private final Version version;
@@ -17,15 +18,15 @@ public AbstractConfigurationService(Version version) {
1718
this.version = version;
1819
}
1920

20-
protected <R extends CustomResource> void register(ControllerConfiguration<R> config) {
21+
protected <R extends CustomResource<?, ?>> void register(ControllerConfiguration<R> config) {
2122
put(config, true);
2223
}
2324

24-
protected <R extends CustomResource> void replace(ControllerConfiguration<R> config) {
25+
protected <R extends CustomResource<?, ?>> void replace(ControllerConfiguration<R> config) {
2526
put(config, false);
2627
}
2728

28-
private <R extends CustomResource> void put(
29+
private <R extends CustomResource<?, ?>> void put(
2930
ControllerConfiguration<R> config, boolean failIfExisting) {
3031
final var name = config.getName();
3132
if (failIfExisting) {
@@ -38,8 +39,8 @@ private <R extends CustomResource> void put(
3839
config.setConfigurationService(this);
3940
}
4041

41-
protected void throwExceptionOnNameCollision(
42-
String newControllerClassName, ControllerConfiguration existing) {
42+
protected <R extends CustomResource<?, ?>> void throwExceptionOnNameCollision(
43+
String newControllerClassName, ControllerConfiguration<R> existing) {
4344
throw new IllegalArgumentException(
4445
"Controller name '"
4546
+ existing.getName()
@@ -50,7 +51,7 @@ protected void throwExceptionOnNameCollision(
5051
}
5152

5253
@Override
53-
public <R extends CustomResource> ControllerConfiguration<R> getConfigurationFor(
54+
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
5455
ResourceController<R> controller) {
5556
final var key = keyFor(controller);
5657
final var configuration = configurations.get(key);
@@ -72,7 +73,7 @@ private String getControllersNameMessage() {
7273
+ ".";
7374
}
7475

75-
protected String keyFor(ResourceController controller) {
76+
protected <R extends CustomResource<?, ?>> String keyFor(ResourceController<R> controller) {
7677
return ControllerUtils.getNameFor(controller);
7778
}
7879

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public interface ConfigurationService {
3434
* @param controller the controller we want the configuration of
3535
* @param <R> the {@code CustomResource} type associated with the specified controller
3636
* @return the {@link ControllerConfiguration} associated with the specified controller or {@code
37-
* null} if no configuration exists for the controller
37+
* null} if no configuration exists for the controller
3838
*/
39-
<R extends CustomResource> ControllerConfiguration<R> getConfigurationFor(
39+
<R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
4040
ResourceController<R> controller);
4141

4242
/**

0 commit comments

Comments
 (0)
0