Commit b055246f authored by Binbin Zhao's avatar Binbin Zhao

Replace capacity with allocatable to calculate pod resource

It is not accurate to use capacity to do the calculation.
parent 562e721e
......@@ -151,15 +151,15 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
// It assumes that cluster add-on pods stay stable and cannot be run in parallel with any other test that touches Nodes or Pods.
// It is so because we need to have precise control on what's running in the cluster.
It("validates resource limits of pods that are allowed to run [Conformance]", func() {
nodeMaxCapacity := int64(0)
nodeMaxAllocatable := int64(0)
nodeToCapacityMap := make(map[string]int64)
nodeToAllocatableMap := make(map[string]int64)
for _, node := range nodeList.Items {
capacity, found := node.Status.Capacity["cpu"]
allocatable, found := node.Status.Allocatable["cpu"]
Expect(found).To(Equal(true))
nodeToCapacityMap[node.Name] = capacity.MilliValue()
if nodeMaxCapacity < capacity.MilliValue() {
nodeMaxCapacity = capacity.MilliValue()
nodeToAllocatableMap[node.Name] = allocatable.MilliValue()
if nodeMaxAllocatable < allocatable.MilliValue() {
nodeMaxAllocatable = allocatable.MilliValue()
}
}
framework.WaitForStableCluster(cs, masterNodes)
......@@ -167,21 +167,21 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
pods, err := cs.Core().Pods(metav1.NamespaceAll).List(metav1.ListOptions{})
framework.ExpectNoError(err)
for _, pod := range pods.Items {
_, found := nodeToCapacityMap[pod.Spec.NodeName]
_, found := nodeToAllocatableMap[pod.Spec.NodeName]
if found && pod.Status.Phase != v1.PodSucceeded && pod.Status.Phase != v1.PodFailed {
framework.Logf("Pod %v requesting resource cpu=%vm on Node %v", pod.Name, getRequestedCPU(pod), pod.Spec.NodeName)
nodeToCapacityMap[pod.Spec.NodeName] -= getRequestedCPU(pod)
nodeToAllocatableMap[pod.Spec.NodeName] -= getRequestedCPU(pod)
}
}
var podsNeededForSaturation int
milliCpuPerPod := nodeMaxCapacity / maxNumberOfPods
milliCpuPerPod := nodeMaxAllocatable / maxNumberOfPods
if milliCpuPerPod < minPodCPURequest {
milliCpuPerPod = minPodCPURequest
}
framework.Logf("Using pod capacity: %vm", milliCpuPerPod)
for name, leftCapacity := range nodeToCapacityMap {
for name, leftCapacity := range nodeToAllocatableMap {
framework.Logf("Node: %v has cpu capacity: %vm", name, leftCapacity)
podsNeededForSaturation += (int)(leftCapacity / milliCpuPerPod)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment