Skip to content

Commit 826349b

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

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
@@ -98,7 +98,7 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
9898
if (secondaryResources.isEmpty()) {
9999
return Optional.empty();
100100
} else {
101-
return selectManagedResource(secondaryResources, primary, context);
101+
return selectManagedSecondaryResource(secondaryResources, primary, context);
102102
}
103103
}
104104
}
@@ -115,7 +115,7 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
115115
* @throws IllegalStateException if more than one candidate is found, in which case some other
116116
* mechanism might be necessary to distinguish between candidate secondary resources
117117
*/
118-
protected Optional<R> selectManagedResource(Set<R> secondaryResources, P primary,
118+
protected Optional<R> selectManagedSecondaryResource(Set<R> secondaryResources, P primary,
119119
Context<P> context) {
120120
R desired = desired(primary, context);
121121
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
@@ -291,17 +291,25 @@ protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, Stri
291291
}
292292

293293
@Override
294-
protected Optional<R> selectManagedResource(Set<R> secondaryResources, P primary,
294+
protected Optional<R> selectManagedSecondaryResource(Set<R> secondaryResources, P primary,
295295
Context<P> context) {
296-
ResourceID managedResourceID = managedResourceID(primary, context);
296+
ResourceID managedResourceID = managedSecondaryResourceID(primary, context);
297297
return secondaryResources.stream()
298298
.filter(r -> r.getMetadata().getName().equals(managedResourceID.getName()) &&
299299
Objects.equals(r.getMetadata().getNamespace(),
300300
managedResourceID.getNamespace().orElse(null)))
301301
.findFirst();
302302
}
303303

304-
protected ResourceID managedResourceID(P primary, Context<P> context) {
304+
/**
305+
* Override this method in order to optimize and not compute the desired when selecting the target
306+
* secondary resource. Simply, a static ResourceID can be returned.
307+
*
308+
* @param primary resource
309+
* @param context of current reconciliation
310+
* @return id of the target managed resource
311+
*/
312+
protected ResourceID managedSecondaryResourceID(P primary, Context<P> context) {
305313
return ResourceID.fromResource(desired(primary, context));
306314
}
307315

0 commit comments

Comments
 (0)