Skip to content

Commit

Permalink
docs, improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <csviri@gmail.com>
  • Loading branch information
csviri committed Mar 1, 2024
1 parent 3dfbd8f commit 826349b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
if (secondaryResources.isEmpty()) {
return Optional.empty();
} else {
return selectManagedResource(secondaryResources, primary, context);
return selectManagedSecondaryResource(secondaryResources, primary, context);
}
}
}
Expand All @@ -115,7 +115,7 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
* @throws IllegalStateException if more than one candidate is found, in which case some other
* mechanism might be necessary to distinguish between candidate secondary resources
*/
protected Optional<R> selectManagedResource(Set<R> secondaryResources, P primary,
protected Optional<R> selectManagedSecondaryResource(Set<R> secondaryResources, P primary,
Context<P> context) {
R desired = desired(primary, context);
var targetResources =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,25 @@ protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, Stri
}

@Override
protected Optional<R> selectManagedResource(Set<R> secondaryResources, P primary,
protected Optional<R> selectManagedSecondaryResource(Set<R> secondaryResources, P primary,
Context<P> context) {
ResourceID managedResourceID = managedResourceID(primary, context);
ResourceID managedResourceID = managedSecondaryResourceID(primary, context);
return secondaryResources.stream()
.filter(r -> r.getMetadata().getName().equals(managedResourceID.getName()) &&
Objects.equals(r.getMetadata().getNamespace(),
managedResourceID.getNamespace().orElse(null)))
.findFirst();
}

protected ResourceID managedResourceID(P primary, Context<P> context) {
/**
* Override this method in order to optimize and not compute the desired when selecting the target
* secondary resource. Simply, a static ResourceID can be returned.
*
* @param primary resource
* @param context of current reconciliation
* @return id of the target managed resource
*/
protected ResourceID managedSecondaryResourceID(P primary, Context<P> context) {
return ResourceID.fromResource(desired(primary, context));
}

Expand Down

0 comments on commit 826349b

Please sign in to comment.