mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 02:08:13 +00:00 
			
		
		
		
	Merge pull request #43008 from ravisantoshgudimetla/taints_small_changes
Automatic merge from submit-queue (batch tested with PRs 43681, 40423, 43562, 43008, 43381) Changes for removing deadcode in taint_tolerations **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #43007
This commit is contained in:
		| @@ -34,13 +34,10 @@ func PriorityMetadata(pod *v1.Pod, nodeNameToInfo map[string]*schedulercache.Nod | |||||||
| 	if pod == nil { | 	if pod == nil { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	tolerations, err := getTolerationListFromPod(pod) | 	tolerationsPreferNoSchedule := getAllTolerationPreferNoSchedule(pod.Spec.Tolerations) | ||||||
| 	if err != nil { |  | ||||||
| 		return nil |  | ||||||
| 	} |  | ||||||
| 	return &priorityMetadata{ | 	return &priorityMetadata{ | ||||||
| 		nonZeroRequest: getNonZeroRequests(pod), | 		nonZeroRequest: getNonZeroRequests(pod), | ||||||
| 		podTolerations: tolerations, | 		podTolerations: tolerationsPreferNoSchedule, | ||||||
| 		affinity:       schedulercache.ReconcileAffinity(pod), | 		affinity:       schedulercache.ReconcileAffinity(pod), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,56 +27,48 @@ import ( | |||||||
|  |  | ||||||
| // CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule | // CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule | ||||||
| func countIntolerableTaintsPreferNoSchedule(taints []v1.Taint, tolerations []v1.Toleration) (intolerableTaints int) { | func countIntolerableTaintsPreferNoSchedule(taints []v1.Taint, tolerations []v1.Toleration) (intolerableTaints int) { | ||||||
| 	for i := range taints { | 	for _, taint := range taints { | ||||||
| 		taint := &taints[i] |  | ||||||
| 		// check only on taints that have effect PreferNoSchedule | 		// check only on taints that have effect PreferNoSchedule | ||||||
| 		if taint.Effect != v1.TaintEffectPreferNoSchedule { | 		if taint.Effect != v1.TaintEffectPreferNoSchedule { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if !v1.TolerationsTolerateTaint(tolerations, taint) { | 		if !v1.TolerationsTolerateTaint(tolerations, &taint) { | ||||||
| 			intolerableTaints++ | 			intolerableTaints++ | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
| // getAllTolerationEffectPreferNoSchedule gets the list of all Toleration with Effect PreferNoSchedule | // getAllTolerationEffectPreferNoSchedule gets the list of all Tolerations with Effect PreferNoSchedule or with no effect. | ||||||
| func getAllTolerationPreferNoSchedule(tolerations []v1.Toleration) (tolerationList []v1.Toleration) { | func getAllTolerationPreferNoSchedule(tolerations []v1.Toleration) (tolerationList []v1.Toleration) { | ||||||
| 	for i := range tolerations { | 	for _, toleration := range tolerations { | ||||||
| 		toleration := &tolerations[i] | 		// Empty effect means all effects which includes PreferNoSchedule, so we need to collect it as well. | ||||||
| 		if len(toleration.Effect) == 0 || toleration.Effect == v1.TaintEffectPreferNoSchedule { | 		if len(toleration.Effect) == 0 || toleration.Effect == v1.TaintEffectPreferNoSchedule { | ||||||
| 			tolerationList = append(tolerationList, *toleration) | 			tolerationList = append(tolerationList, toleration) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
| func getTolerationListFromPod(pod *v1.Pod) ([]v1.Toleration, error) { |  | ||||||
| 	return getAllTolerationPreferNoSchedule(pod.Spec.Tolerations), nil |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // ComputeTaintTolerationPriority prepares the priority list for all the nodes based on the number of intolerable taints on the node | // ComputeTaintTolerationPriority prepares the priority list for all the nodes based on the number of intolerable taints on the node | ||||||
| func ComputeTaintTolerationPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (schedulerapi.HostPriority, error) { | func ComputeTaintTolerationPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (schedulerapi.HostPriority, error) { | ||||||
| 	node := nodeInfo.Node() | 	node := nodeInfo.Node() | ||||||
| 	if node == nil { | 	if node == nil { | ||||||
| 		return schedulerapi.HostPriority{}, fmt.Errorf("node not found") | 		return schedulerapi.HostPriority{}, fmt.Errorf("node not found") | ||||||
| 	} | 	} | ||||||
|  | 	// To hold all the tolerations with Effect PreferNoSchedule | ||||||
| 	var tolerationList []v1.Toleration | 	var tolerationsPreferNoSchedule []v1.Toleration | ||||||
| 	if priorityMeta, ok := meta.(*priorityMetadata); ok { | 	if priorityMeta, ok := meta.(*priorityMetadata); ok { | ||||||
| 		tolerationList = priorityMeta.podTolerations | 		tolerationsPreferNoSchedule = priorityMeta.podTolerations | ||||||
|  |  | ||||||
| 	} else { | 	} else { | ||||||
| 		var err error | 		tolerationsPreferNoSchedule = getAllTolerationPreferNoSchedule(pod.Spec.Tolerations) | ||||||
| 		tolerationList, err = getTolerationListFromPod(pod) |  | ||||||
| 		if err != nil { |  | ||||||
| 			return schedulerapi.HostPriority{}, err |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return schedulerapi.HostPriority{ | 	return schedulerapi.HostPriority{ | ||||||
| 		Host:  node.Name, | 		Host:  node.Name, | ||||||
| 		Score: countIntolerableTaintsPreferNoSchedule(node.Spec.Taints, tolerationList), | 		Score: countIntolerableTaintsPreferNoSchedule(node.Spec.Taints, tolerationsPreferNoSchedule), | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -204,6 +204,26 @@ func TestTaintAndToleration(t *testing.T) { | |||||||
| 				{Host: "nodeC", Score: 0}, | 				{Host: "nodeC", Score: 0}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			test: "Default behaviour No taints and tolerations, lands on node with no taints", | ||||||
|  | 			//pod without tolerations | ||||||
|  | 			pod: podWithTolerations([]v1.Toleration{}), | ||||||
|  | 			nodes: []*v1.Node{ | ||||||
|  | 				//Node without taints | ||||||
|  | 				nodeWithTaints("nodeA", []v1.Taint{}), | ||||||
|  | 				nodeWithTaints("nodeB", []v1.Taint{ | ||||||
|  | 					{ | ||||||
|  | 						Key:    "cpu-type", | ||||||
|  | 						Value:  "arm64", | ||||||
|  | 						Effect: v1.TaintEffectPreferNoSchedule, | ||||||
|  | 					}, | ||||||
|  | 				}), | ||||||
|  | 			}, | ||||||
|  | 			expectedList: []schedulerapi.HostPriority{ | ||||||
|  | 				{Host: "nodeA", Score: 10}, | ||||||
|  | 				{Host: "nodeB", Score: 0}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
| 	for _, test := range tests { | 	for _, test := range tests { | ||||||
| 		nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(nil, test.nodes) | 		nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(nil, test.nodes) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Submit Queue
					Kubernetes Submit Queue