fix(yurtmanager): prevent nil map assignment panic in hubleader controller - #2720
Open
nishantbkl3345-ship-it wants to merge 2 commits into
Open
Conversation
…LeaderNodeLabelSelector is nil
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a potential runtime panic in the hubleader controller when using the mark leader election strategy with a nil/omitted LeaderNodeLabelSelector, and adds a unit test to prevent regressions.
Changes:
- Avoids overwriting an initialized
matchLabelsmap with a potentially nilLeaderNodeLabelSelector. - Copies selector key/value pairs into
matchLabelsinstead of reassigning the map reference (preventing nil-map assignment panic). - Adds a unit test covering
markstrategy withLeaderNodeLabelSelector: nil.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/yurtmanager/controller/hubleader/hubleader_controller.go | Prevents nil-map assignment panic by copying selector labels into an initialized matchLabels map. |
| pkg/yurtmanager/controller/hubleader/hubleader_controller_test.go | Adds a regression test for mark strategy with a nil LeaderNodeLabelSelector. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Author
|
@zhangzhenyuyu hey! please look upon the pr when you get a chance! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What this PR does / why we need it
Fixes a potential
nilmap assignment panic inhubleader_controller.When
nodepool.Spec.LeaderElectionStrategyis set tomarkbutnodepool.Spec.LeaderNodeLabelSelectorisnil(or omitted),matchLabels = nodepool.Spec.LeaderNodeLabelSelectoroverwrote the non-nilmatchLabelsmap withnil. Attempting to writematchLabels[projectinfo.GetNodePoolLabel()] = nodepool.GetName()subsequently triggered a runtime panic (panic: assignment to entry in nil map).This PR safely iterates and copies key-value pairs from
nodepool.Spec.LeaderNodeLabelSelectorintomatchLabelswithout replacing the non-nil map reference.Which issue(s) this PR fixes
N/A
Special notes for your reviewer
mark election strategy with nil LeaderNodeLabelSelectortopkg/yurtmanager/controller/hubleader/hubleader_controller_test.go.