From f3d7b72b164fa37be99012f2ac995e55f70b5d9f Mon Sep 17 00:00:00 2001 From: Lan Liang Date: Thu, 17 Aug 2023 08:42:03 +0000 Subject: [PATCH] ResourceSummary add check index for -1 Signed-off-by: Lan Liang --- pkg/modeling/modeling.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/modeling/modeling.go b/pkg/modeling/modeling.go index 71eabeb2a..82cc6ed15 100644 --- a/pkg/modeling/modeling.go +++ b/pkg/modeling/modeling.go @@ -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