Skip to content

Commit ba6106e

Browse files
chore: use formatter-maven-plugin to automatic code formatting (#505)
Fixes #504 Co-authored-by: Chris Laprun <[email protected]>
1 parent 44b42a1 commit ba6106e

File tree

49 files changed

+185
-173
lines changed

Some content is hidden

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

49 files changed

+185
-173
lines changed

.github/workflows/master-snapshot-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
java: [11, 15]
18+
java: [11, 16]
1919
distribution: [adopt, adopt-openj9]
2020
kubernetes: ['v1.17.13','v1.18.20','v1.19.14','v1.20.10','v1.21.4']
2121
steps:

.github/workflows/pr.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
java: [11, 15]
18+
java: [11, 16]
1919
distribution: [ adopt, adopt-openj9 ]
2020
kubernetes: ['v1.17.13','v1.18.20','v1.19.14','v1.20.10','v1.21.4']
2121
steps:
@@ -32,7 +32,7 @@ jobs:
3232
distribution: ${{ matrix.distribution }}
3333
java-version: ${{ matrix.java }}
3434
- name: Check code format
35-
run: ./mvnw ${MAVEN_ARGS} fmt:check --file pom.xml
35+
run: ./mvnw ${MAVEN_ARGS} formatter:validate -Dconfigfile=$PWD/contributing/eclipse-google-style.xml --file pom.xml
3636
- name: Run unit tests
3737
run: ./mvnw ${MAVEN_ARGS} -B test --file pom.xml
3838
- name: Set up Minikube

contributing/eclipse-google-style.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
6666
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
6767
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
68-
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
68+
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
6969
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
7070
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
7171
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_local_variable_annotation" value="true"/>

operator-framework-core/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
</plugins>
5858
</build>
5959

60-
6160
<dependencies>
6261
<dependency>
6362
<groupId>io.fabric8</groupId>

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public <R extends CustomResource> void register(ResourceController<R> controller
124124

125125
/**
126126
* Add a registration requests for the specified controller with this operator, overriding its
127-
* default configuration by the specified one (usually created via {@link
128-
* io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
127+
* default configuration by the specified one (usually created via
128+
* {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
129129
* passing it the controller's original configuration. The effective registration of the
130130
* controller is delayed till the operator is started.
131131
*
@@ -150,8 +150,8 @@ public <R extends CustomResource> void register(
150150

151151
/**
152152
* Registers the specified controller with this operator, overriding its default configuration by
153-
* the specified one (usually created via {@link
154-
* io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
153+
* the specified one (usually created via
154+
* {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
155155
* passing it the controller's original configuration.
156156
*
157157
* @param controller the controller to register
@@ -241,7 +241,7 @@ private void throwMissingCRDException(String crdName, String specVersion, String
241241
* but is missing
242242
*
243243
* @return {@code true} if the current namespace is requested but is missing, {@code false}
244-
* otherwise
244+
* otherwise
245245
*/
246246
private static <R extends CustomResource> boolean failOnMissingCurrentNS(
247247
ControllerConfiguration<R> configuration) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
/**
2828
* If true, will dispatch new event to the controller if generation increased since the last
29-
* processing, otherwise will process all events. See generation meta attribute <a
30-
* href="https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource">here</a>
29+
* processing, otherwise will process all events. See generation meta attribute <a href=
30+
* "https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource">here</a>
3131
*
3232
* @return whether the controller takes generation into account to process events
3333
*/
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.javaoperatorsdk.operator.api;
22

33
public enum DeleteControl {
4-
DEFAULT_DELETE,
5-
NO_FINALIZER_REMOVAL
4+
DEFAULT_DELETE, NO_FINALIZER_REMOVAL
65
}

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

+18-17
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ public interface ResourceController<R extends CustomResource> {
88
/**
99
* The implementation should delete the associated component(s). Note that this is method is
1010
* called when an object is marked for deletion. After it's executed the custom resource finalizer
11-
* is automatically removed by the framework; unless the return value is {@link
12-
* DeleteControl#NO_FINALIZER_REMOVAL}, which indicates that the controller has determined that
13-
* the resource should not be deleted yet, in which case it is up to the controller to restore the
14-
* resource's status so that it's not marked for deletion anymore.
11+
* is automatically removed by the framework; unless the return value is
12+
* {@link DeleteControl#NO_FINALIZER_REMOVAL}, which indicates that the controller has determined
13+
* that the resource should not be deleted yet, in which case it is up to the controller to
14+
* restore the resource's status so that it's not marked for deletion anymore.
1515
*
16-
* <p>It's important that this method be idempotent, as it could be called several times,
17-
* depending on the conditions and the controller's configuration (for example, if the controller
18-
* is configured to not use a finalizer but the resource does have finalizers, it might be be
16+
* <p>
17+
* It's important that this method be idempotent, as it could be called several times, depending
18+
* on the conditions and the controller's configuration (for example, if the controller is
19+
* configured to not use a finalizer but the resource does have finalizers, it might be be
1920
* "offered" again for deletion several times until the finalizers are all removed.
2021
*
2122
* @param resource the resource that is marked for deletion
2223
* @param context the context with which the operation is executed
2324
* @return {@link DeleteControl#DEFAULT_DELETE} - so the finalizer is automatically removed after
24-
* the call. {@link DeleteControl#NO_FINALIZER_REMOVAL} if you don't want to remove the
25-
* finalizer to indicate that the resource should not be deleted after all, in which case the
26-
* controller should restore the resource's state appropriately.
25+
* the call. {@link DeleteControl#NO_FINALIZER_REMOVAL} if you don't want to remove the
26+
* finalizer to indicate that the resource should not be deleted after all, in which case
27+
* the controller should restore the resource's state appropriately.
2728
*/
2829
default DeleteControl deleteResource(R resource, Context<R> context) {
2930
return DeleteControl.DEFAULT_DELETE;
@@ -36,20 +37,20 @@ default DeleteControl deleteResource(R resource, Context<R> context) {
3637
*
3738
* @param resource the resource that has been created or updated
3839
* @param context the context with which the operation is executed
39-
* @return The resource is updated in api server if the return value is not {@link
40-
* UpdateControl#noUpdate()}. This the common use cases. However in cases, for example the
41-
* operator is restarted, and we don't want to have an update call to k8s api to be made
42-
* unnecessarily, by returning {@link UpdateControl#noUpdate()} this update can be skipped.
43-
* <b>However we will always call an update if there is no finalizer on object and it's not
44-
* marked for deletion.</b>
40+
* @return The resource is updated in api server if the return value is not
41+
* {@link UpdateControl#noUpdate()}. This the common use cases. However in cases, for
42+
* example the operator is restarted, and we don't want to have an update call to k8s api
43+
* to be made unnecessarily, by returning {@link UpdateControl#noUpdate()} this update can
44+
* be skipped. <b>However we will always call an update if there is no finalizer on object
45+
* and it's not marked for deletion.</b>
4546
*/
4647
UpdateControl<R> createOrUpdateResource(R resource, Context<R> context);
4748

4849
/**
4950
* In init typically you might want to register event sources.
5051
*
5152
* @param eventSourceManager the {@link EventSourceManager} which handles this controller and with
52-
* which event sources can be registered
53+
* which event sources can be registered
5354
*/
5455
default void init(EventSourceManager eventSourceManager) {}
5556
}

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <R extends CustomResource> ControllerConfiguration<R> getConfigurationFor(
2424
* Retrieves the Kubernetes client configuration
2525
*
2626
* @return the configuration of the Kubernetes client, defaulting to the provided
27-
* auto-configuration
27+
* auto-configuration
2828
*/
2929
default Config getClientConfiguration() {
3030
return Config.autoConfigure(null);
@@ -45,11 +45,13 @@ default Config getClientConfiguration() {
4545
Version getVersion();
4646

4747
/**
48-
* Whether the operator should query the CRD to make sure it's deployed and validate {@link
49-
* CustomResource} implementations before attempting to register the associated controllers.
48+
* Whether the operator should query the CRD to make sure it's deployed and validate
49+
* {@link CustomResource} implementations before attempting to register the associated
50+
* controllers.
5051
*
51-
* <p>Note that this might require elevating the privileges associated with the operator to gain
52-
* read access on the CRD resources.
52+
* <p>
53+
* Note that this might require elevating the privileges associated with the operator to gain read
54+
* access on the CRD resources.
5355
*
5456
* @return {@code true} if CRDs should be checked (default), {@code false} otherwise
5557
*/
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
package io.javaoperatorsdk.operator.api.config;
22

3-
public class DefaultRetryConfiguration implements RetryConfiguration {}
3+
public class DefaultRetryConfiguration implements RetryConfiguration {
4+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public String getCommit() {
3636
/**
3737
* Returns the date at which this SDK instance was built
3838
*
39-
* @return the build time at which this SDK instance was built or the date corresponding to {@link
40-
* java.time.Instant#EPOCH} if the built time couldn't be retrieved
39+
* @return the build time at which this SDK instance was built or the date corresponding to
40+
* {@link java.time.Instant#EPOCH} if the built time couldn't be retrieved
4141
*/
4242
public Date getBuiltTime() {
4343
return builtTime;

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,12 @@ private RetryExecution getOrInitRetryExecution(ExecutionScope executionScope) {
238238
* with a non up to date CR. Here we cache the latest CustomResource from the update execution so
239239
* we make sure its already used in the up-coming execution.
240240
*
241-
* <p>Note that this is an improvement, not a bug fix. This situation can happen naturally, we
242-
* just make the execution more efficient, and avoid questions about conflicts.
241+
* <p>
242+
* Note that this is an improvement, not a bug fix. This situation can happen naturally, we just
243+
* make the execution more efficient, and avoid questions about conflicts.
243244
*
244-
* <p>Note that without the conditional locking in the cache, there is a very minor chance that we
245+
* <p>
246+
* Note that without the conditional locking in the cache, there is a very minor chance that we
245247
* would override an additional change coming from a different client.
246248
*/
247249
private void cacheUpdatedResourceIfChanged(
@@ -259,9 +261,8 @@ private void cacheUpdatedResourceIfChanged(
259261
getVersion(originalCustomResource));
260262
eventSourceManager.cacheResource(
261263
customResourceAfterExecution,
262-
customResource ->
263-
getVersion(customResource).equals(originalResourceVersion)
264-
&& !originalResourceVersion.equals(getVersion(customResourceAfterExecution)));
264+
customResource -> getVersion(customResource).equals(originalResourceVersion)
265+
&& !originalResourceVersion.equals(getVersion(customResourceAfterExecution)));
265266
}
266267
}
267268

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ private PostExecutionControl handleDispatch(ExecutionScope<R> executionScope) {
9393
}
9494

9595
/**
96-
* Determines whether the given resource should be dispatched to the controller's {@link
97-
* ResourceController#deleteResource(CustomResource, Context)} method
96+
* Determines whether the given resource should be dispatched to the controller's
97+
* {@link ResourceController#deleteResource(CustomResource, Context)} method
9898
*
9999
* @param resource the resource to be potentially deleted
100100
* @return {@code true} if the resource should be handed to the controller's {@code
@@ -109,11 +109,12 @@ private boolean shouldNotDispatchToDelete(R resource) {
109109
private PostExecutionControl handleCreateOrUpdate(
110110
ExecutionScope<R> executionScope, R resource, Context<R> context) {
111111
if (configuration.useFinalizer() && !resource.hasFinalizer(configuration.getFinalizer())) {
112-
/* We always add the finalizer if missing and the controller is configured to use a finalizer.
113-
We execute the controller processing only for processing the event sent as a results
114-
of the finalizer add. This will make sure that the resources are not created before
115-
there is a finalizer.
116-
*/
112+
/*
113+
* We always add the finalizer if missing and the controller is configured to use a finalizer.
114+
* We execute the controller processing only for processing the event sent as a results of the
115+
* finalizer add. This will make sure that the resources are not created before there is a
116+
* finalizer.
117+
*/
117118
updateCustomResourceWithFinalizer(resource);
118119
return PostExecutionControl.onlyFinalizerAdded();
119120
} else {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/DefaultEventSourceManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ public void cleanup(String customResourceUid) {
160160
// todo: remove
161161
public CustomResourceCache getCache() {
162162
final var source =
163-
(CustomResourceEventSource)
164-
getRegisteredEventSources().get(CUSTOM_RESOURCE_EVENT_SOURCE_NAME);
163+
(CustomResourceEventSource) getRegisteredEventSources()
164+
.get(CUSTOM_RESOURCE_EVENT_SOURCE_NAME);
165165
return source.getCache();
166166
}
167167

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/Event.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface Event {
77

88
/**
99
* @return the UID of the the {@link CustomResource} for which a reconcile loop should be
10-
* triggered.
10+
* triggered.
1111
* @deprecated use {@link #getCustomResourcesSelector()}
1212
*/
1313
@Deprecated

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public interface EventSource extends Closeable {
1111
default void start() {}
1212

1313
/**
14-
* This method is invoked when this {@link EventSource} instance is de-registered from a {@link
15-
* EventSourceManager}.
14+
* This method is invoked when this {@link EventSource} instance is de-registered from a
15+
* {@link EventSourceManager}.
1616
*/
1717
@Override
1818
default void close() {}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface EventSourceManager extends Closeable {
1313
* @param name the name of the {@link EventSource} to add
1414
* @param eventSource the {@link EventSource} to register
1515
* @throws IllegalStateException if an {@link EventSource} with the same name is already
16-
* registered.
16+
* registered.
1717
* @throws OperatorException if an error occurred during the registration process
1818
*/
1919
void registerEventSource(String name, EventSource eventSource)
@@ -25,7 +25,7 @@ void registerEventSource(String name, EventSource eventSource)
2525
*
2626
* @param name the name of the {@link EventSource} to remove
2727
* @return an optional {@link EventSource} which would be empty if no {@link EventSource} have
28-
* been registered with the given name.
28+
* been registered with the given name.
2929
*/
3030
Optional<EventSource> deRegisterEventSource(String name);
3131

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/CustomResourceSelectorTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public void setup() {
5151
doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResourceUids(any());
5252
doCallRealMethod().when(defaultEventSourceManagerMock).cacheResource(any(), any());
5353
doAnswer(
54-
invocation -> {
55-
final var resourceId = (String) invocation.getArgument(0);
56-
customResourceCache.cleanup(resourceId);
57-
return null;
58-
})
59-
.when(defaultEventSourceManagerMock)
60-
.cleanup(any());
54+
invocation -> {
55+
final var resourceId = (String) invocation.getArgument(0);
56+
customResourceCache.cleanup(resourceId);
57+
return null;
58+
})
59+
.when(defaultEventSourceManagerMock)
60+
.cleanup(any());
6161
}
6262

6363
@Test

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/DefaultEventHandlerTest.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ public void setup() {
7474
doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResourceUids(any());
7575
doCallRealMethod().when(defaultEventSourceManagerMock).cacheResource(any(), any());
7676
doAnswer(
77-
invocation -> {
78-
final var resourceId = (String) invocation.getArgument(0);
79-
customResourceCache.cleanup(resourceId);
80-
return null;
81-
})
82-
.when(defaultEventSourceManagerMock)
83-
.cleanup(any());
77+
invocation -> {
78+
final var resourceId = (String) invocation.getArgument(0);
79+
customResourceCache.cleanup(resourceId);
80+
return null;
81+
})
82+
.when(defaultEventSourceManagerMock)
83+
.cleanup(any());
8484
}
8585

8686
@Test
@@ -239,11 +239,10 @@ private void waitMinimalTime() {
239239
private String eventAlreadyUnderProcessing() {
240240
when(eventDispatcherMock.handleExecution(any()))
241241
.then(
242-
(Answer<PostExecutionControl>)
243-
invocationOnMock -> {
244-
Thread.sleep(FAKE_CONTROLLER_EXECUTION_DURATION);
245-
return PostExecutionControl.defaultDispatch();
246-
});
242+
(Answer<PostExecutionControl>) invocationOnMock -> {
243+
Thread.sleep(FAKE_CONTROLLER_EXECUTION_DURATION);
244+
return PostExecutionControl.defaultDispatch();
245+
});
247246
Event event = prepareCREvent();
248247
defaultEventHandler.handleEvent(event);
249248
return event.getRelatedCustomResourceUid();

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSourceTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
class CustomResourceEventSourceTest {
2121

2222
public static final String FINALIZER = "finalizer";
23-
MixedOperation<
24-
TestCustomResource,
25-
KubernetesResourceList<TestCustomResource>,
26-
Resource<TestCustomResource>>
27-
client = mock(MixedOperation.class);
23+
MixedOperation<TestCustomResource, KubernetesResourceList<TestCustomResource>, Resource<TestCustomResource>> client =
24+
mock(MixedOperation.class);
2825
EventHandler eventHandler = mock(EventHandler.class);
2926

3027
private CustomResourceEventSource<TestCustomResource> customResourceEventSource =

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/internal/TimerEventSourceTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import org.junit.jupiter.api.Test;
2020
import org.mockito.ArgumentCaptor;
2121

22-
@Disabled(
23-
"Currently very flaky, will fix in https://github.com/java-operator-sdk/java-operator-sdk/issues/293")
22+
@Disabled("Currently very flaky, will fix in https://github.com/java-operator-sdk/java-operator-sdk/issues/293")
2423
class TimerEventSourceTest {
2524

2625
public static final int INITIAL_DELAY = 50;

0 commit comments

Comments
 (0)