Skip to content

improve: related resource reference change#3425

Open
csviri wants to merge 21 commits into
operator-framework:nextfrom
csviri:strict-primary-to-secondary-index
Open

improve: related resource reference change#3425
csviri wants to merge 21 commits into
operator-framework:nextfrom
csviri:strict-primary-to-secondary-index

Conversation

@csviri

@csviri csviri commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

When there is a resource that references (not owner reference) one or more custom resources (see sample), and the reference changes, we want to trigger reconciliation for both old and new resources referenced.
This PR fixes it by calling also the SeondaryToPrimary mapper twice (also for old resource) on update operation.

It adjusts also PrimaryToSecondaryIndex so when a reference changes it removed from the secondary from the old primary. That is a more strict, but correct behavior.

We did not have this issue for now, since usually the reference for (typically) "config resources" that serve as an input for the reconciliation (among the spec) is usually is other way around.
Note that for this use case PrimaryToSecondaryMapper is NOT needed, since basically this is very similar to classic owner reference scenario.

TODO:

  • filtering caching update path should not call SecondaryToPrimaryMapper twice

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves handling of secondary→primary reference changes by extending the primary-to-secondary index update semantics, adding targeted tests (unit + integration), and introducing a new sample scenario demonstrating reconciliations when a secondary’s referenced primary set changes.

Changes:

  • Updated the informer eventing/indexing pipeline so updates can reconcile both newly referenced and no-longer-referenced primaries.
  • Added new core tests covering narrowing/moving references across updates.
  • Added a new operator-framework integration test + sample resources demonstrating subset reference changes.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/TargetStatus.java Adds a simple status model used by the sample primary CR.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/TargetReconciler.java Sample reconciler driven by a referencing secondary CR via an informer event source.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/TargetCustomResource.java Sample primary custom resource type for the new scenario.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/SecondaryToPrimaryReferenceChangeIT.java New IT demonstrating subset reference changes and expected reconciliation behavior.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/ConfigToTargetMapper.java Secondary→primary mapper for the sample that maps config.targetNames to targets.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/ConfigSpec.java Spec model for the sample secondary CR, including targetNames and value.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/secondarytoprimaryreferencechange/ConfigCustomResource.java Sample secondary custom resource type.
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/PrimaryToSecondaryIndexTest.java Adds tests verifying index updates remove obsolete primaries on update.
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java Updates mocks/verifications for new index method signatures and delete behavior.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/SecondaryToPrimaryMapper.java Updates mapper Javadoc wording.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/PrimaryToSecondaryIndex.java Changes index callbacks to return affected primary IDs.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/NOOPPrimaryToSecondaryIndex.java Adapts NOOP implementation to new return types.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java Uses index-returned primaries to drive reconciliation propagation and unions old/new mappings.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java Tracks and removes obsolete primaries on update; returns affected primaries for reconciliation.
docs/content/en/docs/documentation/eventing.md Documents secondary→primary mapping behavior (currently inconsistent with the API).

Comment thread docs/content/en/docs/documentation/eventing.md Outdated
@csviri csviri marked this pull request as draft June 17, 2026 15:04
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 17, 2026
@csviri csviri requested a review from Copilot June 17, 2026 15:12
@csviri csviri changed the title improve: related resource owner reference change improve: related resource reference change Jun 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Comment on lines +31 to +37
* Maps a secondary resource to the set of primary resources that should be reconciled in
* response.
*
* @param resource the secondary resource for which an event was received
* @return set of primary resource IDs to enqueue for reconciliation; an empty set means the event
* is irrelevant and no reconciliation is triggered. This is called also the old and the new
* resources, in case of an update.
Comment on lines +206 to +210
if (primaryResourceIdSet == null) {
primaryResourceIdSet = new HashSet<>();
primaryResourceIdSet.addAll(
configuration().getSecondaryToPrimaryMapper().toPrimaryResourceIDs(resource));
if (oldResource != null) {

@csviri csviri Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relevant will take a look

@csviri csviri changed the title improve: related resource reference change [WIP] improve: related resource reference change Jun 17, 2026
@csviri csviri force-pushed the strict-primary-to-secondary-index branch from 8170175 to 74c83aa Compare June 17, 2026 15:35
@csviri csviri requested a review from Copilot June 17, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Comment on lines 35 to 44
@Override
public void onAddOrUpdate(R resource) {
// empty method because of noop implementation
public Set<ResourceID> onAddOrUpdate(R resource, R oldResource) {
return null;
}

@Override
public void onDelete(R resource) {
public Set<ResourceID> onDelete(R resource) {
// empty method because of noop implementation
return null;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis is relevant, but will need a refactoring to remove, will get rid of it in a subsequent PR

@dvob

dvob commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

I updated my reproducer and it works as expected (dvob/java-operator-sdk-repo-example@1ce1404).

Also I like that with this approach we no longer need a special wiring.

@csviri thanks a lot for your effort!

@csviri csviri changed the title [WIP] improve: related resource reference change improve: related resource reference change Jun 18, 2026
@csviri csviri marked this pull request as ready for review June 18, 2026 06:50
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2026
public void onAddOrUpdate(R resource) {
// empty method because of noop implementation
public Set<ResourceID> onAddOrUpdate(R resource, R oldResource) {
return null;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very ugly, might be better to remove the NOOP index

csviri added 7 commits June 18, 2026 08:53
…urce

This might needed in some corner cases where might help with optimizations to which resource to trigger.

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
csviri and others added 12 commits June 18, 2026 08:53
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
@csviri csviri force-pushed the strict-primary-to-secondary-index branch from dcaa6c0 to 22e4a58 Compare June 18, 2026 06:53
@csviri

csviri commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

I updated my reproducer and it works as expected (dvob/java-operator-sdk-repo-example@1ce1404).

Also I like that with this approach we no longer need a special wiring.

@csviri thanks a lot for your effort!

Thank you @dvob for feedback and highlighting this use case, that helps a lot!

@csviri

csviri commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

@metacosm @xstefank after this is merged I will do a small refactoring in the InformerEventSource since that coudl be a bit simpler, just did not want to do it in same PR. Please take a look on this.

@metacosm

Copy link
Copy Markdown
Collaborator

Can we focus this PR on what it needs to accomplish instead of also renaming methods and changing their visibility (if possible)?

csviri added 2 commits June 18, 2026 10:22
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
@csviri

csviri commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Can we focus this PR on what it needs to accomplish instead of also renaming methods and changing their visibility (if possible)?

yep, np, I did

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InformerEventSource: trigger reconciles based on old and new resource state

4 participants