Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Fish-pro opened this issue May 30, 2023 · 3 comments
Closed
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@Fish-pro
Copy link
Member

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:

  • Karmada version: latest
  • kubectl-karmada or karmadactl version (the result of kubectl-karmada version or karmadactl version):
  • Others:
@Fish-pro Fish-pro added the kind/bug Categorizes issue or PR as related to a bug. label May 30, 2023
@RainbowMango
Copy link
Member

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

@Fish-pro
Copy link
Member Author

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
Copy link
Member

Why closed this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants