Skip to content

Commit

Permalink
ResourceSummary add check index for -1
Browse files Browse the repository at this point in the history
Signed-off-by: Lan Liang <gcslyp@gmail.com>
  • Loading branch information
liangyuanpeng committed Aug 17, 2023
1 parent bd0c511 commit f3d7b72
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/modeling/modeling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f3d7b72

Please sign in to comment.