Skip to content

Commit c33a831

Browse files
committed
docs, improvements
Signed-off-by: Attila Mészáros <csviri@gmail.com>
1 parent a516e76 commit c33a831

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
106106
if (secondaryResources.isEmpty()) {
107107
return Optional.empty();
108108
} else {
109-
return selectManagedResource(secondaryResources, primary, context);
109+
return selectManagedSecondaryResource(secondaryResources, primary, context);
110110
}
111111
}
112112
}
@@ -123,7 +123,7 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
123123
* @throws IllegalStateException if more than one candidate is found, in which case some other
124124
* mechanism might be necessary to distinguish between candidate secondary resources
125125
*/
126-
protected Optional<R> selectManagedResource(Set<R> secondaryResources, P primary,
126+
protected Optional<R> selectManagedSecondaryResource(Set<R> secondaryResources, P primary,
127127
Context<P> context) {
128128
R desired = desired(primary, context);
129129
var targetResources =

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,25 @@ protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, Stri
296296
}
297297

298298
@Override
299-
protected Optional<R> selectManagedResource(Set<R> secondaryResources, P primary,
299+
protected Optional<R> selectManagedSecondaryResource(Set<R> secondaryResources, P primary,
300300
Context<P> context) {
301-
ResourceID managedResourceID = managedResourceID(primary, context);
301+
ResourceID managedResourceID = managedSecondaryResourceID(primary, context);
302302
return secondaryResources.stream()
303303
.filter(r -> r.getMetadata().getName().equals(managedResourceID.getName()) &&
304304
Objects.equals(r.getMetadata().getNamespace(),
305305
managedResourceID.getNamespace().orElse(null)))
306306
.findFirst();
307307
}
308308

309-
protected ResourceID managedResourceID(P primary, Context<P> context) {
309+
/**
310+
* Override this method in order to optimize and not compute the desired when selecting the target
311+
* secondary resource. Simply, a static ResourceID can be returned.
312+
*
313+
* @param primary resource
314+
* @param context of current reconciliation
315+
* @return id of the target managed resource
316+
*/
317+
protected ResourceID managedSecondaryResourceID(P primary, Context<P> context) {
310318
return ResourceID.fromResource(desired(primary, context));
311319
}
312320

0 commit comments

Comments
 (0)