Skip to content

Commit 97b5204

Browse files
committed
- code quality improvements
1 parent a787eb0 commit 97b5204

File tree

12 files changed

+15
-19
lines changed

12 files changed

+15
-19
lines changed

operator-framework/src/main/java/com/github/containersolutions/operator/Operator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.containersolutions.operator;
22

3-
import com.github.containersolutions.operator.api.Controller;
43
import com.github.containersolutions.operator.api.ResourceController;
54
import com.github.containersolutions.operator.processing.EventDispatcher;
65
import com.github.containersolutions.operator.processing.EventScheduler;
@@ -61,7 +60,7 @@ private <R extends CustomResource> void registerController(ResourceController<R>
6160
MixedOperation client = k8sClient.customResources(crd, resClass, CustomResourceList.class, getCustomResourceDoneableClass(controller));
6261
EventDispatcher eventDispatcher = new EventDispatcher(controller,
6362
finalizer, new EventDispatcher.CustomResourceFacade(client), ControllerUtils.getGenerationEventProcessing(controller));
64-
EventScheduler eventScheduler = new EventScheduler(eventDispatcher, retry, finalizer);
63+
EventScheduler eventScheduler = new EventScheduler(eventDispatcher, retry);
6564
registerWatches(controller, client, resClass, watchAllNamespaces, targetNamespaces, eventScheduler);
6665
}
6766

operator-framework/src/main/java/com/github/containersolutions/operator/api/Controller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
* See generation meta attribute
2626
* <a href="https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource">here</a>
2727
*/
28-
boolean generationAwareEventProcessing() default false;
28+
boolean generationAwareEventProcessing() default true;
2929
}

operator-framework/src/main/java/com/github/containersolutions/operator/processing/EventDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private void updateCustomResource(CustomResource updatedResource) {
114114

115115

116116
private void removeDefaultFinalizer(CustomResource resource) {
117-
log.debug("Removing finalizer on {}: {}", resource);
117+
log.debug("Removing finalizer on resource {}:", resource);
118118
resource.getMetadata().getFinalizers().remove(resourceDefaultFinalizer);
119119
customResourceFacade.replaceWithLock(resource);
120120
}

operator-framework/src/main/java/com/github/containersolutions/operator/processing/EventScheduler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ public class EventScheduler implements Watcher<CustomResource> {
4040
private final ScheduledThreadPoolExecutor executor;
4141
private final EventStore eventStore = new EventStore();
4242
private final Retry retry;
43-
private final String finalizer;
4443

4544
private ReentrantLock lock = new ReentrantLock();
4645

47-
public EventScheduler(EventDispatcher eventDispatcher, Retry retry, String finalizer) {
46+
public EventScheduler(EventDispatcher eventDispatcher, Retry retry) {
4847
this.eventDispatcher = eventDispatcher;
4948
this.retry = retry;
50-
this.finalizer = finalizer;
5149
executor = new ScheduledThreadPoolExecutor(1);
5250
executor.setRemoveOnCancelPolicy(true);
5351
}

operator-framework/src/main/java/com/github/containersolutions/operator/processing/retry/GenericRetryExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public GenericRetryExecution(GenericRetry genericRetry) {
2121
public Optional<Long> nextDelay() {
2222
if (lastAttemptIndex == 0) {
2323
lastAttemptIndex++;
24-
return Optional.of(0l);
24+
return Optional.of(0L);
2525
}
2626
if (genericRetry.getMaxAttempts() > -1 && lastAttemptIndex >= genericRetry.getMaxAttempts()) {
2727
return Optional.empty();

operator-framework/src/test/java/com/github/containersolutions/operator/ControllerExecutionIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void retryConflict() {
6565
integrationTestSupport.teardownIfSuccess(() -> {
6666
TestCustomResource resource = testCustomResource();
6767
TestCustomResource resource2 = testCustomResource();
68-
resource2.getMetadata().getAnnotations().put("testannotation", "val");
68+
resource2.getMetadata().getAnnotations().put("test-annotation", "val");
6969

7070
integrationTestSupport.getCrOperations().inNamespace(TEST_NAMESPACE).create(resource);
7171
integrationTestSupport.getCrOperations().inNamespace(TEST_NAMESPACE).createOrReplace(resource2);
@@ -77,7 +77,7 @@ public void retryConflict() {
7777

7878

7979
void awaitResourcesCreatedOrUpdated() {
80-
await("configmap created").atMost(5, TimeUnit.SECONDS)
80+
await("config map created").atMost(5, TimeUnit.SECONDS)
8181
.untilAsserted(() -> {
8282
ConfigMap configMap = integrationTestSupport.getK8sClient().configMaps().inNamespace(TEST_NAMESPACE)
8383
.withName("test-config-map").get();

operator-framework/src/test/java/com/github/containersolutions/operator/EventSchedulerTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.containersolutions.operator;
22

3-
import com.github.containersolutions.operator.api.Controller;
43
import com.github.containersolutions.operator.processing.CustomResourceEvent;
54
import com.github.containersolutions.operator.processing.EventDispatcher;
65
import com.github.containersolutions.operator.processing.EventScheduler;
@@ -33,7 +32,6 @@ class EventSchedulerTest {
3332

3433
public static final int INVOCATION_DURATION = 80;
3534
public static final int MAX_RETRY_ATTEMPTS = 3;
36-
public static final String finalizer = Controller.DEFAULT_FINALIZER;
3735
@SuppressWarnings("unchecked")
3836
private EventDispatcher eventDispatcher = mock(EventDispatcher.class);
3937

@@ -210,7 +208,7 @@ private Object normalExecution(InvocationOnMock invocation) {
210208

211209

212210
private EventScheduler initScheduler() {
213-
return new EventScheduler(eventDispatcher, new GenericRetry().setMaxAttempts(MAX_RETRY_ATTEMPTS).withLinearRetry(), finalizer);
211+
return new EventScheduler(eventDispatcher, new GenericRetry().setMaxAttempts(MAX_RETRY_ATTEMPTS).withLinearRetry());
214212
}
215213

216214
private Object exceptionInExecution(InvocationOnMock invocation) {

operator-framework/src/test/java/com/github/containersolutions/operator/sample/TestCustomResourceController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
import java.time.LocalDateTime;
1615
import java.util.HashMap;
1716
import java.util.Map;
1817
import java.util.concurrent.atomic.AtomicInteger;
1918

2019
@Controller(
20+
generationAwareEventProcessing = false,
2121
crdName = TestCustomResourceController.CRD_NAME,
2222
customResourceClass = TestCustomResource.class)
2323
public class TestCustomResourceController implements ResourceController<TestCustomResource>, TestExecutionInfoProvider {

operator-framework/src/test/java/com/github/containersolutions/operator/sample/subresource/SubResourceTestCustomResourceController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
@Controller(
1414
crdName = SubResourceTestCustomResourceController.CRD_NAME,
15-
customResourceClass = SubResourceTestCustomResource.class)
15+
customResourceClass = SubResourceTestCustomResource.class,
16+
generationAwareEventProcessing = false)
1617
public class SubResourceTestCustomResourceController implements ResourceController<SubResourceTestCustomResource>,
1718
TestExecutionInfoProvider {
1819

samples/common/src/main/java/com/github/containersolutions/operator/sample/CustomServiceController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.slf4j.LoggerFactory;
1212

1313
import java.util.Arrays;
14+
import java.util.Collections;
1415

1516
/**
1617
* A very simple sample controller that creates a service with a label.
@@ -43,7 +44,7 @@ public UpdateControl<CustomService> createOrUpdateResource(CustomService resourc
4344
ServicePort servicePort = new ServicePort();
4445
servicePort.setPort(8080);
4546
ServiceSpec serviceSpec = new ServiceSpec();
46-
serviceSpec.setPorts(Arrays.asList(servicePort));
47+
serviceSpec.setPorts(Collections.singletonList(servicePort));
4748

4849
kubernetesClient.services().inNamespace(resource.getMetadata().getNamespace()).createOrReplaceWithNew()
4950
.withNewMetadata()

0 commit comments

Comments
 (0)