-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix#4497: hypernode update bug #4498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix#4497: hypernode update bug #4498
Conversation
|
Welcome @cyf-2002! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @cyf-2002, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request provides a critical fix for the HyperNode controller's update mechanism. It corrects an issue where only the status subresource of a HyperNode was being updated, preventing full resource modifications from taking effect. By switching to the appropriate client method, the PR ensures that all intended changes to HyperNode objects are properly persisted.
Highlights
- Bug Fix: HyperNode Update Logic: This PR addresses a bug where updates to HyperNode resources were not being fully applied. Previously, the
UpdateStatusmethod was incorrectly used, which only modifies thestatussubresource of the HyperNode object. This meant that changes to other fields, such as annotations (as seen in the preceding code), were not being persisted. - API Client Method Correction: The core change involves replacing the call to
vcClient.TopologyV1alpha1().HyperNodes().UpdateStatus()withvcClient.TopologyV1alpha1().HyperNodes().Update()inpkg/controllers/hypernode/utils/utils.go. This ensures that the entire HyperNode resource, including its metadata and spec, is correctly updated by the Kubernetes API server.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
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 fixes a bug in the hypernode update mechanism by changing from status-only updates to full object updates. The change addresses issue #4497 where the hypernode controller was incorrectly using UpdateStatus() instead of Update().
- Changes the update method from
UpdateStatus()toUpdate()in the hypernode controller - Ensures that annotation changes are properly persisted to the hypernode object
| } | ||
|
|
||
| _, err = vcClient.TopologyV1alpha1().HyperNodes().UpdateStatus(context.Background(), current, metav1.UpdateOptions{}) | ||
| _, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{}) |
Copilot
AI
Jul 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from UpdateStatus() to Update() is correct for persisting annotation changes, but consider whether the full object update is necessary. If only annotations are being modified, you might want to use a strategic merge patch to avoid potential conflicts with concurrent updates to other fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request fixes a bug where HyperNode spec and metadata updates were not being persisted. The change from UpdateStatus to Update is correct for this purpose. However, the review identifies a remaining high-severity issue in the UpdateHyperNode function: it attempts to update the resource's status, but this will be silently ignored by the Update call due to the status subresource being enabled on the CRD. This creates a latent bug. I've provided a detailed explanation and recommendation in the line comment.
| _, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{}) | ||
| return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this change to use Update is correct for persisting changes to the spec and metadata, a significant issue remains. The HyperNode CRD has the status subresource enabled. When a CRD has a status subresource, the .status field can only be modified via a dedicated UpdateStatus call. The standard Update call will silently ignore any changes to the .status field. The UpdateHyperNode function modifies the .status field of the current object before calling Update. This is misleading as the status change will not be persisted, creating a latent bug for any caller that expects the status to be updated.
Recommendations:
- The function should either be refactored to perform a separate
UpdateStatuscall, or it should not be responsible for status updates at all, leaving that to dedicated functions likesyncHyperNodeStatus. - As a general best practice, objects retrieved from a lister cache should be deep-copied before modification to avoid mutating a shared object in the cache.
9d76b95 to
5389552
Compare
|
/priority high |
| } | ||
|
|
||
| _, err = vcClient.TopologyV1alpha1().HyperNodes().UpdateStatus(context.Background(), current, metav1.UpdateOptions{}) | ||
| _, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need update both spec and status as the HyperNode status may also include Network condition in status and this also need to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can update func update status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I mean we should update both spec and status, any other way is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,I got it. So if I want to fix this bug, I can call both update and updatestatus func.
ab3b22e to
ccad709
Compare
| current.Annotations[k] = v | ||
| } | ||
|
|
||
| _, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to judge err here to avoid override
if err != nil{
return err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
|
Is there a way to just call API once and update both spec and status? |
|
/ok-to-test |
|
Please also merge to one commit. |
02e692f to
5c5352f
Compare
Signed-off-by: cyf-2002 <865636335@qq.com>
5c5352f to
823460f
Compare
Done. I can't find a way to just call API once temporarily. |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Monokaix The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
…node fix#4497: hypernode update bug Signed-off-by: Monokaix <changxuzheng@huawei.com>
What type of PR is this?
fix
What this PR does / why we need it:
Hypernode controller will ignore updating spec, as it only calls UpdateStatus() to update hypernode. When I test the function of autoupdate, hypernode spec will never be updated since it's created. So we should add Update() call.
Which issue(s) this PR fixes:
#4497
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?