Merge pull request #3950 from liangyuanpeng/rs_check

ResourceSummary add check index for -1
This commit is contained in:
karmada-bot 2023-08-18 10:48:57 +08:00 committed by GitHub
commit f7a10b9fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -162,6 +162,10 @@ func safeChangeNum(num *int, change int) {
// AddToResourceSummary add resource node into modeling summary
func (rs *ResourceSummary) AddToResourceSummary(crn ClusterResourceNode) {
index := rs.getIndex(crn)
if index == -1 {
klog.Error("ClusterResource can not add to resource summary: index is invalid.")
return
}
modeling := &(*rs)[index]
if rs.GetNodeNumFromModel(modeling) <= 5 {
root := modeling.linkedlist
@ -269,6 +273,9 @@ func (rs *ResourceSummary) GetNodeNumFromModel(model *resourceModels) int {
// DeleteFromResourceSummary dalete resource node into modeling summary
func (rs *ResourceSummary) DeleteFromResourceSummary(crn ClusterResourceNode) error {
index := rs.getIndex(crn)
if index == -1 {
return errors.New("ClusterResource can not delet the resource summary: index is invalid.")
}
modeling := &(*rs)[index]
if rs.GetNodeNumFromModel(modeling) >= 6 {
root := modeling.redblackTree