Skip to content

Commit e6b565a

Browse files
committed
feat: allow transform resource before caching in TemporaryResoureCache
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 6396b48 commit e6b565a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryResourceCache.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Optional;
2121
import java.util.concurrent.ConcurrentHashMap;
22+
import java.util.function.UnaryOperator;
2223

2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
@@ -60,6 +61,7 @@ public class TemporaryResourceCache<T extends HasMetadata> {
6061
private String latestResourceVersion;
6162

6263
private final Map<ResourceID, EventFilterDetails> activeUpdates = new HashMap<>();
64+
private final UnaryOperator<T> transformationFunction;
6365

6466
public enum EventHandling {
6567
DEFER,
@@ -68,7 +70,13 @@ public enum EventHandling {
6870
}
6971

7072
public TemporaryResourceCache(boolean comparableResourceVersions) {
73+
this(comparableResourceVersions, t -> t);
74+
}
75+
76+
public TemporaryResourceCache(
77+
boolean comparableResourceVersions, UnaryOperator<T> transformationFunction) {
7178
this.comparableResourceVersions = comparableResourceVersions;
79+
this.transformationFunction = transformationFunction;
7280
}
7381

7482
public synchronized void startEventFilteringModify(ResourceID resourceID) {
@@ -204,7 +212,7 @@ public synchronized void putResource(T newResource) {
204212
"Temporarily moving ahead to target version {} for resource id: {}",
205213
newResource.getMetadata().getResourceVersion(),
206214
resourceId);
207-
cache.put(resourceId, newResource);
215+
cache.put(resourceId, transformationFunction.apply(newResource));
208216
}
209217
}
210218

0 commit comments

Comments
 (0)