Merge pull request #70401 from ravisantoshgudimetla/fix-e2e-node-capacity

Fix capacities as well
pull/58/head
k8s-ci-robot 2018-11-01 09:53:04 -07:00 committed by GitHub
commit a525a2b4ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -275,15 +275,19 @@ var _ = SIGDescribe("SchedulerPriorities [Serial]", func() {
nodeName := lastNode.Name
nodeOriginalMemory, found := lastNode.Status.Allocatable[v1.ResourceMemory]
nodeOriginalCPU, found := lastNode.Status.Allocatable[v1.ResourceCPU]
nodeOriginalCPUCapacity, found := lastNode.Status.Capacity[v1.ResourceCPU]
nodeOriginalMemoryCapacity, found := lastNode.Status.Capacity[v1.ResourceMemory]
Expect(found).To(Equal(true))
nodeOriginalMemoryVal := nodeOriginalMemory.Value()
nodeOriginalCPUVal := nodeOriginalCPU.MilliValue()
err := updateNodeAllocatable(cs, nodeName, int64(10737418240), int64(12000))
nodeOriginalMemoryCapacityVal := nodeOriginalMemoryCapacity.Value()
nodeOriginalCPUCapacityVal := nodeOriginalCPUCapacity.MilliValue()
err := updateNodeResources(cs, nodeName, int64(10737418240), int64(12000), int64(10737418240), int64(12000))
Expect(err).NotTo(HaveOccurred())
defer func() {
// Resize the node back to its original allocatable values.
if err := updateNodeAllocatable(cs, nodeName, nodeOriginalMemoryVal, nodeOriginalCPUVal); err != nil {
framework.Logf("Failed to revert node memory with %v", err)
if err := updateNodeResources(cs, nodeName, nodeOriginalMemoryVal, nodeOriginalCPUVal, nodeOriginalMemoryCapacityVal, nodeOriginalCPUCapacityVal); err != nil {
framework.Logf("Failed to revert node resources with %v", err)
}
// Reset the node list with its old entry.
nodeList.Items[len(nodeList.Items)-1] = lastNode
@ -458,15 +462,17 @@ func addRandomTaitToNode(cs clientset.Interface, nodeName string) *v1.Taint {
return &testTaint
}
// updateNodeAllocatable updates the allocatable values of given node with the given values.
func updateNodeAllocatable(c clientset.Interface, nodeName string, memory, cpu int64) error {
// updateNodeResources updates the resource of given node with the given values.
func updateNodeResources(c clientset.Interface, nodeName string, memoryAllocatable, cpuAllocatable, memoryCapacity, cpuCapacity int64) error {
node, err := c.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
framework.ExpectNoError(err)
if err != nil {
return err
}
node.Status.Allocatable[v1.ResourceMemory] = *resource.NewQuantity(memory, resource.BinarySI)
node.Status.Allocatable[v1.ResourceCPU] = *resource.NewMilliQuantity(cpu, resource.DecimalSI)
node.Status.Capacity[v1.ResourceMemory] = *resource.NewQuantity(memoryCapacity, resource.BinarySI)
node.Status.Capacity[v1.ResourceCPU] = *resource.NewMilliQuantity(cpuCapacity, resource.DecimalSI)
node.Status.Allocatable[v1.ResourceMemory] = *resource.NewQuantity(memoryAllocatable, resource.BinarySI)
node.Status.Allocatable[v1.ResourceCPU] = *resource.NewMilliQuantity(cpuAllocatable, resource.DecimalSI)
_, err = c.CoreV1().Nodes().UpdateStatus(node)
return err
}