Skip to content

Conversation

@Poor12
Copy link
Contributor

@Poor12 Poor12 commented Aug 11, 2025

What type of PR is this?

The sts/pg object is retrieved from the informer cache and should be treated as read-only. Modifying sts.Spec.Selector.MatchLabels/pg directly can lead to race conditions and unpredictable behavior in the controller. So deepcopy it befor update.

What this PR does / why we need it:

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

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 @Poor12, 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!

I've addressed potential race conditions and unpredictable behavior by ensuring that objects retrieved from the informer cache are treated as read-only. My changes involve implementing deep copies of PodGroup and StatefulSet objects before any modifications are made. This prevents direct alteration of cached objects, promoting thread safety and predictable controller behavior, particularly when updating PodGroup specifications or StatefulSet labels.

Highlights

  • Deep Copying PodGroup in Job Controller: I've added a DeepCopy() call for the PodGroup object before any modifications are made to its specifications. This ensures that the object retrieved from the informer cache, which should be treated as read-only, is not directly altered, preventing potential race conditions.
  • Safe Modification of StatefulSet Labels: I've implemented a manual deep copy for sts.Spec.Selector.MatchLabels when constructing the matchLabels for the LabelSelector. This prevents direct modification of the cached StatefulSet object's selector.
  • Deep Copying PodGroup in PodGroup Controller: I've introduced a DeepCopy() operation for the PodGroup object before checking for updates and performing the update operation. This ensures that any modifications are applied to a mutable copy, safeguarding the integrity of the cached object.
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.

@volcano-sh-bot volcano-sh-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 11, 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.

Code Review

This pull request correctly addresses a critical bug where objects from the informer cache were being modified directly, which could lead to race conditions. The fix involves creating deep copies of PodGroup and StatefulSet objects before modification, which is the correct approach. The changes are well-implemented. I have one suggestion to simplify a block of code in job_controller_actions.go for better readability and maintainability.

Comment on lines 806 to 831
if taskMember, ok := podGroupToUpdate.Spec.MinTaskMember[task.Name]; !ok {
pgShouldUpdate = true
pg.Spec.MinTaskMember[task.Name] = cnt
podGroupToUpdate.Spec.MinTaskMember[task.Name] = cnt
} else {
if taskMember == cnt {
continue
}

pgShouldUpdate = true
pg.Spec.MinTaskMember[task.Name] = cnt
podGroupToUpdate.Spec.MinTaskMember[task.Name] = cnt
}

Choose a reason for hiding this comment

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

medium

The logic for updating MinTaskMember can be simplified to reduce code duplication and improve readability.

		if taskMember, ok := podGroupToUpdate.Spec.MinTaskMember[task.Name]; !ok || taskMember != cnt {
			pgShouldUpdate = true
			podGroupToUpdate.Spec.MinTaskMember[task.Name] = cnt
		}

@Poor12
Copy link
Contributor Author

Poor12 commented Aug 11, 2025

/cc @JesseStutler I just found another place may occur the same situation and update it in the same time. Could you please help check the code?

@JesseStutler
Copy link
Member

/cc @JesseStutler I just found another place may occur the same situation and update it in the same time. Could you please help check the code?

OK. Thanks
/priority high
/kind bug

@volcano-sh-bot volcano-sh-bot added priority/high kind/bug Categorizes issue or PR as related to a bug. labels Aug 11, 2025
@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 11, 2025
Signed-off-by: shentiecheng <shentiecheng@bytedance.com>
@volcano-sh-bot volcano-sh-bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2025
@Poor12 Poor12 requested a review from Monokaix August 11, 2025 08:05
@Monokaix
Copy link
Member

/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 11, 2025
Copy link
Member

@JesseStutler JesseStutler left a comment

Choose a reason for hiding this comment

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

/lgtm
Thanks, we can cherry-pick this commit in the same PR: #4522 @Poor12

@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2025
@volcano-sh-bot volcano-sh-bot merged commit c490211 into volcano-sh:master Aug 11, 2025
19 checks passed
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. priority/high size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants