fix: use the cached desired state when selecting an external secondary resource - #3528
Draft
csviri wants to merge 1 commit into
Draft
Conversation
…y resource `AbstractExternalDependentResource.selectTargetSecondaryResource` called `desired(primary, context)` directly instead of going through `getOrComputeDesired(context)`. `getOrComputeDesired` exists precisely so that `desired` is invoked at most once per reconciliation; its javadoc states that the SDK should call it exclusively and that `desired` should never be called directly, because this "supports scenarios where idempotent computation of the desired state is not feasible". Calling `desired` directly here means it is computed an extra time on every reconciliation of an external dependent resource: once to pick the target secondary and again from `match`/`reconcile` via the cache. That is wasted work in all cases, and produces an inconsistent desired state for any implementation whose `desired` is not idempotent - exactly the case the cache is there to support. `KubernetesDependentResource` already routes through `getOrComputeDesired` via `targetSecondaryResourceID`; this brings the external variant in line. No unit test is added: the code path is only covered by the external dependent integration tests under `operator-framework`, which need a cluster.
16 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness/performance issue in the external dependent resource flow by ensuring the desired state used to select the target secondary resource comes from the per-reconciliation desired-state cache, rather than recomputing it.
Changes:
- Update
AbstractExternalDependentResource.selectTargetSecondaryResourceto usegetOrComputeDesired(context)instead of callingdesired(primary, context)directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AbstractExternalDependentResource.selectTargetSecondaryResourcecalleddesired(primary, context)directly instead of going throughgetOrComputeDesired(context).getOrComputeDesiredexists precisely so thatdesiredis invoked atmost once per reconciliation; its javadoc states that the SDK should call
it exclusively and that
desiredshould never be called directly, becausethis "supports scenarios where idempotent computation of the desired state
is not feasible".
Calling
desireddirectly here means it is computed an extra time onevery reconciliation of an external dependent resource: once to pick the
target secondary and again from
match/reconcilevia the cache. That iswasted work in all cases, and produces an inconsistent desired state for
any implementation whose
desiredis not idempotent - exactly the casethe cache is there to support.
KubernetesDependentResourcealready routes throughgetOrComputeDesiredvia
targetSecondaryResourceID; this brings the external variant in line.No unit test is added: the code path is only covered by the external
dependent integration tests under
operator-framework, which need acluster.
Part of #3517