fix(frontend): resolve owner references using apiVersion+kind to prevent wrong resource links#5641
Conversation
|
|
|
Welcome @DashratRajpurohit! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: DashratRajpurohit The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
7f9fbdc to
526c568
Compare
illume
left a comment
There was a problem hiding this comment.
Thanks for these changes.
Can you please have a look at the git commits to see if they meet the contribution guidelines? We use a Linux kernel style of git commits. See the contributing guide for general context, and please see previous git commits with git log for examples.
Commits that need attention
fix(frontend): resolve owner references using apiVersion+kind— Missingarea: descriptionprefix — e.g.frontend: HomeButton: Fix so it navigates to homeorbackend: config: Add enable-dynamic-clusters flag.
Commit guidelines
- Use atomic commits focused on a single change.
- Use the title format
<area>: <Description of changes>— description must start with a capital letter. - Keep the title under 72 characters (soft requirement).
- Explain the intention and why the change is needed.
- Make commit titles meaningful and describe what changed.
- Do not add code that a later commit rewrites; squash or reorder commits instead.
- Do not include
Fixes #NNin commit messages.
Good examples:
frontend: HomeButton: Fix so it navigates to homebackend: config: Add enable-dynamic-clusters flag
There was a problem hiding this comment.
Pull request overview
This PR updates resource metadata owner-reference rendering so Headlamp only links known resources when the owner reference matches both kind and apiVersion, avoiding incorrect links for CRDs that reuse built-in kind names.
Changes:
- Adds apiVersion validation before creating owner-reference links.
- Falls back to plain text for unmatched owner references.
- Fixes the
console.errorinterpolation for owner-reference route lookup errors.
CI status and PR commit history were not available in this review context; please confirm checks are passing and the PR history is linear.
| ownerRef.kind in ResourceClasses | ||
| ? (() => { | ||
| const cls = ResourceClasses[ownerRef.kind as keyof typeof ResourceClasses]; | ||
| return cls.apiVersion === ownerRef.apiVersion ? cls : null; |
| ownerRef.kind in ResourceClasses | ||
| ? (() => { | ||
| const cls = ResourceClasses[ownerRef.kind as keyof typeof ResourceClasses]; | ||
| return cls.apiVersion === ownerRef.apiVersion ? cls : null; |
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.
Update MetadataDisplay to validate both kind and apiVersion when resolving owner references. This ensures accurate linking for resources with overlapping kind names. - Match apiVersion against both string and array definitions in ResourceClasses. - Fall back to plain text if no exact match is found. - Fix template literal bug in console error log. - Add comprehensive unit tests in MetadataDisplay.test.tsx. Fixes: kubernetes-sigs#5569
526c568 to
9241636
Compare
|
Invalid commit message issues detected Invalid commit messagesKeywords which can automatically close issues and hashtag(#) mentions are not allowed.
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. |
|
@illume all feedback has been addressed with the latest changes and unit tests. I have updated the PR description with the summary of changes. |
Description
Latest Changes
Fixes #5569
Problem
When Headlamp shows "Controlled by" in a resource's metadata panel, it resolved
the owner reference link using only the
kindfield. But Kubernetes allowsdifferent API groups to use the same kind name:
Jobbatch/v1Jobbatch.volcano.sh/v1alpha1ReplicaSetapps/v1ReplicaSetcustom.io/v1So if a Pod was owned by a Volcano
Job, Headlamp would silently link to abatch/v1 Job— the wrong resource entirely.This is a silent correctness bug — the UI shows a clickable link that navigates
to the wrong place with no error shown to the user.
Root Cause
In
frontend/src/components/common/Resource/MetadataDisplay.tsx, themakeOwnerReferencesfunction matched resources using onlyownerRef.kind:The
KubeOwnerReferencetype already has anapiVersionfield thatuniquely identifies the API group — it was simply never used in the lookup.
Additionally, a minor pre-existing bug was found in the same function:
the
console.errorcall used{ownerRef.kind}(a plain object literal syntax)instead of
${ownerRef.kind}(a template literal), so error messages werenever correctly interpolated.
Fix
If the
apiVersiondoes not match (e.g. a CRD with the same kind name as abuilt-in resource), the owner reference is rendered as plain text instead of
an incorrect clickable link.
Changes
frontend/src/components/common/Resource/MetadataDisplay.tsxkindandapiVersionto match; fix template literal inconsole.errorDiff size: 1 file · +14 insertions · −3 deletions
Test Scenarios
✅ Case 1 — Standard built-in resource (link still works correctly)
Before fix: Clickable link → correct
batch/v1 Job✅After fix: Clickable link → correct
batch/v1 Job✅ (no regression)✅ Case 2 — CRD with the same kind name (wrong link is now prevented)
Before fix: Broken link → navigates to
batch/v1 Jobnamedmy-volcano-jobwhich likely does not exist ❌
After fix: Plain text
Job: my-volcano-job— no incorrect link ✅✅ Case 3 — Completely unknown CRD (unchanged behaviour)
Before fix: Plain text
FooController: foo-ctrl✅After fix: Plain text
FooController: foo-ctrl✅ (no change)✅ Case 4 — console.error template literal fix
How to Test Manually
kindname identical to a built-inresource (e.g.
kind: JobwithapiVersion: batch.volcano.sh/v1alpha1)ownerReferencespoints to that CRD resourcebatch/v1 JobapiVersiondoes not matchChecklist
MetadataDisplay.tsx)npm run lintpasses — exit code0ownerReferencesrendering behaviourconsole.errortemplate literal interpolation