-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix panic in job controller's killPods action #4569
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
Conversation
|
Welcome @neo502721! |
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 @neo502721, 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 resolves a critical bug in the job controller's killPods action that could lead to a nil pointer dereference. Previously, direct access to jobInfo.Pods using potentially non-existent target.TaskName or target.PodName could cause the application to panic. The fix introduces robust checks to validate the existence of these keys before map access, significantly enhancing the stability and reliability of the job controller's pod termination logic.
Highlights
- Bug Fix - Nil Pointer Dereference: Addresses a potential nil pointer dereference in the
killPodsfunction within the job controller. - Robust Map Access: Implements checks for the existence of
target.TaskNameandtarget.PodNamein thejobInfo.Podsmap before attempting to access their values, preventing panics. - Improved Error Prevention: Ensures that the
podsToKillmap is populated safely, even if the target task or pod does not exist in thejobInfo.Podsstructure.
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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
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. ↩
|
/assign @hzxuzhonghu |
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 correctly addresses a potential nil pointer dereference in the killPods function by adding necessary checks before accessing nested maps. The fix is direct and effective. I've included one suggestion to refactor the conditional logic using a switch statement, which could improve readability and maintainability.
| if target.Type == state.TargetTypeTask { | ||
| podsToKill = jobInfo.Pods[target.TaskName] | ||
| if targetPods, found := jobInfo.Pods[target.TaskName]; found { | ||
| podsToKill = targetPods | ||
| } | ||
| } else if target.Type == state.TargetTypePod { | ||
| podsToKill[target.PodName] = jobInfo.Pods[target.TaskName][target.PodName] | ||
| if targetPods, found := jobInfo.Pods[target.TaskName]; found { | ||
| if pod, found := targetPods[target.PodName]; found { | ||
| podsToKill[target.PodName] = pod | ||
| } | ||
| } | ||
| } |
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 if-else if structure works, but using a switch statement on target.Type would be more idiomatic Go in this case. It improves readability and makes the code more extensible if more TargetType values are added in the future.
| if target.Type == state.TargetTypeTask { | |
| podsToKill = jobInfo.Pods[target.TaskName] | |
| if targetPods, found := jobInfo.Pods[target.TaskName]; found { | |
| podsToKill = targetPods | |
| } | |
| } else if target.Type == state.TargetTypePod { | |
| podsToKill[target.PodName] = jobInfo.Pods[target.TaskName][target.PodName] | |
| if targetPods, found := jobInfo.Pods[target.TaskName]; found { | |
| if pod, found := targetPods[target.PodName]; found { | |
| podsToKill[target.PodName] = pod | |
| } | |
| } | |
| } | |
| switch target.Type { | |
| case state.TargetTypeTask: | |
| if targetPods, found := jobInfo.Pods[target.TaskName]; found { | |
| podsToKill = targetPods | |
| } | |
| case state.TargetTypePod: | |
| if targetPods, found := jobInfo.Pods[target.TaskName]; found { | |
| if pod, found := targetPods[target.PodName]; found { | |
| podsToKill[target.PodName] = pod | |
| } | |
| } | |
| } |
866f89d to
d0123c5
Compare
Signed-off-by: neo502721 <[email protected]>
|
/ok-to-test |
hzxuzhonghu
left a comment
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.
genrally lg, could you add a test case for it
|
|
Thanks so much for this fix, really appreciate it! |
Signed-off-by: neo502721 <[email protected]>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu 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 |
What type of PR is this?
/kind bug
What this PR does / why we need it:
In the killPods function, directly accessing pod from jobInfo.Pods[target.TaskName][target.PodName]
could cause a nil pointer dereference error when target.Type is TargetTypePod. This is because
if target.TaskName does not exist in jobInfo.Pods, or target.PodName does not exist in the
corresponding task, accessing this map would cause a panic.
This fix prevents direct access to potentially non-existent map keys by checking if the task
and pod exist, thereby preventing nil pointer dereference errors.
Which issue(s) this PR fixes:
Fixes #4543
Special notes for your reviewer:
Does this PR introduce a user-facing change?