Skip to content

Commit 4d274b4

Browse files
committed
wip
1 parent c295061 commit 4d274b4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
import io.javaoperatorsdk.operator.processing.event.ResourceID;
2020
import io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource;
2121

22-
/** Provides id for the target resource. */
22+
/**
23+
* Provides id for the target resource. This mapper is used across multiple component of the
24+
* framework, like the {@link
25+
* io.javaoperatorsdk.operator.processing.dependent.AbstractExternalDependentResource}, in {@link
26+
* ExternalResourceCachingEventSource}, and {@link
27+
* io.javaoperatorsdk.operator.processing.dependent.KubernetesBulkDependentResource}.
28+
*/
2329
public interface ResourceIDMapper<R, ID> {
2430

2531
ID idFor(R resource);
@@ -29,7 +35,7 @@ public interface ResourceIDMapper<R, ID> {
2935
* String. See also docs for: {@link ExternalResourceCachingEventSource}
3036
*
3137
* @return static id mapper, all resources are mapped for same id.
32-
* @param <T> secondary resource type
38+
* @param <R> secondary resource type
3339
*/
3440
static <R> ResourceIDMapper<R, String> singleResourceCacheKeyMapper() {
3541
return r -> "id";

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,21 @@
2626
import io.javaoperatorsdk.operator.processing.ResourceIDMapper;
2727
import io.javaoperatorsdk.operator.processing.event.ResourceID;
2828

29+
/**
30+
* A narrowed interface for bulk dependent resources for Kubernetes resources, that assumes that the
31+
* ID is a {@link ResourceID}. Note that you are not limited to this when dealing with Kubernetes
32+
* resources you can still choose a different ID type and directly implement {@link
33+
* BulkDependentResource}.
34+
*/
2935
public interface KubernetesBulkDependentResource<R extends HasMetadata, P extends HasMetadata>
3036
extends BulkDependentResource<R, P, ResourceID>, DependentResource<R, P> {
3137

38+
/**
39+
* Since we can list all the related resources and by assuming the ID is type of {@link
40+
* ResourceID} it is trivial to create the target map. The only issue is if there are other
41+
* secondary resources of the target type which are not managed by this bulk dependent resources,
42+
* for those it is enough to override secondaryResourceFilter method.
43+
*/
3244
@Override
3345
default Map<ResourceID, R> getSecondaryResources(P primary, Context<P> context) {
3446
return context
@@ -40,6 +52,10 @@ default Map<ResourceID, R> getSecondaryResources(P primary, Context<P> context)
4052
Function.identity()));
4153
}
4254

55+
/**
56+
* Override if not all the secondary resources of target type are managed by the bulk dependent
57+
* resource.
58+
*/
4359
default Predicate<R> secondaryResourceFilter(P primary, Context<P> context) {
4460
return r -> true;
4561
}

0 commit comments

Comments
 (0)