mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Added unit test for node operation in schedulercache.
This commit is contained in:
		@@ -40,6 +40,7 @@ import (
 | 
			
		||||
	"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
 | 
			
		||||
	priorityutil "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities/util"
 | 
			
		||||
	"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
 | 
			
		||||
	schedutil "k8s.io/kubernetes/plugin/pkg/scheduler/util"
 | 
			
		||||
	"k8s.io/metrics/pkg/client/clientset_generated/clientset"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -835,7 +836,7 @@ func PodFitsHostPorts(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.No
 | 
			
		||||
		wantPorts = predicateMeta.podPorts
 | 
			
		||||
	} else {
 | 
			
		||||
		// We couldn't parse metadata - fallback to computing it.
 | 
			
		||||
		wantPorts = GetUsedPorts(pod)
 | 
			
		||||
		wantPorts = schedutil.GetUsedPorts(pod)
 | 
			
		||||
	}
 | 
			
		||||
	if len(wantPorts) == 0 {
 | 
			
		||||
		return true, nil, nil
 | 
			
		||||
@@ -850,24 +851,6 @@ func PodFitsHostPorts(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.No
 | 
			
		||||
	return true, nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetUsedPorts(pods ...*v1.Pod) map[int]bool {
 | 
			
		||||
	ports := make(map[int]bool)
 | 
			
		||||
	for _, pod := range pods {
 | 
			
		||||
		for j := range pod.Spec.Containers {
 | 
			
		||||
			container := &pod.Spec.Containers[j]
 | 
			
		||||
			for k := range container.Ports {
 | 
			
		||||
				podPort := &container.Ports[k]
 | 
			
		||||
				// "0" is explicitly ignored in PodFitsHostPorts,
 | 
			
		||||
				// which is the only function that uses this value.
 | 
			
		||||
				if podPort.HostPort != 0 {
 | 
			
		||||
					ports[int(podPort.HostPort)] = true
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return ports
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// search two arrays and return true if they have at least one common element; return false otherwise
 | 
			
		||||
func haveSame(a1, a2 []string) bool {
 | 
			
		||||
	for _, val1 := range a1 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user