Skip to content

Commit 63b6909

Browse files
committed
wip
Signed-off-by: Attila Mészáros <[email protected]>
1 parent b496832 commit 63b6909

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class ExpectationManager<P extends HasMetadata> {
1313

14-
private final ConcurrentHashMap<ResourceID, RegisteredExpectation<P>> registeredExpectations =
14+
protected final ConcurrentHashMap<ResourceID, RegisteredExpectation<P>> registeredExpectations =
1515
new ConcurrentHashMap<>();
1616

1717
public void setExpectation(P primary, Expectation<P> expectation, Duration timeout) {
@@ -53,6 +53,10 @@ public Optional<Expectation<P>> getExpectation(P primary) {
5353
return Optional.ofNullable(regExp).map(RegisteredExpectation::expectation);
5454
}
5555

56+
public Optional<String> getExpectationName(P primary) {
57+
return getExpectation(primary).map(Expectation::name);
58+
}
59+
5660
public void cleanup(P primary) {
5761
registeredExpectations.remove(ResourceID.fromResource(primary));
5862
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ public boolean isFulfilled() {
1212
public boolean isTimedOut() {
1313
return status == ExpectationStatus.TIMED_OUT;
1414
}
15+
16+
public String name() {
17+
return expectation.name();
18+
}
1519
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.javaoperatorsdk.operator.processing.expectation;
2+
3+
import java.time.Duration;
4+
import java.time.LocalDateTime;
5+
6+
import io.fabric8.kubernetes.api.model.HasMetadata;
7+
import io.javaoperatorsdk.operator.api.reconciler.IndexedResourceCache;
8+
9+
public class PeriodicCleanerExpectationManager<P extends HasMetadata>
10+
extends ExpectationManager<P> {
11+
12+
private final Duration cleanupDelayAfterExpiration;
13+
private final IndexedResourceCache<P> primaryCache;
14+
15+
// todo fixes schedule
16+
public PeriodicCleanerExpectationManager(Duration period, Duration cleanupDelayAfterExpiration) {
17+
this.cleanupDelayAfterExpiration = cleanupDelayAfterExpiration;
18+
this.primaryCache = null;
19+
}
20+
21+
public PeriodicCleanerExpectationManager(Duration period, IndexedResourceCache<P> primaryCache) {
22+
this.cleanupDelayAfterExpiration = null;
23+
this.primaryCache = primaryCache;
24+
}
25+
26+
public void clean() {
27+
registeredExpectations
28+
.entrySet()
29+
.removeIf(
30+
e -> {
31+
if (cleanupDelayAfterExpiration != null) {
32+
return LocalDateTime.now()
33+
.isAfter(
34+
e.getValue()
35+
.registeredAt()
36+
.plus(e.getValue().timeout())
37+
.plus(cleanupDelayAfterExpiration));
38+
} else {
39+
return primaryCache.get(e.getKey()).isEmpty();
40+
}
41+
});
42+
}
43+
}

0 commit comments

Comments
 (0)