Skip to content
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

Change the length of modelSortings array for panic of index error #3591

Merged
merged 1 commit into from
May 29, 2023

Conversation

sunbinnnnn
Copy link

@sunbinnnnn sunbinnnnn commented May 26, 2023

If grade number of resourceModel less than rsName, the controller may panic with index error.

What type of PR is this?

/kind bug

What this PR does / why we need it:
Add a precheck to check if resource model grades less than resources count.

Which issue(s) this PR fixes:
Fixes #3472

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Fixed the panic issue in case of the grade number of resourceModel is less than the number of resources.

@karmada-bot
Copy link
Collaborator

Welcome @sunbinnnnn! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 26, 2023
@XiShanYongYe-Chang
Copy link
Member

/cc @Poor12 @halfrost

@karmada-bot karmada-bot requested a review from Poor12 May 26, 2023 09:51
@karmada-bot
Copy link
Collaborator

@XiShanYongYe-Chang: GitHub didn't allow me to request PR reviews from the following users: halfrost.

Note that only karmada-io members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @Poor12 @halfrost

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codecov-commenter
Copy link

codecov-commenter commented May 26, 2023

Codecov Report

Merging #3591 (efb2ce0) into master (218a0b2) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #3591      +/-   ##
==========================================
- Coverage   55.86%   55.85%   -0.01%     
==========================================
  Files         216      216              
  Lines       20121    20121              
==========================================
- Hits        11240    11238       -2     
- Misses       8276     8278       +2     
  Partials      605      605              
Flag Coverage Δ
unittests 55.85% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/modeling/modeling.go 71.09% <100.00%> (ø)

... and 1 file with indirect coverage changes

@Poor12
Copy link
Member

Poor12 commented May 27, 2023

Thanks @sunbinnnnn.
After I went through the code, I find that add this validation is not a thoroughly solution. I suggest the change:

// generate a sorted array by first priority of ResourceName
modelSortings = make([][]resource.Quantity, len(rsList))

to

// generate a sorted array by first priority of ResourceName
modelSortings = make([][]resource.Quantity, len(rsName))

@halfrost
Copy link
Contributor

I agree with @Poor12 's solution. Increasing the capacity of modelSortings is a more thorough solution.

If grade number of resourceModel less than rsName, the controller
may panic with index error.
The length of resource model grades array should equl the length
of rsName array.

Signed-off-by: NeilSun <sunbinnnnn@hotmail.com>
@sunbinnnnn sunbinnnnn changed the title Fix using precheck to check if ResourceModel defined with error Change the length of modelSortings array for panic of index error May 27, 2023
@Poor12
Copy link
Member

Poor12 commented May 28, 2023

LGTM

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

@Poor12 Please clarify if this patch needs cherry-pick. If yes, please propose a release note. Thanks.

@Poor12
Copy link
Member

Poor12 commented May 29, 2023

I think this issue needs to cherry-pick. For release node, I propose:

karmada-controller-manager: fix the issue that controller-manager panic when the grade number of resourceModel is less than number of resource

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label May 29, 2023
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

karmada-bot added a commit that referenced this pull request Jun 1, 2023
…91-origin-release-1.3

Automated cherry pick of #3591: Change the length of modelSortings array for panic of index
karmada-bot added a commit that referenced this pull request Jun 1, 2023
…91-origin-release-1.4

Automated cherry pick of #3591: Change the length of modelSortings array for panic of index
karmada-bot added a commit that referenced this pull request Jun 1, 2023
…91-origin-release-1.5

Automated cherry pick of #3591: Change the length of modelSortings array for panic of index
@RainbowMango RainbowMango added this to the v1.6 milestone Aug 18, 2023
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. 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.

ResourceModel: panic: runtime error
7 participants