FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

improve: owner reference mappers checks only group not apiVersion by csviri · Pull Request #3302 · operator-framework/java-operator-sdk · GitHub

improve: owner reference mappers checks only group not apiVersion - #3302

Merged
csviri merged 5 commits into
operator-framework:mainfrom
csviri:owner-ref-mapper
Apr 22, 2026
Merged

improve: owner reference mappers checks only group not apiVersion#3302
csviri merged 5 commits into
operator-framework:mainfrom
csviri:owner-ref-mapper

Conversation

csviri commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

In case of a resource is has a new version, but owner reference
still points to the old version we should still propapage the event.

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

Copilot AI review requested due to automatic review settings April 20, 2026 10:25
openshift-ci Bot requested review from metacosm and xstefank April 20, 2026 10:25

csviri commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator Author

cc @shawkins

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This PR updates owner-reference-based secondary-to-primary mapping so events still propagate when the owner reference points to an older version of the same API group (e.g., apps/v1beta1 vs apps/v1), by matching on group instead of full apiVersion.

Changes:

  • Update Mappers.fromOwnerReferences(...) to match owner references by kind + API group (ignoring version).
  • Add ReconcilerUtilsInternal.getGroup(String apiVersion) helper to extract the API group from an apiVersion string.
  • Add a unit test validating group extraction behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java Relaxes owner-reference matching from exact apiVersion to API group comparison.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ReconcilerUtilsInternal.java Introduces getGroup helper for parsing API group from apiVersion.
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ReconcilerUtilsInternalTest.java Adds coverage for getGroup parsing behavior.

Comment on lines 101 to 110
public static <T extends HasMetadata> SecondaryToPrimaryMapper<T> fromOwnerReferences(
String apiVersion, String kind, boolean clusterScope) {
String correctApiVersion = apiVersion.startsWith("/") ? apiVersion.substring(1) : apiVersion;
return resource ->
resource.getMetadata().getOwnerReferences().stream()
.filter(r -> r.getKind().equals(kind) && r.getApiVersion().equals(correctApiVersion))
.filter(
r ->
r.getKind().equals(kind)
&& getGroup(r.getApiVersion()).equals(getGroup(apiVersion)))
.map(or -> ResourceID.fromOwnerReference(resource, or, clusterScope))
.collect(Collectors.toSet());

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This change intentionally relaxes ownerReference matching from full apiVersion to just group. Please add a focused unit test in the existing MappersTest that demonstrates the new behavior (same group + kind but different versions should still map), so future refactors don’t accidentally revert to strict apiVersion matching.

Copilot uses AI. Check for mistakes.

csviri commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator Author

see also: keycloak/keycloak#48030 (comment)

csviri added 2 commits April 20, 2026 12:46
In case of a resource is has a new version, but owner reference
still points to the old version we should still propapage the event.

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
csviri force-pushed the owner-ref-mapper branch from 0345443 to e57272d Compare April 20, 2026 10:46
csviri requested a review from shawkins April 20, 2026 10:46
.filter(
r ->
r.getKind().equals(kind)
&& getGroup(r.getApiVersion()).equals(getGroup(apiVersion)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure this is the correct behavior: shouldn't there be a conversion hook instead? It seems dangerous to potentially match resources with differing versions…

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Conversion hooks, does not update the owner references of the resource. Maybe we should have an integration test also this, to see how exactly and what happens. I will add one.

csviri commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator Author

Maybe would be more pc to target next with this PR.

xstefank left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't have anything else to add to what was already mentioned.

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
csviri marked this pull request as draft April 21, 2026 14:29
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 Apr 21, 2026
csviri changed the title improve: owner reference mappers checks only group not apiVersion [WIP] improve: owner reference mappers checks only group not apiVersion Apr 21, 2026
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
csviri marked this pull request as ready for review April 22, 2026 08:03
openshift-ci Bot requested review from metacosm and xstefank April 22, 2026 08:03
csviri changed the title [WIP] improve: owner reference mappers checks only group not apiVersion improve: owner reference mappers checks only group not apiVersion Apr 22, 2026
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 Apr 22, 2026

csviri commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator Author

@xstefank @metacosm I added also an E2E test, it seems that even if the CR is updated to new apiVersion the owner ref stays the same. So the implementation is correct this way.

Signed-off-by: Chris Laprun <metacosm@gmail.com>
csviri merged commit 94f005e into operator-framework:main Apr 22, 2026
30 of 32 checks passed

Copy link
Copy Markdown
Collaborator

Thank you everyone.

csviri deleted the owner-ref-mapper branch April 24, 2026 10:36
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL