fix: verify metadata is non-nil in resource allocation
This commit is contained in:
		| @@ -402,19 +402,34 @@ func TestBalancedResourceAllocation(t *testing.T) { | ||||
| 	for _, test := range tests { | ||||
| 		t.Run(test.name, func(t *testing.T) { | ||||
| 			nodeNameToInfo := schedulernodeinfo.CreateNodeNameToInfoMap(test.pods, test.nodes) | ||||
| 			if len(test.pod.Spec.Volumes) > 0 { | ||||
| 				maxVolumes := 5 | ||||
| 				for _, info := range nodeNameToInfo { | ||||
| 					info.TransientInfo.TransNodeInfo.AllocatableVolumesCount = getExistingVolumeCountForNode(info.Pods(), maxVolumes) | ||||
| 					info.TransientInfo.TransNodeInfo.RequestedVolumes = len(test.pod.Spec.Volumes) | ||||
| 			metadata := &priorityMetadata{ | ||||
| 				nonZeroRequest: getNonZeroRequests(test.pod), | ||||
| 			} | ||||
|  | ||||
| 			for _, hasMeta := range []bool{true, false} { | ||||
| 				if len(test.pod.Spec.Volumes) > 0 { | ||||
| 					maxVolumes := 5 | ||||
| 					for _, info := range nodeNameToInfo { | ||||
| 						info.TransientInfo.TransNodeInfo.AllocatableVolumesCount = getExistingVolumeCountForNode(info.Pods(), maxVolumes) | ||||
| 						info.TransientInfo.TransNodeInfo.RequestedVolumes = len(test.pod.Spec.Volumes) | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 				var function PriorityFunction | ||||
| 				if hasMeta { | ||||
| 					function = priorityFunction(BalancedResourceAllocationMap, nil, metadata) | ||||
| 				} else { | ||||
| 					function = priorityFunction(BalancedResourceAllocationMap, nil, nil) | ||||
| 				} | ||||
|  | ||||
| 				list, err := function(test.pod, nodeNameToInfo, test.nodes) | ||||
|  | ||||
| 				if err != nil { | ||||
| 					t.Errorf("unexpected error: %v", err) | ||||
| 				} | ||||
| 				if !reflect.DeepEqual(test.expectedList, list) { | ||||
| 					t.Errorf("hasMeta %#v expected %#v, got %#v", hasMeta, test.expectedList, list) | ||||
| 				} | ||||
| 			} | ||||
| 			list, err := priorityFunction(BalancedResourceAllocationMap, nil, nil)(test.pod, nodeNameToInfo, test.nodes) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error: %v", err) | ||||
| 			} | ||||
| 			if !reflect.DeepEqual(test.expectedList, list) { | ||||
| 				t.Errorf("expected %#v, got %#v", test.expectedList, list) | ||||
| 			} | ||||
| 		}) | ||||
| 	} | ||||
|   | ||||
| @@ -43,7 +43,7 @@ func ResourceLimitsPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *schedule | ||||
|  | ||||
| 	// compute pod limits | ||||
| 	var podLimits *schedulernodeinfo.Resource | ||||
| 	if priorityMeta, ok := meta.(*priorityMetadata); ok && priorityMeta != nil { | ||||
| 	if priorityMeta, ok := meta.(*priorityMetadata); ok { | ||||
| 		// We were able to parse metadata, use podLimits from there. | ||||
| 		podLimits = priorityMeta.podLimits | ||||
| 	} else { | ||||
|   | ||||
| @@ -140,21 +140,25 @@ func TestResourceLimitsPriority(t *testing.T) { | ||||
| 	for _, test := range tests { | ||||
| 		t.Run(test.name, func(t *testing.T) { | ||||
| 			nodeNameToInfo := schedulernodeinfo.CreateNodeNameToInfoMap(nil, test.nodes) | ||||
| 			metadata := &priorityMetadata{ | ||||
| 				podLimits: getResourceLimits(test.pod), | ||||
| 			} | ||||
|  | ||||
| 			for _, hasMeta := range []bool{true, false} { | ||||
| 				var metadata *priorityMetadata | ||||
| 				var function PriorityFunction | ||||
| 				if hasMeta { | ||||
| 					metadata = &priorityMetadata{ | ||||
| 						podLimits: getResourceLimits(test.pod), | ||||
| 					} | ||||
| 					function = priorityFunction(ResourceLimitsPriorityMap, nil, metadata) | ||||
| 				} else { | ||||
| 					function = priorityFunction(ResourceLimitsPriorityMap, nil, nil) | ||||
| 				} | ||||
|  | ||||
| 				list, err := priorityFunction(ResourceLimitsPriorityMap, nil, metadata)(test.pod, nodeNameToInfo, test.nodes) | ||||
| 				list, err := function(test.pod, nodeNameToInfo, test.nodes) | ||||
|  | ||||
| 				if err != nil { | ||||
| 					t.Errorf("unexpected error: %v", err) | ||||
| 				} | ||||
| 				if !reflect.DeepEqual(test.expectedList, list) { | ||||
| 					t.Errorf("expected %#v, got %#v", test.expectedList, list) | ||||
| 					t.Errorf("hasMeta %#v expected %#v, got %#v", hasMeta, test.expectedList, list) | ||||
| 				} | ||||
| 			} | ||||
| 		}) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 draveness
					draveness