Skip to content

improve: extend SecondaryToPrimaryMapper so it also gets the old resource#3388

Closed
csviri wants to merge 6 commits into
operator-framework:nextfrom
csviri:secondary-to-primary-improve
Closed

improve: extend SecondaryToPrimaryMapper so it also gets the old resource#3388
csviri wants to merge 6 commits into
operator-framework:nextfrom
csviri:secondary-to-primary-improve

Conversation

@csviri

@csviri csviri commented May 28, 2026

Copy link
Copy Markdown
Collaborator

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

TODO adaptor

Signed-off-by: Attila Mészáros a_meszaros@apple.com

@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 May 28, 2026
@csviri

csviri commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author

@csviri

csviri commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author

as discussed with @dvob , he will created a detailed issue for this.

@dvob

dvob commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@csviri thank you for implementing this so quickly. I also created issue #3401 for reference which we can more or less close right away if this is merged.

I updated my reproducer to use two different types (MyThing and MyThingConfig), in the hope that it is more understandable. I also updated it to use this PR and it did work (test does no longer fail) https://github.com/dvob/java-operator-sdk-repo-example/tree/csviri-secondary-to-primary-improve

However, when updating my reproducer, I ran into a different challenge. In my initial reproducer I used only one CRD (Repo) which referenced itself. But now I have to two different CRDs and in withPrimaryToSecondaryMapper I basically want to access the MyThingConfig informer which I'm building which is not easily possible. For now I did some dirty hack. But you might have a better idea to achieve this: https://github.com/dvob/java-operator-sdk-repo-example/blob/4b9e01c3099ae580036aa81cbe1558c0d422f0b0/src/main/java/com/example/MyThingReconciler.java#L53 ?

One thing which also came to my mind is, that if you not specify withPrimaryToSecondaryMapper it will use the DefaultPrimaryToSecondaryIndex which most likely will behave wrong in such a scenario. This is not really a problem, as you just can set withPrimaryToSecondaryMapper, but I'm just no sure how obvious this is for users of the API.

@csviri

csviri commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

@dvob

dvob commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Yes, I think docs are fine.

For a long time i didn't even knew about the default reverse index behavior. I did set the primaryToSecondaryMapper every time explicitly and I still do this because I think its easier to understand if things are a little more explicit. I don't know how other users rely on this.

@csviri

csviri commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

I did set the primaryToSecondaryMapper every time explicitly and I still do this because I think its easier to understand if things are a little more explicit. I don't know how other users rely on this.

Yes, unfortunately this is not a that nice and round concept, but currently the only way to be able to use getSecondaryResource uniformly. We time to time get questions around it so it is used.

@csviri

csviri commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

basically want to access the MyThingConfig informer which I'm building which is not easily possible. For now I did some dirty hack. But you might have a better idea to achieve this: https://github.com/dvob/java-operator-sdk-repo-example/blob/4b9e01c3099ae580036aa81cbe1558c0d422f0b0/src/main/java/com/example/MyThingReconciler.java#L53 ?

Please take a look on indexers, setting a custom indexer for that would solve the problem as far I can see. InformerEventSource has API to add indexer:

@Override
public void addIndexers(Map<String, Function<R, List<String>>> indexers) {
if (isRunning()) {
throw new OperatorException("Cannot add indexers after InformerEventSource started.");
}
this.indexers.putAll(indexers);
}

then access the resource by index:

@csviri

csviri commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

I will add an Integration test to showcase your sample handling

csviri added 5 commits June 17, 2026 14:29
…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>
@csviri csviri force-pushed the secondary-to-primary-improve branch from 9f0c947 to 35b6467 Compare June 17, 2026 12:33
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
@csviri

csviri commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

replaced by: #3425

@csviri

csviri commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

@dvob I implemented an alternative version with an integration test to cover your use case, if everything goes well, this will be in next minor release. Please take a look, and let me know if it looks good to you.

@csviri csviri closed this Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InformerEventSource: trigger reconciles based on old and new resource state

2 participants