Skip to content

Commit 6802574

Browse files
committed
Merge branch 'master' of github.com:ContainerSolutions/java-operator-sdk into int-test-improvement
2 parents 33daf67 + 8d04be4 commit 6802574

File tree

7 files changed

+74
-48
lines changed

7 files changed

+74
-48
lines changed

.github/main.workflow

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Java CI with Maven
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
java: [8, 11]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up JDK
23+
uses: actions/setup-java@v1
24+
with:
25+
java-version: ${{ matrix.java }}
26+
- name: Build with Maven
27+
run: mvn -B package -P no-integration-tests --file pom.xml

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# java-operator-sdk
22
[![Build Status](https://travis-ci.org/ContainerSolutions/java-operator-sdk.svg?branch=master)](https://travis-ci.org/ContainerSolutions/java-operator-sdk)
3+
![Java CI with Maven](https://github.com/ContainerSolutions/java-operator-sdk/workflows/Java%20CI%20with%20Maven/badge.svg)
34

45
SDK for building Kubernetes Operators in Java. Inspired by [operator-sdk](https://github.com/operator-framework/operator-sdk).
56
In this first iteration we aim to provide a framework which handles the reconciliation loop by dispatching events to
@@ -13,7 +14,7 @@ Feature we would like to implement and invite the community to help us implement
1314

1415
* ~~Spring Boot sample~~
1516
* Class generation from CRD to POJO
16-
* Quarkus support
17+
* GraalVM / Quarkus support
1718

1819
## Additional Features
1920

operator-framework/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
</build>
3232

3333
<dependencies>
34-
<dependency>
35-
<groupId>com.google.guava</groupId>
36-
<artifactId>guava</artifactId>
37-
</dependency>
3834
<dependency>
3935
<groupId>io.fabric8</groupId>
4036
<artifactId>openshift-client</artifactId>

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

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

33

44
import com.github.containersolutions.operator.processing.retry.Retry;
5-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
65
import io.fabric8.kubernetes.client.CustomResource;
76
import io.fabric8.kubernetes.client.KubernetesClientException;
87
import io.fabric8.kubernetes.client.Watcher;
@@ -11,7 +10,6 @@
1110

1211
import java.util.Optional;
1312
import java.util.concurrent.ScheduledThreadPoolExecutor;
14-
import java.util.concurrent.ThreadFactory;
1513
import java.util.concurrent.TimeUnit;
1614
import java.util.concurrent.locks.ReentrantLock;
1715

@@ -32,12 +30,6 @@
3230
* <li>Threading approach thus thread pool size and/or implementation should be configurable</li>
3331
* </ul>
3432
* <p>
35-
* Notes:
36-
* <ul>
37-
* <li> In implementation we have to lock since the fabric8 client event handling is multi-threaded, we can receive multiple events
38-
* for same resource. Also we do callback from other threads.
39-
* </li>
40-
* </ul>
4133
*/
4234

4335
public class EventScheduler implements Watcher<CustomResource> {
@@ -54,11 +46,7 @@ public class EventScheduler implements Watcher<CustomResource> {
5446
public EventScheduler(EventDispatcher eventDispatcher, Retry retry) {
5547
this.eventDispatcher = eventDispatcher;
5648
this.retry = retry;
57-
ThreadFactory threadFactory = new ThreadFactoryBuilder()
58-
.setNameFormat("event-consumer-%d")
59-
.setDaemon(false)
60-
.build();
61-
executor = new ScheduledThreadPoolExecutor(1, threadFactory);
49+
executor = new ScheduledThreadPoolExecutor(1);
6250
executor.setRemoveOnCancelPolicy(true);
6351
}
6452

@@ -67,14 +55,13 @@ public void eventReceived(Watcher.Action action, CustomResource resource) {
6755
log.debug("Event received for action: {}, {}: {}", action.toString().toLowerCase(), resource.getClass().getSimpleName(),
6856
resource.getMetadata().getName());
6957
CustomResourceEvent event = new CustomResourceEvent(action, resource, retry);
70-
scheduleEvent(event);
58+
scheduleEventFromApi(event);
7159
}
7260

73-
void scheduleEvent(CustomResourceEvent event) {
74-
log.trace("Current queue size {}", executor.getQueue().size());
75-
log.debug("Scheduling event: {}", event);
61+
void scheduleEventFromApi(CustomResourceEvent event) {
7662
try {
7763
lock.lock();
64+
log.debug("Scheduling event from Api: {}", event);
7865
if (event.getResource().getMetadata().getDeletionTimestamp() != null && event.getAction() == Action.DELETED) {
7966
// Note that we always use finalizers, we want to process delete event just in corner case,
8067
// when we are not able to add finalizer (lets say because of optimistic locking error, and the resource was deleted instantly).
@@ -95,30 +82,39 @@ void scheduleEvent(CustomResourceEvent event) {
9582
eventStore.addOrReplaceEventAsNotScheduled(event);
9683
return;
9784
}
85+
scheduleEventForExecution(event);
86+
log.trace("Scheduling event from API finished: {}", event);
87+
} finally {
88+
lock.unlock();
89+
}
90+
}
9891

92+
private void scheduleEventForExecution(CustomResourceEvent event) {
93+
try {
94+
lock.lock();
95+
log.trace("Current queue size {}", executor.getQueue().size());
96+
log.debug("Scheduling event for execution: {}", event);
9997
Optional<Long> nextBackOff = event.nextBackOff();
10098
if (!nextBackOff.isPresent()) {
10199
log.warn("Event max retry limit reached. Will be discarded. {}", event);
102100
return;
103101
}
104-
log.debug("Creating scheduled task for event: {}", event);
105102
eventStore.addEventUnderProcessing(event);
106103
executor.schedule(new EventConsumer(event, eventDispatcher, this),
107104
nextBackOff.get(), TimeUnit.MILLISECONDS);
105+
log.trace("Scheduled task for event: {}", event);
108106
} finally {
109-
log.debug("Scheduling event finished: {}", event);
110107
lock.unlock();
111108
}
112109
}
113110

114111
void eventProcessingFinishedSuccessfully(CustomResourceEvent event) {
115112
try {
116113
lock.lock();
117-
log.debug("Event processing successful for event: {}", event);
118114
eventStore.removeEventUnderProcessing(event.resourceUid());
119115
if (eventStore.containsNotScheduledEvent(event.resourceUid())) {
120-
log.debug("Scheduling recent event for processing processing: {}", event);
121-
scheduleEvent(eventStore.removeEventNotScheduled(event.resourceUid()));
116+
log.debug("Scheduling recent event for processing: {}", event);
117+
scheduleNotYetScheduledEventForExecution(event.resourceUid());
122118
}
123119
} finally {
124120
lock.unlock();
@@ -130,19 +126,22 @@ void eventProcessingFailed(CustomResourceEvent event) {
130126
lock.lock();
131127
eventStore.removeEventUnderProcessing(event.resourceUid());
132128
if (eventStore.containsNotScheduledEvent(event.resourceUid())) {
133-
CustomResourceEvent notScheduledEvent = eventStore.removeEventNotScheduled(event.resourceUid());
134-
log.debug("Event processing failed. Scheduling the most recent event. Failed event: {}," +
135-
" Most recent event: {}", event, notScheduledEvent);
136-
scheduleEvent(notScheduledEvent);
129+
log.debug("Event processing failed. Scheduling the most recent event. Failed event: {}", event);
130+
scheduleNotYetScheduledEventForExecution(event.resourceUid());
137131
} else {
138132
log.debug("Event processing failed. Attempting to re-schedule the event: {}", event);
139-
scheduleEvent(event);
133+
scheduleEventForExecution(event);
140134
}
141135
} finally {
142136
lock.unlock();
143137
}
144138
}
145139

140+
private void scheduleNotYetScheduledEventForExecution(String uuid) {
141+
CustomResourceEvent notScheduledEvent = eventStore.removeEventNotScheduled(uuid);
142+
scheduleEventForExecution(notScheduledEvent);
143+
}
144+
146145
@Override
147146
public void onClose(KubernetesClientException e) {
148147
log.error("Error: ", e);

pom.xml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141

4242
<dependencyManagement>
4343
<dependencies>
44-
<dependency>
45-
<groupId>com.google.guava</groupId>
46-
<artifactId>guava</artifactId>
47-
<version>28.1-jre</version>
48-
</dependency>
4944
<dependency>
5045
<groupId>io.fabric8</groupId>
5146
<artifactId>openshift-client</artifactId>
@@ -104,14 +99,31 @@
10499
</build>
105100

106101
<profiles>
102+
<profile>
103+
<id>no-integration-tests</id>
104+
<build>
105+
<plugins>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-surefire-plugin</artifactId>
109+
<version>2.22.2</version>
110+
<configuration>
111+
<excludes>
112+
<exclude>**/*IT.java</exclude>
113+
</excludes>
114+
</configuration>
115+
</plugin>
116+
</plugins>
117+
</build>
118+
</profile>
107119
<profile>
108120
<id>release</id>
109121
<build>
110122
<plugins>
111123
<plugin>
112124
<groupId>org.apache.maven.plugins</groupId>
113125
<artifactId>maven-surefire-plugin</artifactId>
114-
<!--<version>2.19.1</version> -->
126+
<version>2.22.2</version>
115127
<configuration>
116128
<excludes>
117129
<exclude>**/*IT.java</exclude>

samples/basic/spring-boot/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<plugin>
5656
<groupId>org.springframework.boot</groupId>
5757
<artifactId>spring-boot-maven-plugin</artifactId>
58+
<version>2.2.6.RELEASE</version>
5859
</plugin>
5960
</plugins>
6061
</build>

0 commit comments

Comments
 (0)