fix: prevent nil pointer dereference in application failover controller#7169
fix: prevent nil pointer dereference in application failover controller#7169goyalpalak18 wants to merge 1 commit intokarmada-io:masterfrom
Conversation
Signed-off-by: goyalpalak18 <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Summary of ChangesHello @goyalpalak18, 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 addresses a critical nil pointer dereference issue within the application failover controllers and validation webhook. The Highlights
Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this comment.
Code Review
This pull request addresses a critical nil pointer dereference in the applicationfailover controller by adding necessary nil checks for TolerationSeconds. The changes are well-implemented across both ClusterResourceBinding and ResourceBinding controllers, and the validation logic. The inclusion of unit tests to cover the nil case is excellent and ensures the fix is robust. My only suggestion is to define the default toleration value as a constant to improve maintainability and avoid magic numbers.
pkg/controllers/applicationfailover/crb_application_failover_controller.go
Show resolved
Hide resolved
pkg/controllers/applicationfailover/rb_application_failover_controller.go
Show resolved
Hide resolved
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7169 +/- ##
==========================================
- Coverage 46.56% 46.54% -0.02%
==========================================
Files 700 700
Lines 48139 48146 +7
==========================================
- Hits 22414 22408 -6
- Misses 24040 24050 +10
- Partials 1685 1688 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @goyalpalak18 is this the same issue as #7127? |
|
Hey @RainbowMango, yes it is. I opened this one as a simplified replacement for #7127. Based on the feedback there, I dropped the webhook changes and just kept this defensive nil-check for the controller. I meant to close #7127 earlier—I'll close it now so we can focus on this lighter fix. |
|
Hi @goyalpalak18, first of all, thanks for your contribution. As I commented earlier, I think this protection is a bit overdone, because logically speaking, when this function is called, this value will not be nil. |
|
Hi @goyalpalak18 do you have any other comments or do you agree to close this PR? |
|
No other comments from my side. Let's close it. Thanks! |
Description
I fixed a critical nil pointer dereference panic in the
applicationfailovercontroller and validation webhook.The
TolerationSecondsfield is a pointer (*int32), and while it usually has a default, I found that legacy objects or specific upgrade paths can leave itnil. Previously, the code dereferenced this pointer blindly, causing thekarmada-controller-managerto crash-loop.Root Cause
The
detectFailureandsyncBindingfunctions assumedTolerationSecondswas always populated. I identified that direct dereferencing (*tolerationSeconds) without a check was the direct cause of the runtime panic.Proposed Changes
Defensive Controller Logic:
I modified
rb_application_failover_controller.goandcrb_application_failover_controller.go. I added a nil check that falls back to the default300sif the field is missing, preventing the panic.Safe Validation:
I updated
pkg/util/validation/validation.goto include a nil-check guard before validating the value.Tests:
I added unit tests to
rb_application_failover_controller_test.go,crb_application_failover_controller_test.go, andvalidation_test.goto confirm thatnilvalues are handled gracefully.