karmada-io / karmada

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

When the resource model is enabled, the karmada-controller-manager panic #3601

Closed Fish-pro closed 9 months ago

Fish-pro commented 10 months ago

What happened:

The following error occurs after the resource model is enabled

image

企业微信截图_16854127816585

企业微信截图_16854138557404

I try to locate it,searchLastLessElement return '-1'

func searchLastLessElement(nums []resource.Quantity, target resource.Quantity) int {
    low, high := 0, len(nums)-1
    for low <= high {
        mid := low + ((high - low) >> 1)
        diff1 := nums[mid].Cmp(target)
        var diff2 int
        if mid != len(nums)-1 {
            diff2 = nums[mid+1].Cmp(target)
        }
        // diff < 1 means nums[mid] <= target
        // diff == 1 means nums[mid+1] > target
        if diff1 < 1 {
            if (mid == len(nums)-1) || (diff2 == 1) {
                // find the last less element that equal to target element
                return mid
            }
            low = mid + 1
        } else {
            high = mid - 1
        }
    }
    return -1
}

Get the slice object according to index '-1', thus panic


// AddToResourceSummary add resource node into modeling summary
func (rs *ResourceSummary) AddToResourceSummary(crn ClusterResourceNode) {
    index := rs.getIndex(crn)
    modeling := &(*rs)[index]
    if rs.GetNodeNumFromModel(modeling) <= 5 {
        root := modeling.linkedlist
        if root == nil {
            root = list.New()
        }
        found := false
        // traverse linkedlist to add quantity of recourse modeling
        for element := root.Front(); element != nil; element = element.Next() {
            switch clusterResourceNodeComparator(element.Value, crn) {
            case 0:
                {
                    tmpCrn := element.Value.(ClusterResourceNode)
                    safeChangeNum(&tmpCrn.quantity, crn.quantity)
                    element.Value = tmpCrn
                    found = true
                    break
                }
            case 1:
                {
                    root.InsertBefore(crn, element)
                    found = true
                    break
                }
            case -1:
                {
                    continue
                }
            }
            if found {
                break
            }
        }
        if !found {
            root.PushBack(crn)
        }
        modeling.linkedlist = root
    } else {
        root := modeling.redblackTree
        if root == nil {
            root = llConvertToRbt(modeling.linkedlist)
            modeling.linkedlist = nil
        }
        tmpNode := root.GetNode(crn)
        if tmpNode != nil {
            node := tmpNode.Key.(ClusterResourceNode)
            safeChangeNum(&node.quantity, crn.quantity)
            tmpNode.Key = node
        } else {
            root.Put(crn, crn.quantity)
        }
        modeling.redblackTree = root
    }
    safeChangeNum(&modeling.Quantity, crn.quantity)
}

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

RainbowMango commented 10 months ago

Which version are you using? We just fixed a panic issue at #3591 yesterday.

Fish-pro commented 10 months ago

Which version are you using? We just fixed a panic issue at #3591 yesterday.

@RainbowMango I installed it last week. we did not update the local branch. I will try again after updating

RainbowMango commented 9 months ago

Why closed this?