Skip to content

ROX-33557: fix node resolution from hostname#19461

Open
rhacs-bot wants to merge 1 commit intorelease-4.10from
backport-19435-to-release-4.10
Open

ROX-33557: fix node resolution from hostname#19461
rhacs-bot wants to merge 1 commit intorelease-4.10from
backport-19435-to-release-4.10

Conversation

@rhacs-bot
Copy link
Contributor

Backport f5d5cf0 from #19435.

@rhacs-bot rhacs-bot requested a review from a team as a code owner March 17, 2026 16:44
@github-actions github-actions bot added area/sensor backport PR to backport changes from master to release branch ai-review labels Mar 17, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • In getNodeByPrefix, the warning log for additional matches uses match.Name, which refers to the previously selected node instead of the current conflicting node (k); this makes the log misleading and likely not what you intended to surface for debugging.
  • The selection logic in getNodeByPrefix compares keys lexicographically (k < match.Name), but the comment says it should favor the 'closest match' and 'most likely requested node'; consider aligning the implementation with that intent (e.g., preferring the shortest matching name or longest common prefix) or adjusting the comment to reflect the actual behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getNodeByPrefix`, the warning log for additional matches uses `match.Name`, which refers to the previously selected node instead of the current conflicting node (`k`); this makes the log misleading and likely not what you intended to surface for debugging.
- The selection logic in `getNodeByPrefix` compares keys lexicographically (`k < match.Name`), but the comment says it should favor the 'closest match' and 'most likely requested node'; consider aligning the implementation with that intent (e.g., preferring the shortest matching name or longest common prefix) or adjusting the comment to reflect the actual behavior.

## Individual Comments

### Comment 1
<location path="sensor/kubernetes/listener/resources/node_store.go" line_range="109-110" />
<code_context>
+
+	var match *nodeWrap
+	for k, v := range s.nodes {
+		if strings.HasPrefix(k, prefix) {
+			if match != nil {
+				log.Warnf("Additional nodes match prefix %q: %s", prefix, match.Name)
+			}
</code_context>
<issue_to_address>
**issue:** Warn log for additional matches logs the previous match name instead of the newly found conflicting key, which can be misleading.

Inside the `if match != nil` block, the warning logs `match.Name` (the already selected node) instead of the newly found key `k`. This makes the warning misleading about which node is the “additional” match. Please log `k`, or both `k` and `match.Name`, so the conflicting entries are clearly identified.
</issue_to_address>

### Comment 2
<location path="sensor/kubernetes/listener/resources/node_store.go" line_range="113-120" />
<code_context>
+			if match != nil {
+				log.Warnf("Additional nodes match prefix %q: %s", prefix, match.Name)
+			}
+			if match == nil || k < match.Name {
+				// favor the closest match, whether the prefix matches more
+				// of the string. This serves two purposes:
+				//   1. it is deterministic
+				//   2. it returns the most likely requested node of the multiple
+				//      matches
+				match = v
</code_context>
<issue_to_address>
**suggestion:** Lexicographical comparison does not really implement the "closest match" heuristic described in the comment.

The logic here returns the lexicographically smallest `k`, which is deterministic but not necessarily the “closest” match (e.g., `ip-10-0-24-9a` vs `ip-10-0-24-9z`). If the intent is a true notion of closeness (e.g., minimal suffix length or another distance metric), the comparison should be updated. Otherwise, consider rephrasing the comment to emphasize determinism and tie-breaking rather than semantic closeness or “most likely requested node.”

```suggestion
			if match == nil || k < match.Name {
				// favor a deterministic match by choosing the lexicographically
				// smallest node name among matches. This serves two purposes:
				//   1. it is deterministic
				//   2. it provides a stable tie-breaker when multiple nodes
				//      match the same prefix, but does not guarantee semantic
				//      "closeness" to the requested node name
				match = v
			}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +109 to +110
if strings.HasPrefix(k, prefix) {
if match != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Warn log for additional matches logs the previous match name instead of the newly found conflicting key, which can be misleading.

Inside the if match != nil block, the warning logs match.Name (the already selected node) instead of the newly found key k. This makes the warning misleading about which node is the “additional” match. Please log k, or both k and match.Name, so the conflicting entries are clearly identified.

Comment on lines +113 to +120
if match == nil || k < match.Name {
// favor the closest match, whether the prefix matches more
// of the string. This serves two purposes:
// 1. it is deterministic
// 2. it returns the most likely requested node of the multiple
// matches
match = v
}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Lexicographical comparison does not really implement the "closest match" heuristic described in the comment.

The logic here returns the lexicographically smallest k, which is deterministic but not necessarily the “closest” match (e.g., ip-10-0-24-9a vs ip-10-0-24-9z). If the intent is a true notion of closeness (e.g., minimal suffix length or another distance metric), the comparison should be updated. Otherwise, consider rephrasing the comment to emphasize determinism and tie-breaking rather than semantic closeness or “most likely requested node.”

Suggested change
if match == nil || k < match.Name {
// favor the closest match, whether the prefix matches more
// of the string. This serves two purposes:
// 1. it is deterministic
// 2. it returns the most likely requested node of the multiple
// matches
match = v
}
if match == nil || k < match.Name {
// favor a deterministic match by choosing the lexicographically
// smallest node name among matches. This serves two purposes:
// 1. it is deterministic
// 2. it provides a stable tie-breaker when multiple nodes
// match the same prefix, but does not guarantee semantic
// "closeness" to the requested node name
match = v
}

@rhacs-bot
Copy link
Contributor Author

Images are ready for the commit at 13548da.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.10.0-1-g13548da157.

@github-actions
Copy link
Contributor

/konflux-retest main-on-push

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 0% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.37%. Comparing base (7b817fa) to head (13548da).

Files with missing lines Patch % Lines
sensor/kubernetes/listener/resources/node_store.go 0.00% 28 Missing ⚠️
sensor/common/detector/detector.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           release-4.10   #19461      +/-   ##
================================================
- Coverage         49.38%   49.37%   -0.02%     
================================================
  Files              2660     2660              
  Lines            200669   200697      +28     
================================================
- Hits              99103    99090      -13     
- Misses            94125    94163      +38     
- Partials           7441     7444       +3     
Flag Coverage Δ
go-unit-tests 49.37% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

/konflux-retest operator-bundle-on-push

1 similar comment
@github-actions
Copy link
Contributor

/konflux-retest operator-bundle-on-push

@openshift-ci
Copy link

openshift-ci bot commented Mar 17, 2026

@rhacs-bot: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/gke-qa-e2e-tests 13548da link false /test gke-qa-e2e-tests
ci/prow/gke-nongroovy-compatibility-tests 13548da link false /test gke-nongroovy-compatibility-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

ai-review area/sensor backport PR to backport changes from master to release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants