Skip to content

Conversation

@cyf-2002
Copy link
Contributor

@cyf-2002 cyf-2002 commented Jul 29, 2025

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?


Copilot AI review requested due to automatic review settings July 29, 2025 12:15
@volcano-sh-bot
Copy link
Contributor

Welcome @cyf-2002!

It looks like this is your first PR to volcano-sh/volcano.

Thank you, and welcome to Volcano. 😃

@volcano-sh-bot volcano-sh-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 29, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a 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 UpdateStatus method was incorrectly used, which only modifies the status subresource 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() with vcClient.TopologyV1alpha1().HyperNodes().Update() in pkg/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

  1. 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.

Copy link
Contributor

Copilot AI left a 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() to Update() 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{})
Copy link

Copilot AI Jul 29, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 66 to 71
_, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{})
return err

Choose a reason for hiding this comment

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

high

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 UpdateStatus call, or it should not be responsible for status updates at all, leaving that to dedicated functions like syncHyperNodeStatus.
  • 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.

@cyf-2002 cyf-2002 force-pushed the fix/fix-update-hypernode branch from 9d76b95 to 5389552 Compare July 29, 2025 12:30
@cyf-2002 cyf-2002 changed the title fix hypernode update bug fix#4497: hypernode update bug Jul 30, 2025
@JesseStutler
Copy link
Member

/priority high
Thanks, but please complete your description of the PR, right now it's too simple. @cyf-2002

}

_, err = vcClient.TopologyV1alpha1().HyperNodes().UpdateStatus(context.Background(), current, metav1.UpdateOptions{})
_, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{})
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@cyf-2002 cyf-2002 force-pushed the fix/fix-update-hypernode branch from ab3b22e to ccad709 Compare July 30, 2025 09:29
@cyf-2002 cyf-2002 closed this Jul 31, 2025
@cyf-2002 cyf-2002 reopened this Jul 31, 2025
@cyf-2002
Copy link
Contributor Author

/priority high Thanks, but please complete your description of the PR, right now it's too simple. @cyf-2002

I added some details, and I described the question on #4497.

current.Annotations[k] = v
}

_, err = vcClient.TopologyV1alpha1().HyperNodes().Update(context.Background(), current, metav1.UpdateOptions{})
Copy link
Member

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

@Monokaix
Copy link
Member

Monokaix commented Aug 1, 2025

Is there a way to just call API once and update both spec and status?

@Monokaix
Copy link
Member

Monokaix commented Aug 4, 2025

/ok-to-test

@volcano-sh-bot volcano-sh-bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Aug 4, 2025
@Monokaix
Copy link
Member

Monokaix commented Aug 4, 2025

Please also merge to one commit.

@cyf-2002 cyf-2002 force-pushed the fix/fix-update-hypernode branch from 02e692f to 5c5352f Compare August 4, 2025 07:03
Signed-off-by: cyf-2002 <865636335@qq.com>
@cyf-2002 cyf-2002 force-pushed the fix/fix-update-hypernode branch from 5c5352f to 823460f Compare August 4, 2025 07:06
@cyf-2002
Copy link
Contributor Author

cyf-2002 commented Aug 4, 2025

Please also merge to one commit.

Done. I can't find a way to just call API once temporarily.

@Monokaix
Copy link
Member

Monokaix commented Aug 4, 2025

/approve

@volcano-sh-bot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 4, 2025
@cyf-2002 cyf-2002 requested a review from JesseStutler August 5, 2025 01:48
@JesseStutler
Copy link
Member

/lgtm

@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 5, 2025
@volcano-sh-bot volcano-sh-bot merged commit 5682afb into volcano-sh:master Aug 5, 2025
19 checks passed
Monokaix pushed a commit to Monokaix/volcano that referenced this pull request Aug 7, 2025
…node

fix#4497: hypernode update bug

Signed-off-by: Monokaix <changxuzheng@huawei.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/high size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants