Commit 85f1e0ea authored by PingWang's avatar PingWang

Fix the bug of the "removePod" function in node_info.go

It should reduce the resource data after finding the pod in the pods, because perhaps no corresponding pod in the pods of the node, at this time it shouldn't reduce the resource data of the node.
parent 5ffebfa3
...@@ -132,27 +132,27 @@ func (n *NodeInfo) removePod(pod *api.Pod) error { ...@@ -132,27 +132,27 @@ func (n *NodeInfo) removePod(pod *api.Pod) error {
return err return err
} }
cpu, mem, nvidia_gpu, non0_cpu, non0_mem := calculateResource(pod)
n.requestedResource.MilliCPU -= cpu
n.requestedResource.Memory -= mem
n.requestedResource.NvidiaGPU -= nvidia_gpu
n.nonzeroRequest.MilliCPU -= non0_cpu
n.nonzeroRequest.Memory -= non0_mem
for i := range n.pods { for i := range n.pods {
k2, err := getPodKey(n.pods[i]) k2, err := getPodKey(n.pods[i])
if err != nil { if err != nil {
glog.Errorf("Cannot get pod key, err: %v", err) glog.Errorf("Cannot get node.pod(%s/%s) key, err: %v", n.pods[i].Namespace, n.pods[i].Name, err)
continue continue
} }
if k1 == k2 { if k1 == k2 {
// delete the element // delete the element
n.pods[i] = n.pods[len(n.pods)-1] n.pods[i] = n.pods[len(n.pods)-1]
n.pods = n.pods[:len(n.pods)-1] n.pods = n.pods[:len(n.pods)-1]
// reduce the resource data
cpu, mem, nvidia_gpu, non0_cpu, non0_mem := calculateResource(pod)
n.requestedResource.MilliCPU -= cpu
n.requestedResource.Memory -= mem
n.requestedResource.NvidiaGPU -= nvidia_gpu
n.nonzeroRequest.MilliCPU -= non0_cpu
n.nonzeroRequest.Memory -= non0_mem
return nil return nil
} }
} }
return fmt.Errorf("no corresponding pod in pods") return fmt.Errorf("no corresponding pod(%s/%s) in pods of node(%s)", pod.Namespace, pod.Name, n.node.Name)
} }
func calculateResource(pod *api.Pod) (cpu int64, mem int64, nvidia_gpu int64, non0_cpu int64, non0_mem int64) { func calculateResource(pod *api.Pod) (cpu int64, mem int64, nvidia_gpu int64, non0_cpu int64, non0_mem int64) {
......
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