fix: honour bulk dependent resource capabilities during reconciliation - #3520
Draft
csviri wants to merge 1 commit into
Draft
fix: honour bulk dependent resource capabilities during reconciliation#3520csviri wants to merge 1 commit into
csviri wants to merge 1 commit into
Conversation
A `BulkDependentResource` may implement any subset of `Creator`, `Updater` and `Deleter`. `BulkDependentResourceInstance`, the internal per-item wrapper that reuses `AbstractDependentResource`'s reconcile logic, implements all three and delegates each call to the bulk resource with an unchecked cast. Its capabilities therefore have to be derived from the wrapped bulk resource. 0b8d8dd introduced the overridable `creatable()` / `updatable()` hooks for exactly this, but the wiring was never completed: * `BulkDependentResourceInstance` overrides `isCreatable()` / `isUpdatable()`, which `reconcile` never consults, so both overrides were dead code. * the inner create branch of `AbstractDependentResource.reconcile` still read the `creatable` field directly instead of calling `creatable()`. Since the wrapper implements all three interfaces, both fields are always true, so create and update were attempted regardless of what the bulk resource actually supports, failing with a ClassCastException in `BulkDependentResourceInstance.create` / `update`: java.lang.ClassCastException: class ...CreateAndDeleteOnlyBulk cannot be cast to class ...Updater at BulkDependentResourceInstance.update(BulkDependentResourceReconciler.java:115) at AbstractDependentResource.handleUpdate(AbstractDependentResource.java:204) A non-bulk dependent in the same situation just logs "implement Updater interface to modify it" and skips the operation. Fixes this by overriding `creatable()` / `updatable()` in the wrapper and by using `creatable()` in the create branch. `isCreatable()` / `isUpdatable()` now delegate to `creatable()` / `updatable()` so the two pairs cannot drift apart again. Adds regression tests for a create+delete-only and a delete-only bulk dependent; both fail without this change.
16 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes reconciliation for bulk dependents so create/update operations are only attempted when the wrapped BulkDependentResource actually supports them, preventing ClassCastException from the per-item wrapper incorrectly advertising capabilities.
Changes:
- Wire
AbstractDependentResource.reconcileto consult the overridablecreatable()hook (not the rawcreatablefield) when entering the create path. - Update
BulkDependentResourceInstanceto overridecreatable()/updatable()based on the wrapped bulk resource’s implemented capabilities. - Add regression tests covering bulk dependents that support only (create+delete) and only (delete), ensuring create/update are skipped appropriately.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java | Ensures reconciliation uses creatable()/updatable() hooks consistently so capability overrides are honored. |
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java | Derives per-item wrapper create/update capabilities from the wrapped bulk resource to avoid invalid casts. |
| operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceCapabilitiesTest.java | Adds regression coverage for bulk resources that intentionally do not implement Creator and/or Updater. |
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.
A
BulkDependentResourcemay implement any subset ofCreator,UpdaterandDeleter.BulkDependentResourceInstance, the internalper-item wrapper that reuses
AbstractDependentResource's reconcilelogic, implements all three and delegates each call to the bulk resource
with an unchecked cast. Its capabilities therefore have to be derived
from the wrapped bulk resource.
0b8d8dd introduced the overridable
creatable()/updatable()hooksfor exactly this, but the wiring was never completed:
BulkDependentResourceInstanceoverridesisCreatable()/isUpdatable(), whichreconcilenever consults, so both overrideswere dead code.
AbstractDependentResource.reconcilestillread the
creatablefield directly instead of callingcreatable().Since the wrapper implements all three interfaces, both fields are always
true, so create and update were attempted regardless of what the bulk
resource actually supports, failing with a ClassCastException in
BulkDependentResourceInstance.create/update:A non-bulk dependent in the same situation just logs "implement Updater
interface to modify it" and skips the operation.
Fixes this by overriding
creatable()/updatable()in the wrapper andby using
creatable()in the create branch.isCreatable()/isUpdatable()now delegate tocreatable()/updatable()so the twopairs cannot drift apart again.
Adds regression tests for a create+delete-only and a delete-only bulk
dependent; both fail without this change.
Part of #3517