karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.11k stars 803 forks source link

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

Closed sunbinnnnn closed 11 months ago

sunbinnnnn commented 11 months ago

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 commented 11 months ago

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

XiShanYongYe-Chang commented 11 months ago

/cc @Poor12 @halfrost

karmada-bot commented 11 months ago

@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](https://github.com/karmada-io/karmada/pull/3591#issuecomment-1564123983): >/cc @Poor12 @halfrost Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
codecov-commenter commented 11 months ago

Codecov Report

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

:exclamation: 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%) :arrow_down:

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 commented 11 months ago

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 commented 11 months ago

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

Poor12 commented 11 months ago

LGTM

Poor12 commented 11 months ago

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
karmada-bot commented 11 months ago

[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: - ~~[OWNERS](https://github.com/karmada-io/karmada/blob/master/OWNERS)~~ [RainbowMango] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment